60 _cudaGraphicsResource =
nullptr;
61 _cudaTextureObject = 0;
108 assetMgr->
textures().push_back(
this);
167 assetMgr->
textures().push_back(
this);
195 assert(!filename.empty());
211 #ifdef SL_BUILD_WITH_KTX
213 _width = _ktxTexture->baseWidth;
214 _height = _ktxTexture->baseHeight;
215 _depth = _ktxTexture->numDimensions == 3 ? _ktxTexture->baseDepth : 1;
235 _cudaGraphicsResource =
nullptr;
236 _cudaTextureObject = 0;
241 assetMgr->
textures().push_back(
this);
271 assert(files.size() > 1);
275 for (
const auto& filename : files)
276 load(filename,
true, loadGrayscaleIntoAlpha);
301 _cudaGraphicsResource =
nullptr;
302 _cudaTextureObject = 0;
307 assetMgr->
textures().push_back(
this);
344 load(filename,
true, loadGrayscaleIntoAlpha);
369 _cudaGraphicsResource =
nullptr;
370 _cudaTextureObject = 0;
375 assetMgr->
textures().push_back(
this);
399 assert(colors.size() > 1);
431 _cudaGraphicsResource =
nullptr;
432 _cudaTextureObject = 0;
437 assetMgr->
textures().push_back(
this);
471 assert(!filenameXPos.empty());
472 assert(!filenameXNeg.empty());
473 assert(!filenameYPos.empty());
474 assert(!filenameYNeg.empty());
475 assert(!filenameZPos.empty());
476 assert(!filenameZNeg.empty());
478 load(filenameXPos,
false);
479 load(filenameXNeg,
false);
480 load(filenameYPos,
false);
481 load(filenameYNeg,
false);
482 load(filenameZPos,
false);
483 load(filenameZNeg,
false);
508 _cudaGraphicsResource =
nullptr;
509 _cudaTextureObject = 0;
512 assetMgr->
textures().push_back(
this);
536 #ifdef SL_BUILD_WITH_KTX
537 if (deleteAlsoOnGPU && _ktxTexture)
538 ktxTexture_Destroy((ktxTexture*)_ktxTexture);
566 glDeleteTextures(1, &
_texID);
573 if (_cudaGraphicsResource)
575 CUDA_CHECK(cuGraphicsUnregisterResource(_cudaGraphicsResource));
576 _cudaGraphicsResource =
nullptr;
584 SLbool loadGrayscaleIntoAlpha)
588 SLstring msg =
"SLGLTexture: File not found: " + filename;
597 #ifdef SL_BUILD_WITH_KTX
598 _ktxFileName = filename;
602 KTX_error_code error = ktxTexture_CreateFromMemory(buffer.
data,
604 KTX_TEXTURE_CREATE_NO_FLAGS,
605 (ktxTexture**)&_ktxTexture);
608 if (error != KTX_SUCCESS)
610 string errStr =
"Error in SLGLTexture::load: " +
611 ktxErrorStr(error) +
" in file: " + filename;
615 # ifdef SL_EMSCRIPTEN
617 _ktxTexture->generateMipmaps =
false;
620 if (ktxTexture2_NeedsTranscoding(_ktxTexture))
627 GLint numCompressedTextureFormats = 0;
628 glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numCompressedTextureFormats);
629 std::vector<GLint> compressedTextureFormats(numCompressedTextureFormats, 0);
630 glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, &compressedTextureFormats[0]);
633 # if defined(SL_OS_MACIOS)
634 _compressionFormat = KTX_TTF_PVRTC1_4_RGB;
635 # elif defined(SL_OS_ANDROID)
636 _compressionFormat = KTX_TTF_ETC2_RGBA;
637 # elif defined(SL_EMSCRIPTEN)
641 _compressionFormat = KTX_TTF_BC3_RGBA;
643 _compressionFormat = KTX_TTF_ETC2_RGBA;
645 SL_EXIT_MSG(
"No valid compression format found for this WebGL context");
647 _compressionFormat = KTX_TTF_BC3_RGBA;
649 error = ktxTexture2_TranscodeBasis(_ktxTexture, _compressionFormat, 0);
651 if (error != KTX_SUCCESS || _ktxTexture->pData ==
nullptr)
653 string errStr =
"Error in SLGLTexture::load: " +
655 "\nwhile transcoding file: " + filename +
656 "\nto format: " + compressionFormatStr(_compressionFormat);
661 SL_EXIT_MSG(
"Ktx files are not supported. You have to build with SL_BUILD_WITH_KTX flag enabled.");
668 loadGrayscaleIntoAlpha);
676 assert(colors.size() > 1);
680 for (
const auto& c : colors)
681 col4f.push_back(
CVVec4f(c.r, c.g, c.b, c.a));
716 "LiveVideoImageFromMemory"));
719 bool needsBuild =
_images[0]->load(camWidth,
739 if (needsBuild ||
_texID == 0)
761 "LiveVideoImageFromMemory"));
764 bool needsBuild =
_images[0]->load(camWidth,
783 if (needsBuild ||
_texID == 0)
801 assert(texUnit >= 0 && texUnit < 16);
805 #ifdef SL_BUILD_WITH_KTX
806 if (_ktxTexture->pData ==
nullptr)
808 string errStr =
"Error in SLGLTexture::build: texture " + _ktxFileName +
" contains no data";
816 glDeleteTextures(1, &
_texID);
823 SLint texMaxSize = 0;
824 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texMaxSize);
831 SL_EXIT_MSG(
"SLGLTexture::build: Texture width is too big.");
833 SL_EXIT_MSG(
"SLGLTexture::build: Texture height is too big.");
840 glGenTextures(1, &
_texID);
859 KTX_error_code ktxErrorCode = ktxTexture_GLUpload((ktxTexture*)_ktxTexture, &
_texID, &
_target, &glerror);
862 _ktxTexture->baseHeight;
870 ktxTexture_Destroy((ktxTexture*)_ktxTexture);
871 _ktxTexture =
nullptr;
877 else if (
_target == GL_TEXTURE_EXTERNAL_OES)
879 glGenTextures(1, &
_texID);
887 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
888 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
890 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S,
_wrap_s);
891 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T,
_wrap_t);
894 float color[] = {0.00001f, 0.00001f, 0.00001f, 1.0f};
895 glTexParameterfv(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_BORDER_COLOR_OES, color);
902 SL_EXIT_MSG(
"No images loaded in SLGLTexture::build");
908 glDeleteTextures(1, &
_texID);
909 SL_LOG(
"SLGLTexture::build: Deleted: %d, %s",
919 SLint texMaxSize = 0;
920 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texMaxSize);
927 if (w2 == 0)
SL_EXIT_MSG(
"Image can not be rescaled: width=0");
928 if (h2 == 0)
SL_EXIT_MSG(
"Image can not be rescaled: height=0");
937 SL_EXIT_MSG(
"SLGLTexture::build: Texture width is too big.");
939 SL_EXIT_MSG(
"SLGLTexture::build: Texture height is too big.");
945 SLint texMax3DSize = 0;
946 glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &texMax3DSize);
949 if (img->width() > (
SLuint)texMax3DSize)
950 SL_EXIT_MSG(
"SLGLTexture::build: 3D Texture width is too big.");
951 if (img->height() > (
SLuint)texMax3DSize)
952 SL_EXIT_MSG(
"SLGLTexture::build: 3D Texture height is too big.");
953 if (img->width() !=
_images[0]->width() ||
954 img->height() !=
_images[0]->height())
955 SL_EXIT_MSG(
"SLGLTexture::build: Not all images of the 3D texture have the same size.");
960 if (
_target == GL_TEXTURE_CUBE_MAP)
962 SLint texMaxCubeSize;
963 glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &texMaxCubeSize);
965 SL_EXIT_MSG(
"SLGLTexture::build: Cube Texture width is too big.");
967 SL_EXIT_MSG(
"SLGLTexture::build: Not six images provided for cube map texture.");
971 glGenTextures(1, &
_texID);
982 if (stateGL->
hasExtension(
"GL_EXT_texture_filter_anisotropic"))
987 SL_LOG(
"GL_EXT_texture_filter_anisotropic not available.\n");
1033 GLenum format =
_images[0]->format();
1036 glTexImage2D(GL_TEXTURE_2D,
1056 glGenerateMipmap(GL_TEXTURE_2D);
1067 else if (
_target == GL_TEXTURE_3D)
1071 SLuchar* imageData = &buffer[0];
1076 memcpy(imageData, img->data(), img->bytesPerImage());
1077 imageData += img->bytesPerImage();
1082 glTexImage3D(GL_TEXTURE_3D,
1097 else if (
_target == GL_TEXTURE_CUBE_MAP)
1099 for (
SLuint i = 0; i < 6; i++)
1102 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
1120 glGenerateMipmap(GL_TEXTURE_2D);
1141 void SLGLTexture::buildCudaTexture()
1143 if (!_cudaTextureObject)
1145 CUarray texture_ptr;
1147 CUDA_CHECK(cuGraphicsMapResources(1,
1148 &_cudaGraphicsResource,
1150 CUDA_CHECK(cuGraphicsSubResourceGetMappedArray(&texture_ptr,
1151 _cudaGraphicsResource,
1155 CUDA_RESOURCE_DESC res_desc = {};
1157 res_desc.resType = CU_RESOURCE_TYPE_ARRAY;
1158 res_desc.res.array.hArray = texture_ptr;
1160 CUDA_TEXTURE_DESC tex_desc = {};
1161 tex_desc.addressMode[0] = CU_TR_ADDRESS_MODE_WRAP;
1162 tex_desc.addressMode[1] = CU_TR_ADDRESS_MODE_WRAP;
1163 tex_desc.filterMode = CU_TR_FILTER_MODE_LINEAR;
1164 tex_desc.flags = CU_TRSF_NORMALIZED_COORDINATES;
1166 tex_desc.maxMipmapLevelClamp = 99;
1167 tex_desc.minMipmapLevelClamp = 0;
1169 CUDA_CHECK(cuTexObjectCreate(&_cudaTextureObject,
1173 CUDA_CHECK(cuGraphicsUnmapResources(1,
1174 &_cudaGraphicsResource,
1188 assert(texUnit >= 0 && texUnit < 16);
1208 if (!_cudaGraphicsResource)
1212 cuGraphicsGLRegisterImage(&_cudaGraphicsResource,
1215 CU_GRAPHICS_REGISTER_FLAGS_NONE);
1257 SL_WARN_MSG(
"Filtering to expensive to full update in SLGLTexture::fullupdate!");
1327 if (imgIndex <
_images.size())
1335 if (u < 0.0f || u > 1.0f) u -=
floor(u);
1336 if (v < 0.0f || v > 1.0f) v -=
floor(v);
1342 return SLCol4f(c4f[0], c4f[1], c4f[2], c4f[3]);
1348 return SLCol4f(c4f[0], c4f[1], c4f[2], c4f[3]);
1359 _target == GL_TEXTURE_CUBE_MAP &&
1360 "SLGLTexture::getTexelf: Not a cubemap!");
1365 cubeXYZ2UV(cubemapDir.
x, cubemapDir.
y, cubemapDir.
z, index, u, v);
1388 dudv.
x = texel.
r * 2.0f - 1.0f;
1389 dudv.
y = texel.
g * 2.0f - 1.0f;
1402 if (ext ==
"hdr")
return TT_hdr;
1413 if (appendix ==
"_F")
return TT_font;
1487 (GLvoid*)
_images[index]->data());
1519 (GLvoid*)img2.
data());
1540 case TT_font:
return "TT_font";
1541 case TT_hdr:
return "TT_hdr";
1545 case TT_brdfLUT:
return "TT_roughnessCubemap";
1547 default:
return "TT_unknown";
1568 case TT_hdr:
return "HDR";
1574 default:
return "U";
1583 case GL_NEAREST:
return "nearest";
1584 case GL_LINEAR:
return "linear";
1585 case GL_NEAREST_MIPMAP_NEAREST:
return "nearest mipmap nearest";
1586 case GL_LINEAR_MIPMAP_NEAREST:
return "linear mipmap linear";
1587 case GL_NEAREST_MIPMAP_LINEAR:
return "nearest mipmap linear";
1588 case GL_LINEAR_MIPMAP_LINEAR:
return "linear mipmap linear";
1590 default:
return "unknown";
1600 const function<
void(
int)>& onUpdateProgress)
1602 SLint r = sampleRadius;
1606 SLuint numVoxels = volX * volY * volZ;
1608 SLfloat oneOver255 = 1.0f / 255.0f;
1612 if ((
SLint)img->width() != volX ||
1613 (
SLint)img->height() != volY ||
1615 SL_EXIT_MSG(
"SLGLTexture::calc3DGradients: Not all images have the same size!");
1617 for (
int z = r; z < volZ - r; ++z)
1619 for (
int y = r; y < volY - r; ++y)
1621 for (
int x = r; x < volX - r; ++x)
1635 if (length > 0.0001f)
1638 normal.set(0, 0, 0);
1648 if (onUpdateProgress)
1651 onUpdateProgress(progress);
1668 function<
void(
int)> onUpdateProgress)
1670 SLint r = smoothRadius;
1674 SLuint numVoxels = volX * volY * volZ;
1676 SLfloat oneOver255 = 1.0f / 255.0f;
1680 if ((
SLint)img->width() != volX ||
1681 (
SLint)img->height() != volY || img->format() !=
PF_rgba)
1682 SL_EXIT_MSG(
"SLGLTexture::calc3DGradients: Not all images have the same size3@!");
1685 for (
int z = r; z < volZ - r; ++z)
1687 for (
int y = r; y < volY - r; ++y)
1689 for (
int x = r; x < volX - r; ++x)
1695 for (
int fz = z - r; fz <= z + r; ++fz)
1697 for (
int fy = y - r; fy <= y + r; ++fy)
1699 for (
int fx = x - r; fx <= x + r; ++fx)
1719 if (onUpdateProgress)
1722 onUpdateProgress(progress);
1746 _target == GL_TEXTURE_CUBE_MAP &&
1747 "SLGLTexture::cubeUV2XYZ: Not a cubemap!");
1785 SL_EXIT_MSG(
"SLGLTexture::cubeUV2XYZ: Invalid index");
1801 _target == GL_TEXTURE_CUBE_MAP &&
1802 "SLGLTexture::cubeXYZ2UV: Not a cubemap!");
1808 SLint isXPositive = x > 0 ? 1 : 0;
1809 SLint isYPositive = y > 0 ? 1 : 0;
1810 SLint isZPositive = z > 0 ? 1 : 0;
1812 SLfloat maxAxis = 0.0f, uc = 0.0f, vc = 0.0f;
1815 if (isXPositive && absX >= absY && absX >= absZ)
1826 if (!isXPositive && absX >= absY && absX >= absZ)
1837 if (isYPositive && absY >= absX && absY >= absZ)
1848 if (!isYPositive && absY >= absX && absY >= absZ)
1859 if (isZPositive && absZ >= absX && absZ >= absY)
1870 if (!isZPositive && absZ >= absX && absZ >= absY)
1881 u = 0.5f * (uc / maxAxis + 1.0f);
1882 v = -0.5f * (vc / maxAxis + 1.0f);
1884 #ifdef SL_BUILD_WITH_KTX
1887 string SLGLTexture::compressionFormatStr(
int compressionFormat)
1889 switch (compressionFormat)
1891 case KTX_TTF_ETC1_RGB:
return "ETC1_RGB";
1892 case KTX_TTF_ETC2_RGBA:
return "ETC2_RGBA";
1893 case KTX_TTF_BC1_RGB:
return "BC1_RGB";
1894 case KTX_TTF_BC3_RGBA:
return "BC3_RGBA";
1895 case KTX_TTF_BC4_R:
return "BC4_R";
1896 case KTX_TTF_BC5_RG:
return "BC5_RG";
1897 case KTX_TTF_BC7_RGBA:
return "BC7_RGBA";
1898 case KTX_TTF_PVRTC1_4_RGB:
return "PVRTC1_4_RGB";
1899 case KTX_TTF_PVRTC1_4_RGBA:
return "PVRTC1_4_RGBA";
1900 case KTX_TTF_ASTC_4x4_RGBA:
return "ASTC_4x4_RGBA";
1901 case KTX_TTF_PVRTC2_4_RGB:
return "PVRTC2_4_RGB";
1902 case KTX_TTF_PVRTC2_4_RGBA:
return "PVRTC2_4_RGBA";
1903 case KTX_TTF_ETC2_EAC_R11:
return "ETC2_EAC_R11";
1904 case KTX_TTF_ETC2_EAC_RG11:
return "ETC2_EAC_RG11";
1905 case KTX_TTF_RGBA32:
return "RGBA32";
1906 case KTX_TTF_RGB565:
return "RGB565";
1907 case KTX_TTF_BGR565:
return "BGR565";
1908 case KTX_TTF_RGBA4444:
return "RGBA4444";
1909 case KTX_TTF_ETC:
return "ETC";
1910 case KTX_TTF_BC1_OR_3:
return "BC1_OR_3";
1911 default:
return "NOT_COMPRESSED";
1915 string SLGLTexture::ktxErrorStr(
int ktxErrorCode)
1917 switch (ktxErrorCode)
1919 case KTX_SUCCESS:
return "KTX_SUCCESS";
1920 case KTX_FILE_DATA_ERROR:
return "KTX_FILE_DATA_ERROR";
1921 case KTX_FILE_ISPIPE:
return "KTX_FILE_ISPIPE";
1922 case KTX_FILE_OPEN_FAILED:
return "KTX_FILE_OPEN_FAILED";
1923 case KTX_FILE_OVERFLOW:
return "KTX_FILE_OVERFLOW";
1924 case KTX_FILE_READ_ERROR:
return "KTX_FILE_READ_ERROR";
1925 case KTX_FILE_SEEK_ERROR:
return "KTX_FILE_SEEK_ERROR";
1926 case KTX_FILE_UNEXPECTED_EOF:
return "KTX_FILE_UNEXPECTED_EOF";
1927 case KTX_FILE_WRITE_ERROR:
return "KTX_FILE_WRITE_ERROR";
1928 case KTX_GL_ERROR:
return "KTX_GL_ERROR";
1929 case KTX_INVALID_OPERATION:
return "KTX_INVALID_OPERATION";
1930 case KTX_INVALID_VALUE:
return "KTX_INVALID_VALUE";
1931 case KTX_NOT_FOUND:
return "KTX_NOT_FOUND";
1932 case KTX_OUT_OF_MEMORY:
return "KTX_OUT_OF_MEMORY";
1933 case KTX_TRANSCODE_FAILED:
return "KTX_TRANSCODE_FAILED";
1934 case KTX_UNKNOWN_FILE_FORMAT:
return "KTX_UNKNOWN_FILE_FORMAT";
1935 case KTX_UNSUPPORTED_TEXTURE_TYPE:
return "KTX_UNSUPPORTED_TEXTURE_TYPE";
1936 case KTX_UNSUPPORTED_FEATURE:
return "KTX_UNSUPPORTED_FEATURE";
1937 case KTX_LIBRARY_NOT_LINKED:
return "KTX_LIBRARY_NOT_LINKED";
1938 default:
"Unknown KTX_ERROR";
1940 return string(
"Unknown KTX_ERROR");
1950 switch (internalFormat)
1952 case GL_DEPTH_COMPONENT:
return "GL_DEPTH_COMPONENT";
1953 case GL_DEPTH_STENCIL:
return "GL_DEPTH_STENCIL";
1954 case GL_RED:
return "GL_RED";
1955 case GL_RG:
return "GL_RG";
1956 case GL_RGB:
return "GL_RGB";
1957 case GL_RGBA:
return "GL_RGBA";
1958 case GL_R8:
return "GL_R8";
1959 case GL_R8_SNORM:
return "GL_R8_SNORM";
1962 case GL_RG8:
return "GL_RG8";
1963 case GL_RG8_SNORM:
return "GL_RG8_SNORM";
1970 case GL_RGB8_SNORM:
return "GL_RGB8_SNORM";
1977 case GL_RGBA8:
return "GL_RGBA8";
1978 case GL_RGBA8_SNORM:
return "GL_RGBA8_SNORM";
1979 case GL_RGB10_A2:
return "GL_RGB10_A2";
1980 case GL_RGB10_A2UI:
return "GL_RGB10_A2UI";
1983 case GL_SRGB8:
return "GL_SRGB8";
1984 case GL_SRGB8_ALPHA8:
return "GL_SRGB8_ALPHA8";
1985 case GL_R16F:
return "GL_R16F";
1986 case GL_RG16F:
return "GL_RG16F";
1987 case GL_RGB16F:
return "GL_RGB16F";
1988 case GL_RGBA16F:
return "GL_RGBA16F";
1989 case GL_R32F:
return "GL_R32F";
1990 case GL_RG32F:
return "GL_RG32F";
1991 case GL_RGB32F:
return "GL_RGB32F";
1992 case GL_RGBA32F:
return "GL_RGBA32F";
1993 case GL_R11F_G11F_B10F:
return "GL_R11F_G11F_B10F";
1994 case GL_RGB9_E5:
return "GL_RGB9_E5";
1995 case GL_R8I:
return "GL_R8I";
1996 case GL_R8UI:
return "GL_R8UI";
1997 case GL_R16I:
return "GL_R16I";
1998 case GL_R16UI:
return "GL_R16UI";
1999 case GL_R32I:
return "GL_R32I";
2000 case GL_R32UI:
return "GL_R32UI";
2001 case GL_RG8I:
return "GL_RG8I";
2002 case GL_RG8UI:
return "GL_RG8UI";
2003 case GL_RG16I:
return "GL_RG16I";
2004 case GL_RG16UI:
return "GL_RG16UI";
2005 case GL_RG32I:
return "GL_RG32I";
2006 case GL_RG32UI:
return "GL_RG32UI";
2007 case GL_RGB8I:
return "GL_RGB8I";
2008 case GL_RGB8UI:
return "GL_RGB8UI";
2009 case GL_RGB16I:
return "GL_RGB16I";
2010 case GL_RGB16UI:
return "GL_RGB16UI";
2011 case GL_RGB32I:
return "GL_RGB32I";
2012 case GL_RGB32UI:
return "GL_RGB32UI";
2013 case GL_RGBA8I:
return "GL_RGBA8I";
2014 case GL_RGBA8UI:
return "GL_RGBA8UI";
2015 case GL_RGBA16I:
return "GL_RGBA16I";
2016 case GL_RGBA16UI:
return "GL_RGBA16UI";
2017 case GL_RGBA32I:
return "GL_RGBA32I";
2018 case GL_RGBA32UI:
return "GL_RGBA32UI";
2033 default:
return "Unknown format";
CVPixelFormatGL
Pixel format according to OpenGL pixel format defines.
vector< cv::Vec4f > CVVVec4f
#define PROFILE_FUNCTION()
#define SL_WARN_MSG(message)
vector< SLuchar > SLVuchar
vector< SLstring > SLVstring
#define SL_EXIT_MSG(message)
vector< SLushort > SLVushort
@ AT_position
Vertex position as a 2, 3 or 4 component vectors.
@ AT_uv1
Vertex 1st texture coordinate as 2 component vector.
Singleton class for global render state.
#define GL_TEXTURE_MAX_ANISOTROPY_EXT
SLTextureType
Texture type enumeration & their filename appendix for auto type detection.
#define SL_HDR_GL_INTERNAL_FORMAT
#define SL_ANISOTROPY_MAX
#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
vector< SLVec2f > SLVVec2f
SLVec3< SLfloat > SLVec3f
vector< SLCol4f > SLVCol4f
SLVec4< SLfloat > SLCol4f
OpenCV image class with the same interface as the former SLImage class.
void resize(int width, int height)
void load(const string &filename, bool flipVertical=true, bool loadGrayscaleIntoAlpha=false)
Loads the image with the appropriate image loader.
Toplevel holder of the assets meshes, materials, textures and shaders.
SLVGLTexture & textures()
Encapsulation of an OpenGL shader program object.
SLint uniformMatrix4fv(const SLchar *name, SLsizei count, const SLfloat *value, GLboolean transpose=false) const
Passes a 4x4 float matrix values py pointer to the uniform variable "name".
SLint uniform1f(const SLchar *name, SLfloat v0) const
Passes the float value v0 to the uniform variable "name".
SLint uniform1i(const SLchar *name, SLint v0) const
Passes the int values v0 to the uniform variable "name".
static SLGLProgramGeneric * get(SLStdShaderProg id)
Get program reference for given id.
Singleton class holding all OpenGL states.
void activeTexture(SLenum textureUnit)
SLMat4f modelMatrix
Init all states.
static SLGLState * instance()
Public static instance getter for singleton pattern.
SLMat4f viewMatrix
matrix for the active cameras view transform
SLbool hasExtension(const SLstring &e)
SLfloat glVersionNOf() const
void bindTexture(SLenum target, SLuint textureID)
SLMat4f projectionMatrix
matrix for projection transform
SLbool _resizeToPow2
Flag if image should be resized to n^2.
void deleteImages()
Deletes the CVImages in _images. No more texture mapping in ray tracing.
void build2DMipmaps(SLint target, SLuint index)
static string internalFormatStr(int internalFormat)
Returns the internal pixel format from OpenGL.
SLint _bytesPerPixel
Bytes per texture image pixel (images exist either in _images or on the GPU or on both)
SLint _width
Texture image width in pixels (images exist either in _images or on the GPU or on both)
SLfloat _bumpScale
Bump mapping scale factor.
void cubeXYZ2UV(SLfloat x, SLfloat y, SLfloat z, SLint &index, SLfloat &u, SLfloat &v)
Computes the uv and cubemap image index from a unnormalised vector x,y,z.
SLuint _bytesOnGPU
NO. of bytes on GPU.
SLMat4f _tm
texture matrix
SLint _wrap_t
Wrapping in t direction.
SLVec2f dudv(SLfloat u, SLfloat v)
SLint _min_filter
Minification filter.
void load(const SLstring &filename, SLbool flipVertical=true, SLbool loadGrayscaleIntoAlpha=false)
Loads the texture, converts color depth & applies vertical mirroring.
SLint _wrap_s
Wrapping in s direction.
static SLfloat maxAnisotropy
Returns the derivation as [s,t].
SLbool _deleteImageAfterBuild
Flag if images should be deleted after build on GPU.
SLint _height
Texture image height in pixels (images exist either in _images or on the GPU or on both)
SLTextureType _texType
See SLTextureType.
void deleteData(SLbool deleteAlsoOnGPU)
Delete all data (CVImages and GPU textures)
CVVImage _images
Vector of CVImage pointers.
SLint _depth
3D Texture image depth (images exist either in _images or on the GPU or on both)
SLbyte _uvIndex
Texture coordinate index in SLMesh (0 = default)
SLstring typeShortName()
Returns the texture type short.
virtual void build(SLint texUnit)
SLenum _target
texture target
void cubeUV2XYZ(SLint index, SLfloat u, SLfloat v, SLfloat &x, SLfloat &y, SLfloat &z)
Computes the unnormalised vector x,y,z from tex. coords. uv with cubemap index.
SLstring typeName()
Returns the texture type as string.
std::atomic< bool > _needsUpdate
Flag if image needs an single update.
SLint _internalFormat
Internal OpenGL format.
static SLTextureType detectType(const SLstring &filename)
Detects the texture type from the filename appendix (See SLTexType def.)
SLGLTexture()
Default ctor for all stack instances (not created with new)
void calc3DGradients(SLint sampleRadius, const function< void(int)> &onUpdateProgress=nullptr)
void deleteDataGpu()
Deletes the OpenGL texture objects and releases the memory on the GPU.
SLbool _compressedTexture
True for compressed texture format on GPU.
SLuint _bytesInFile
NO. of bytes in file.
SLint _mag_filter
Magnification filter.
SLstring filterString(SLint glFilter)
Returns OpenGL texture filter as string.
void smooth3DGradients(SLint smoothRadius, function< void(int)> onUpdateProgress=nullptr)
static SLuint totalNumBytesOnGPU
Total NO. of bytes used for textures on GPU.
void bindActive(SLuint texUnit=0)
SLbool _autoCalcTM3D
Flag if texture matrix should be calculated from AABB for 3D mapping.
SLGLVertexArray _vaoSprite
Vertex array object for sprite rendering.
void drawSprite(SLbool doUpdate, SLfloat x, SLfloat y, SLfloat w, SLfloat h)
Draws the texture as 2D sprite with OpenGL buffers.
SLbool copyVideoImage(SLint camWidth, SLint camHeight, CVPixelFormatGL glFormat, SLuchar *data, SLbool isContinuous, SLbool isTopLeft)
Copies the image data from a video camera into the current video image.
SLuint _texID
OpenGL texture ID.
SLCol4f getTexelf(SLfloat u, SLfloat v, SLuint imgIndex=0)
SLGLTexture::getTexelf returns a pixel color from u & v texture coordinates.
void clearAttribs()
Clears the attribute definition.
void drawElementsAs(SLGLPrimitiveType primitiveType, SLuint numIndexes=0, SLuint indexOffsetBytes=0)
Draws the VAO by element indices with a primitive type.
void setAttrib(SLGLAttributeType type, SLint elementSize, SLint location, void *dataPointer, SLGLBufferType dataType=BT_float)
Adds a vertex attribute with data pointer and an element size.
SLuint vaoID() const
Returns either the VAO id or the VBO id.
void setIndices(SLuint numIndicesElements, SLGLBufferType indexDataType, void *indexDataElements, SLuint numIndicesEdges=0, void *indexDataEdges=nullptr)
Adds the index array for indexed element drawing.
void generate(SLuint numVertices, SLGLBufferUsage usage=BU_static, SLbool outputInterleaved=true, SLuint divisor=0)
Generates the VA & VB objects for a NO. of vertices.
Base class for all other classes.
const SLstring & name() const
SLIOBuffer readIntoBuffer(std::string path, SLIOStreamKind kind)
Reads an entire file into memory.
bool exists(std::string path, SLIOStreamKind kind)
Checks whether a given file exists.
Utils provides utilities for string & file handling, logging and math functions.
bool containsString(const string &container, const string &search)
Returns true if container contains the search string.
string getFileNameWOExt(const string &pathFilename)
Returns the filename without extension.
unsigned int getFileSize(const string &pathfilename)
Returns the file size in bytes.
string getFileName(const string &pathFilename)
Returns the filename of path-filename string.
string toUpperString(string s)
Returns a string in upper case.
unsigned closestPowerOf2(unsigned num)
Returns the closest power of 2 to a passed number.
string getFileExt(const string &filename)
Returns the file extension without dot in lower case.
Utility struct that holds a pointer and its length.