/** * @brief * Constructor */ Texture2DArrayDsa::Texture2DArrayDsa(OpenGLRenderer &openGLRenderer, unsigned int width, unsigned int height, unsigned int numberOfSlices, Renderer::TextureFormat::Enum textureFormat, void *data, unsigned int flags) : Texture2DArray(openGLRenderer, width, height, numberOfSlices) { #ifndef OPENGLRENDERER_NO_STATE_CLEANUP // Backup the currently set alignment GLint openGLAlignmentBackup = 0; glGetIntegerv(GL_UNPACK_ALIGNMENT, &openGLAlignmentBackup); #endif // Set correct alignment glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Upload the base map of the texture (mipmaps are automatically created as soon as the base map is changed) glTextureImage3DEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT, 0, Mapping::getOpenGLInternalFormat(textureFormat), static_cast<GLsizei>(width), static_cast<GLsizei>(height), static_cast<GLsizei>(numberOfSlices), 0, Mapping::getOpenGLFormat(textureFormat), Mapping::getOpenGLType(textureFormat), data); // Build mipmaps automatically on the GPU? if (flags & Renderer::TextureFlag::MIPMAPS) { glGenerateTextureMipmapEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT); glTextureParameteriEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); } else { glTextureParameteriEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } glTextureParameteriEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR); #ifndef OPENGLRENDERER_NO_STATE_CLEANUP // Restore previous alignment glPixelStorei(GL_UNPACK_ALIGNMENT, openGLAlignmentBackup); #endif }
//! glTextureImage3D wrapper. May throw. inline void textureImage3D(const GLuint texture, const GLenum target, const GLint level, const GLint intFmt, const GLsizei w, const GLsizei h, const GLsizei d, const GLint b, const GLenum fmt, const GLenum type, const GLvoid *data) { glTextureImage3DEXT( texture, target, level, intFmt, w, h, d, b, fmt, type, data); checkError("glTextureImage3DEXT"); }
//[-------------------------------------------------------] //[ Public methods ] //[-------------------------------------------------------] Texture2DArrayDsa::Texture2DArrayDsa(OpenGLRenderer &openGLRenderer, uint32_t width, uint32_t height, uint32_t numberOfSlices, Renderer::TextureFormat::Enum textureFormat, const void *data, uint32_t flags) : Texture2DArray(openGLRenderer, width, height, numberOfSlices) { #ifndef OPENGLRENDERER_NO_STATE_CLEANUP // Backup the currently set alignment GLint openGLAlignmentBackup = 0; glGetIntegerv(GL_UNPACK_ALIGNMENT, &openGLAlignmentBackup); #endif // Set correct alignment glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Create the OpenGL texture instance const bool isARB_DSA = openGLRenderer.getExtensions().isGL_ARB_direct_state_access(); if (isARB_DSA) { glCreateTextures(GL_TEXTURE_2D_ARRAY_EXT, 1, &mOpenGLTexture); } else { glGenTextures(1, &mOpenGLTexture); } // Upload the base map of the texture (mipmaps are automatically created as soon as the base map is changed) if (isARB_DSA) { glTextureStorage3D(mOpenGLTexture, 1, Mapping::getOpenGLInternalFormat(textureFormat), static_cast<GLsizei>(width), static_cast<GLsizei>(height), static_cast<GLsizei>(numberOfSlices)); if (nullptr != data) { glTextureSubImage3D(mOpenGLTexture, 0, 0, 0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height), static_cast<GLsizei>(numberOfSlices), Mapping::getOpenGLFormat(textureFormat), Mapping::getOpenGLType(textureFormat), data); } } else { glTextureImage3DEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT, 0, static_cast<GLint>(Mapping::getOpenGLInternalFormat(textureFormat)), static_cast<GLsizei>(width), static_cast<GLsizei>(height), static_cast<GLsizei>(numberOfSlices), 0, Mapping::getOpenGLFormat(textureFormat), Mapping::getOpenGLType(textureFormat), data); } // Build mipmaps automatically on the GPU? (or GPU driver) if (flags & Renderer::TextureFlag::GENERATE_MIPMAPS) { if (isARB_DSA) { glGenerateTextureMipmap(mOpenGLTexture); glTextureParameteri(mOpenGLTexture, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); } else { glGenerateTextureMipmapEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT); glTextureParameteriEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); } } else { if (isARB_DSA) { glTextureParameteri(mOpenGLTexture, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } else { glTextureParameteriEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } } if (isARB_DSA) { glTextureParameteri(mOpenGLTexture, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } else { glTextureParameteriEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } #ifndef OPENGLRENDERER_NO_STATE_CLEANUP // Restore previous alignment glPixelStorei(GL_UNPACK_ALIGNMENT, openGLAlignmentBackup); #endif }
void AbstractTexture::imageImplementationDSA(GLenum target, GLint level, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { glTextureImage3DEXT(_id, target, level, GLint(internalFormat), size.x(), size.y(), size.z(), 0, static_cast<GLenum>(format), static_cast<GLenum>(type), data); }