bool KRTextureKTX::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, bool compress, bool premultiply_alpha) { int target_dim = lod_max_dim; if(target_dim < m_min_lod_max_dim) target_dim = m_min_lod_max_dim; if(m_blocks.size() == 0) { return false; } // Determine how much memory will be consumed int width = m_header.pixelWidth; int height = m_header.pixelHeight; long memoryRequired = 0; long memoryTransferred = 0; #if GL_EXT_texture_storage if(target == GL_TEXTURE_CUBE_MAP_POSITIVE_X || target == GL_TEXTURE_2D) { // Call glTexStorage2DEXT only for the first uploadTexture used when creating a texture int level_count=0; int max_lod_width=0; int max_lod_height=0; for(std::list<KRDataBlock *>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) { if(width <= target_dim && height <= target_dim) { if(max_lod_width == 0) { max_lod_width = width; max_lod_height = height; } level_count++; } width = width >> 1; if(width < 1) { width = 1; } height = height >> 1; if(height < 1) { height = 1; } } width = m_header.pixelWidth; height = m_header.pixelHeight; if(target == GL_TEXTURE_CUBE_MAP_POSITIVE_X) { glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, level_count, (GLenum)m_header.glInternalFormat, max_lod_width, max_lod_height); } else if(target == GL_TEXTURE_2D) { glTexStorage2DEXT(target, level_count, (GLenum)m_header.glInternalFormat, max_lod_width, max_lod_height); } }
/* This function should only be used without mipmaps and when data == NULL */ void gl_load_texture_image(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * data) { #ifndef HAVE_PSGL #ifdef HAVE_OPENGLES2 if (gl_check_capability(GL_CAPS_TEX_STORAGE_EXT) && internalFormat != GL_BGRA_EXT) { gl_size_format(&internalFormat); glTexStorage2DEXT(target, 1, internalFormat, width, height); } #else if (gl_check_capability(GL_CAPS_TEX_STORAGE) && internalFormat != GL_BGRA_EXT) { gl_size_format(&internalFormat); glTexStorage2D(target, 1, internalFormat, width, height); } #endif else #endif { #ifdef HAVE_OPENGLES if (gl_check_capability(GL_CAPS_GLES3_SUPPORTED)) #endif gl_size_format(&internalFormat); glTexImage2D(target, level, internalFormat, width, height, border, format, type, data); } }
virtual void SetUp() { ANGLETest::SetUp(); glGenTextures(1, &mTexture2D); glGenTextures(1, &mTextureCube); glBindTexture(GL_TEXTURE_2D, mTexture2D); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); EXPECT_GL_NO_ERROR(); glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1); EXPECT_GL_NO_ERROR(); ASSERT_GL_NO_ERROR(); const std::string vertexShaderSource = SHADER_SOURCE ( precision highp float; attribute vec4 position; varying vec2 texcoord; uniform vec2 textureScale; void main() { gl_Position = vec4(position.xy * textureScale, 0.0, 1.0); texcoord = (position.xy * 0.5) + 0.5; }
// Test that CopyTexture cannot redefine an immutable texture and CopySubTexture can copy data to // immutable textures TEST_P(CopyTextureTest, ImmutableTexture) { if (!checkExtensions()) { return; } if (getClientMajorVersion() < 3 && (!extensionEnabled("GL_EXT_texture_storage") || !extensionEnabled("GL_OES_rgb8_rgba8"))) { std::cout << "Test skipped due to missing ES3 or GL_EXT_texture_storage or GL_OES_rgb8_rgba8" << std::endl; return; } GLColor pixels = GLColor::red; glBindTexture(GL_TEXTURE_2D, mTextures[0]); glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 1, 1); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixels); glBindTexture(GL_TEXTURE_2D, mTextures[1]); glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 1, 1); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1], 0); EXPECT_GL_NO_ERROR(); // Should generate an error when the texture is redefined glCopyTextureCHROMIUM(mTextures[0], mTextures[1], GL_RGBA, GL_UNSIGNED_BYTE, false, false, false); EXPECT_GL_ERROR(GL_INVALID_OPERATION); // Should succeed when using CopySubTexture glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 0, 0, 0, 0, 1, 1, false, false, false); EXPECT_GL_NO_ERROR(); // Check that FB is complete. EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); EXPECT_PIXEL_COLOR_EQ(0, 0, pixels); EXPECT_GL_NO_ERROR(); }
bool checkTexStorageFormatSupport(GLenum internalFormat) { EXPECT_GL_NO_ERROR(); GLuint tex = 0; glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexStorage2DEXT(GL_TEXTURE_2D, 1, internalFormat, 1, 1); glDeleteTextures(1, &tex); return (glGetError() == GL_NO_ERROR); }
void OsmAnd::GPUAPI_OpenGLES2::allocateTexture2D(GLenum target, GLsizei levels, GLsizei width, GLsizei height, const TextureFormat format) { // Use glTexStorage2D if possible if (isSupported_EXT_texture_storage) { GL_CHECK_PRESENT(glTexStorage2DEXT); glTexStorage2DEXT(target, levels, static_cast<GLenum>(format), width, height); GL_CHECK_RESULT; return; } // Fallback to dumb allocation GPUAPI_OpenGL::allocateTexture2D(target, levels, width, height, format); }
GLuint TexSubImageBenchmark::createTexture() { // Use tightly packed data glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Generate a texture object GLuint texture; glGenTextures(1, &texture); // Bind the texture object glBindTexture(GL_TEXTURE_2D, texture); glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, mParams.imageWidth, mParams.imageHeight); // Set the filtering mode glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); return texture; }