Vulkan refactoring - Removed OpenGL implementation for GL_EXT_texture_storage path.
Eliminated dead OpenGL code in KRContext.h Removed GLenum argument from KRTexture2D::uploadTexture and all implementations.
This commit is contained in:
@@ -79,10 +79,6 @@ int KRContext::KRENGINE_SYS_PAGE_SIZE;
|
||||
std::mutex KRContext::g_SurfaceInfoMutex;
|
||||
std::mutex KRContext::g_DeviceInfoMutex;
|
||||
|
||||
const char *KRContext::extension_names[KRENGINE_NUM_EXTENSIONS] = {
|
||||
"GL_EXT_texture_storage"
|
||||
};
|
||||
|
||||
KRContext::log_callback *KRContext::s_log_callback = NULL;
|
||||
void *KRContext::s_log_callback_user_data = NULL;
|
||||
|
||||
|
||||
@@ -115,14 +115,6 @@ public:
|
||||
KRSurfaceManager* getSurfaceManager();
|
||||
KRDeviceManager* getDeviceManager();
|
||||
|
||||
enum {
|
||||
KRENGINE_GL_EXT_texture_storage,
|
||||
KRENGINE_NUM_EXTENSIONS
|
||||
};
|
||||
|
||||
static const char * extension_names[KRENGINE_NUM_EXTENSIONS];
|
||||
static bool extension_available[KRENGINE_NUM_EXTENSIONS];
|
||||
|
||||
void startFrame(float deltaTime);
|
||||
void endFrame(float deltaTime);
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
virtual bool save(const std::string& path);
|
||||
virtual bool save(KRDataBlock &data);
|
||||
|
||||
virtual bool uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, bool compress = false, bool premultiply_alpha = false) = 0;
|
||||
virtual bool uploadTexture(int lod_max_dim, int ¤t_lod_max_dim, bool compress = false, bool premultiply_alpha = false) = 0;
|
||||
virtual void bind(GLuint texture_unit);
|
||||
virtual Vector2i getDimensions() const = 0;
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ long KRTextureKTX::getMemRequiredForSize(int max_dim)
|
||||
return memoryRequired;
|
||||
}
|
||||
|
||||
bool KRTextureKTX::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, bool compress, bool premultiply_alpha)
|
||||
bool KRTextureKTX::uploadTexture(int lod_max_dim, int ¤t_lod_max_dim, bool compress, bool premultiply_alpha)
|
||||
{
|
||||
int target_dim = lod_max_dim;
|
||||
if(target_dim < (int)m_min_lod_max_dim) target_dim = m_min_lod_max_dim;
|
||||
@@ -174,43 +174,6 @@ bool KRTextureKTX::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo
|
||||
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);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Upload texture data
|
||||
int destination_level=0;
|
||||
int source_level = 0;
|
||||
@@ -224,28 +187,15 @@ bool KRTextureKTX::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo
|
||||
if(height > current_lod_max_dim) {
|
||||
current_lod_max_dim = height;
|
||||
}
|
||||
#if GL_APPLE_copy_texture_levels && GL_EXT_texture_storage
|
||||
if(target == GL_TEXTURE_2D && width <= m_current_lod_max_dim && height <= m_current_lod_max_dim) {
|
||||
//GLDEBUG(glCompressedTexImage2D(target, i, (GLenum)m_header.glInternalFormat, width, height, 0, block.length, NULL)); // Allocate, but don't copy
|
||||
// GLDEBUG(glTexImage2D(target, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL));
|
||||
GLDEBUG(glCopyTextureLevelsAPPLE(m_iNewHandle, m_iHandle, source_level, 1));
|
||||
} else {
|
||||
block->lock();
|
||||
GLDEBUG(glCompressedTexSubImage2D(target, destination_level, 0, 0, width, height, (GLenum)m_header.glInternalFormat, (GLsizei)block->getSize(), block->getStart()));
|
||||
block->unlock();
|
||||
|
||||
memoryTransferred += block->getSize(); // memoryTransferred does not include throughput of mipmap levels copied through glCopyTextureLevelsAPPLE
|
||||
}
|
||||
#else
|
||||
block->lock();
|
||||
#if GL_EXT_texture_storage
|
||||
GLDEBUG(glCompressedTexSubImage2D(target, destination_level, 0, 0, width, height, (GLenum)m_header.glInternalFormat, (GLsizei)block->getSize(), block->getStart()));
|
||||
#else
|
||||
/*
|
||||
* TODO - Vulkan Refactoring
|
||||
GLDEBUG(glCompressedTexImage2D(target, destination_level, (GLenum)m_header.glInternalFormat, width, height, 0, (GLsizei)block->getSize(), block->getStart()));
|
||||
#endif
|
||||
*/
|
||||
|
||||
block->unlock();
|
||||
memoryTransferred += (long)block->getSize(); // memoryTransferred does not include throughput of mipmap levels copied through glCopyTextureLevelsAPPLE
|
||||
#endif
|
||||
memoryRequired += (long)block->getSize();
|
||||
//
|
||||
// err = glGetError();
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
virtual ~KRTextureKTX();
|
||||
virtual std::string getExtension();
|
||||
|
||||
bool uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, bool compress = false, bool premultiply_alpha = false);
|
||||
bool uploadTexture(int lod_max_dim, int& current_lod_max_dim, bool compress = false, bool premultiply_alpha = false) override;
|
||||
|
||||
virtual long getMemRequiredForSize(int max_dim);
|
||||
virtual Vector2i getDimensions() const override;
|
||||
|
||||
@@ -178,7 +178,7 @@ long KRTexturePVR::getMemRequiredForSize(int max_dim)
|
||||
return memoryRequired;
|
||||
}
|
||||
|
||||
bool KRTexturePVR::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, bool compress, bool premultiply_alpha)
|
||||
bool KRTexturePVR::uploadTexture(int lod_max_dim, int ¤t_lod_max_dim, bool compress, bool premultiply_alpha)
|
||||
{
|
||||
int target_dim = lod_max_dim;
|
||||
if(target_dim < (int)m_min_lod_max_dim) target_dim = m_min_lod_max_dim;
|
||||
@@ -193,44 +193,6 @@ bool KRTexturePVR::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo
|
||||
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_iWidth;
|
||||
height = m_iHeight;
|
||||
|
||||
if(target == GL_TEXTURE_CUBE_MAP_POSITIVE_X) {
|
||||
glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, level_count, m_internalFormat, max_lod_width, max_lod_height);
|
||||
} else if(target == GL_TEXTURE_2D) {
|
||||
glTexStorage2DEXT(target, level_count, m_internalFormat, max_lod_width, max_lod_height);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Upload texture data
|
||||
int destination_level=0;
|
||||
int source_level = 0;
|
||||
@@ -244,28 +206,14 @@ bool KRTexturePVR::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo
|
||||
if(height > current_lod_max_dim) {
|
||||
current_lod_max_dim = height;
|
||||
}
|
||||
#if GL_APPLE_copy_texture_levels && GL_EXT_texture_storage
|
||||
if(target == GL_TEXTURE_2D && width <= m_current_lod_max_dim && height <= m_current_lod_max_dim) {
|
||||
//GLDEBUG(glCompressedTexImage2D(target, i, m_internalFormat, width, height, 0, block.length, NULL)); // Allocate, but don't copy
|
||||
// GLDEBUG(glTexImage2D(target, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL));
|
||||
GLDEBUG(glCopyTextureLevelsAPPLE(m_iNewHandle, m_iHandle, source_level, 1));
|
||||
} else {
|
||||
block->lock();
|
||||
GLDEBUG(glCompressedTexSubImage2D(target, destination_level, 0, 0, width, height, m_internalFormat, (GLsizei)block->getSize(), block->getStart()));
|
||||
block->unlock();
|
||||
|
||||
memoryTransferred += block->getSize(); // memoryTransferred does not include throughput of mipmap levels copied through glCopyTextureLevelsAPPLE
|
||||
}
|
||||
#else
|
||||
block->lock();
|
||||
#if GL_EXT_texture_storage
|
||||
GLDEBUG(glCompressedTexSubImage2D(target, destination_level, 0, 0, width, height, m_internalFormat, block->getSize(), block->getStart()));
|
||||
#else
|
||||
/*
|
||||
* TODO - Vulkan Refactoring
|
||||
GLDEBUG(glCompressedTexImage2D(target, destination_level, m_internalFormat, width, height, 0, (GLsizei)block->getSize(), block->getStart()));
|
||||
#endif
|
||||
*/
|
||||
block->unlock();
|
||||
memoryTransferred += (long)block->getSize(); // memoryTransferred does not include throughput of mipmap levels copied through glCopyTextureLevelsAPPLE
|
||||
#endif
|
||||
memoryRequired += (long)block->getSize();
|
||||
//
|
||||
// err = glGetError();
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
virtual ~KRTexturePVR();
|
||||
virtual std::string getExtension();
|
||||
|
||||
bool uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, bool compress = false, bool premultiply_alpha = false);
|
||||
bool uploadTexture(int lod_max_dim, int& current_lod_max_dim, bool compress = false, bool premultiply_alpha = false) override;
|
||||
|
||||
virtual long getMemRequiredForSize(int max_dim);
|
||||
virtual Vector2i getDimensions() const override;
|
||||
|
||||
@@ -114,7 +114,7 @@ KRTextureTGA::~KRTextureTGA()
|
||||
|
||||
}
|
||||
|
||||
bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, bool compress, bool premultiply_alpha)
|
||||
bool KRTextureTGA::uploadTexture(int lod_max_dim, int ¤t_lod_max_dim, bool compress, bool premultiply_alpha)
|
||||
{
|
||||
m_pData->lock();
|
||||
TGA_HEADER *pHeader = (TGA_HEADER *)m_pData->getStart();
|
||||
@@ -156,8 +156,11 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo
|
||||
}
|
||||
assert(pSource <= m_pData->getEnd());
|
||||
//#endif
|
||||
/*
|
||||
* TODO - Vulkan Refactoring
|
||||
GLDEBUG(glTexImage2D(target, 0, internal_format, pHeader->width, pHeader->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)converted_image));
|
||||
GLDEBUG(glFinish());
|
||||
*/
|
||||
free(converted_image);
|
||||
|
||||
current_lod_max_dim = m_max_lod_max_dim;
|
||||
@@ -179,9 +182,11 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo
|
||||
pSource += 4;
|
||||
}
|
||||
assert(pSource <= m_pData->getEnd());
|
||||
|
||||
/*
|
||||
* TODO - Vulkan Refactoring
|
||||
GLDEBUG(glTexImage2D(target, 0, internal_format, pHeader->width, pHeader->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)converted_image));
|
||||
GLDEBUG(glFinish());
|
||||
*/
|
||||
free(converted_image);
|
||||
} else {
|
||||
unsigned char *converted_image = (unsigned char *)malloc(pHeader->width * pHeader->height * 4);
|
||||
@@ -197,8 +202,11 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo
|
||||
pSource += 4;
|
||||
}
|
||||
assert(pSource <= m_pData->getEnd());
|
||||
/*
|
||||
* TODO - Vulkan Refactoring
|
||||
GLDEBUG(glTexImage2D(target, 0, internal_format, pHeader->width, pHeader->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)pData));
|
||||
GLDEBUG(glFinish());
|
||||
*/
|
||||
free(converted_image);
|
||||
}
|
||||
|
||||
@@ -273,8 +281,11 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo
|
||||
assert(pSource <= m_pData->getEnd());
|
||||
assert(pDest == pEnd);
|
||||
}
|
||||
/*
|
||||
* TODO - Vulkan Refactoring
|
||||
GLDEBUG(glTexImage2D(target, 0, internal_format, pHeader->width, pHeader->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)converted_image));
|
||||
GLDEBUG(glFinish());
|
||||
*/
|
||||
free(converted_image);
|
||||
current_lod_max_dim = m_max_lod_max_dim;
|
||||
}
|
||||
@@ -311,8 +322,11 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo
|
||||
}
|
||||
assert(pSource <= m_pData->getEnd());
|
||||
assert(pDest == pEnd);
|
||||
/*
|
||||
* TODO - Vulkan Refactoring
|
||||
GLDEBUG(glTexImage2D(target, 0, internal_format, pHeader->width, pHeader->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)converted_image));
|
||||
GLDEBUG(glFinish());
|
||||
*/
|
||||
free(converted_image);
|
||||
current_lod_max_dim = m_max_lod_max_dim;
|
||||
}
|
||||
@@ -347,7 +361,7 @@ KRTexture *KRTextureTGA::compress(bool premultiply_alpha)
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compressed_handle));
|
||||
|
||||
int current_max_dim = 0;
|
||||
if(!uploadTexture(GL_TEXTURE_2D, m_max_lod_max_dim, current_max_dim, true, premultiply_alpha)) {
|
||||
if(!uploadTexture(m_max_lod_max_dim, current_max_dim, true, premultiply_alpha)) {
|
||||
assert(false); // Failed to upload the texture
|
||||
}
|
||||
GLDEBUG(glGenerateMipmap(GL_TEXTURE_2D));
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
virtual ~KRTextureTGA();
|
||||
virtual std::string getExtension();
|
||||
|
||||
bool uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, bool compress = false, bool premultiply_alpha = false);
|
||||
bool uploadTexture(int lod_max_dim, int& current_lod_max_dim, bool compress = false, bool premultiply_alpha = false) override;
|
||||
|
||||
#if !TARGET_OS_IPHONE && !defined(ANDROID)
|
||||
virtual KRTexture *compress(bool premultiply_alpha = false);
|
||||
|
||||
Reference in New Issue
Block a user