mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 07:37:20 +02:00
POlishing the size evaluation and trying to debug the compression scheme
This commit is contained in:
parent
e28e85a29c
commit
16174df0f3
5 changed files with 58 additions and 29 deletions
|
@ -193,6 +193,7 @@ enum Semantic {
|
||||||
SBGRA,
|
SBGRA,
|
||||||
|
|
||||||
// These are generic compression format smeantic for images
|
// These are generic compression format smeantic for images
|
||||||
|
_FIRST_COMPRESSED,
|
||||||
COMPRESSED_R,
|
COMPRESSED_R,
|
||||||
|
|
||||||
COMPRESSED_RGB,
|
COMPRESSED_RGB,
|
||||||
|
@ -208,6 +209,8 @@ enum Semantic {
|
||||||
COMPRESSED_BC7_RGBA,
|
COMPRESSED_BC7_RGBA,
|
||||||
COMPRESSED_BC7_SRGBA, */
|
COMPRESSED_BC7_SRGBA, */
|
||||||
|
|
||||||
|
_LAST_COMPRESSED,
|
||||||
|
|
||||||
R11G11B10,
|
R11G11B10,
|
||||||
|
|
||||||
UNIFORM,
|
UNIFORM,
|
||||||
|
@ -240,6 +243,7 @@ public:
|
||||||
|
|
||||||
Dimension getDimension() const { return (Dimension)_dimension; }
|
Dimension getDimension() const { return (Dimension)_dimension; }
|
||||||
|
|
||||||
|
bool isCompressed() const { return (getSemantic() - _FIRST_COMPRESSED <= _LAST_COMPRESSED - _FIRST_COMPRESSED); }
|
||||||
|
|
||||||
Type getType() const { return (Type)_type; }
|
Type getType() const { return (Type)_type; }
|
||||||
bool isNormalized() const { return (getType() >= NORMALIZED_START); }
|
bool isNormalized() const { return (getType() >= NORMALIZED_START); }
|
||||||
|
|
|
@ -130,6 +130,7 @@ public:
|
||||||
|
|
||||||
GLuint _size; // true size as reported by the gl api
|
GLuint _size; // true size as reported by the gl api
|
||||||
GLuint _virtualSize; // theorical size as expected
|
GLuint _virtualSize; // theorical size as expected
|
||||||
|
GLuint _numLevels{ 0 };
|
||||||
|
|
||||||
void transferMip(GLenum target, const Texture::PixelsPointer& mip) const;
|
void transferMip(GLenum target, const Texture::PixelsPointer& mip) const;
|
||||||
|
|
||||||
|
@ -137,7 +138,7 @@ public:
|
||||||
const Texture& _gpuTexture;
|
const Texture& _gpuTexture;
|
||||||
std::atomic<SyncState> _syncState { SyncState::Idle };
|
std::atomic<SyncState> _syncState { SyncState::Idle };
|
||||||
};
|
};
|
||||||
static GLTexture* syncGPUObject(const TexturePointer& texture);
|
static GLTexture* syncGPUObject(const TexturePointer& texture, bool needTransfer = true);
|
||||||
static GLuint getTextureID(const TexturePointer& texture, bool sync = true);
|
static GLuint getTextureID(const TexturePointer& texture, bool sync = true);
|
||||||
|
|
||||||
// very specific for now
|
// very specific for now
|
||||||
|
|
|
@ -83,7 +83,7 @@ GLBackend::GLFramebuffer* GLBackend::syncGPUObject(const Framebuffer& framebuffe
|
||||||
for (auto& b : framebuffer.getRenderBuffers()) {
|
for (auto& b : framebuffer.getRenderBuffers()) {
|
||||||
surface = b._texture;
|
surface = b._texture;
|
||||||
if (surface) {
|
if (surface) {
|
||||||
gltexture = GLBackend::syncGPUObject(surface);
|
gltexture = GLBackend::syncGPUObject(surface, false); // Grab the gltexture and don't transfer
|
||||||
} else {
|
} else {
|
||||||
gltexture = nullptr;
|
gltexture = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ GLBackend::GLFramebuffer* GLBackend::syncGPUObject(const Framebuffer& framebuffe
|
||||||
if (framebuffer.getDepthStamp() != object->_depthStamp) {
|
if (framebuffer.getDepthStamp() != object->_depthStamp) {
|
||||||
auto surface = framebuffer.getDepthStencilBuffer();
|
auto surface = framebuffer.getDepthStencilBuffer();
|
||||||
if (framebuffer.hasDepthStencil() && surface) {
|
if (framebuffer.hasDepthStencil() && surface) {
|
||||||
gltexture = GLBackend::syncGPUObject(surface);
|
gltexture = GLBackend::syncGPUObject(surface, false); // Grab the gltexture and don't transfer
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gltexture) {
|
if (gltexture) {
|
||||||
|
|
|
@ -53,6 +53,8 @@ GLBackend::GLTexture::GLTexture(const Texture& texture) :
|
||||||
_target(gpuToGLTextureType(texture)),
|
_target(gpuToGLTextureType(texture)),
|
||||||
_size(0),
|
_size(0),
|
||||||
_virtualSize(0),
|
_virtualSize(0),
|
||||||
|
// _numLevels(std::max((uint16)1, texture.maxMip())),
|
||||||
|
_numLevels(texture.maxMip() + 1),
|
||||||
_gpuTexture(texture)
|
_gpuTexture(texture)
|
||||||
{
|
{
|
||||||
Backend::incrementTextureGPUCount();
|
Backend::incrementTextureGPUCount();
|
||||||
|
@ -61,15 +63,6 @@ GLBackend::GLTexture::GLTexture(const Texture& texture) :
|
||||||
|
|
||||||
GLsizei width = texture.getWidth();
|
GLsizei width = texture.getWidth();
|
||||||
GLsizei height = texture.getHeight();
|
GLsizei height = texture.getHeight();
|
||||||
GLsizei levels = 1;
|
|
||||||
if (texture.maxMip() > 0) {
|
|
||||||
if (texture.isAutogenerateMips()) {
|
|
||||||
while ((width | height) >> levels) {
|
|
||||||
++levels;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
levels = std::max(1, std::min(texture.maxMip() + 1, levels));
|
|
||||||
}
|
|
||||||
|
|
||||||
GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat());
|
GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat());
|
||||||
|
|
||||||
|
@ -92,12 +85,26 @@ GLBackend::GLTexture::GLTexture(const Texture& texture) :
|
||||||
|
|
||||||
(void)CHECK_GL_ERROR();
|
(void)CHECK_GL_ERROR();
|
||||||
// GO through the process of allocating the correct storage
|
// GO through the process of allocating the correct storage
|
||||||
if (GLEW_VERSION_4_2) {
|
if (GLEW_VERSION_4_2 && !texture.getTexelFormat().isCompressed()) {
|
||||||
glTexStorage2D(_target, levels, texelFormat.internalFormat, width, height);
|
glTexStorage2D(_target, _numLevels, texelFormat.internalFormat, width, height);
|
||||||
|
(void)CHECK_GL_ERROR();
|
||||||
} else {
|
} else {
|
||||||
glTexImage2D(_target, 0, texelFormat.internalFormat, width, height, 0, texelFormat.format, texelFormat.type, 0);
|
glTexParameteri(_target, GL_TEXTURE_BASE_LEVEL, 0);
|
||||||
|
glTexParameteri(_target, GL_TEXTURE_MAX_LEVEL, _numLevels - 1);
|
||||||
|
|
||||||
|
for (int l = 0; l < _numLevels; l++) {
|
||||||
|
if (texture.getType() == gpu::Texture::TEX_CUBE) {
|
||||||
|
for (int face = 0; face < CUBE_NUM_FACES; face++) {
|
||||||
|
glTexImage2D(CUBE_FACE_LAYOUT[face], l, texelFormat.internalFormat, width, height, 0, texelFormat.format, texelFormat.type, NULL);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
glTexImage2D(_target, l, texelFormat.internalFormat, width, height, 0, texelFormat.format, texelFormat.type, NULL);
|
||||||
|
}
|
||||||
|
width = std::max(1, (width / 2));
|
||||||
|
height = std::max(1, (height / 2));
|
||||||
|
}
|
||||||
|
(void)CHECK_GL_ERROR();
|
||||||
}
|
}
|
||||||
(void)CHECK_GL_ERROR();
|
|
||||||
|
|
||||||
syncSampler(texture.getSampler(), texture.getType(), this);
|
syncSampler(texture.getSampler(), texture.getType(), this);
|
||||||
(void)CHECK_GL_ERROR();
|
(void)CHECK_GL_ERROR();
|
||||||
|
@ -118,9 +125,6 @@ GLBackend::GLTexture::~GLTexture() {
|
||||||
Backend::decrementTextureGPUCount();
|
Backend::decrementTextureGPUCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLBackend::GLTexture::isInvalid() const {
|
|
||||||
return _storageStamp < _gpuTexture.getStamp();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GLBackend::GLTexture::setSize(GLuint size) {
|
void GLBackend::GLTexture::setSize(GLuint size) {
|
||||||
Backend::updateTextureGPUMemoryUsage(_size, size);
|
Backend::updateTextureGPUMemoryUsage(_size, size);
|
||||||
|
@ -136,16 +140,30 @@ void GLBackend::GLTexture::updateSize(GLuint virtualSize) {
|
||||||
setVirtualSize(virtualSize);
|
setVirtualSize(virtualSize);
|
||||||
|
|
||||||
GLint gpuSize{ 0 };
|
GLint gpuSize{ 0 };
|
||||||
glGetTexLevelParameteriv(_target, 0, GL_TEXTURE_COMPRESSED, &gpuSize);
|
if (_target == GL_TEXTURE_CUBE_MAP) {
|
||||||
|
glGetTexLevelParameteriv(CUBE_FACE_LAYOUT[0], 0, GL_TEXTURE_COMPRESSED, &gpuSize);
|
||||||
|
} else {
|
||||||
|
glGetTexLevelParameteriv(_target, 0, GL_TEXTURE_COMPRESSED, &gpuSize);
|
||||||
|
}
|
||||||
|
(void)CHECK_GL_ERROR();
|
||||||
|
|
||||||
if (gpuSize) {
|
if (gpuSize) {
|
||||||
GLint baseLevel;
|
GLint baseLevel;
|
||||||
GLint maxLevel;
|
GLint maxLevel;
|
||||||
glGetTexParameteriv(_target, GL_TEXTURE_BASE_LEVEL, &baseLevel);
|
glGetTexParameteriv(_target, GL_TEXTURE_BASE_LEVEL, &baseLevel);
|
||||||
glGetTexParameteriv(_target, GL_TEXTURE_MAX_LEVEL, &maxLevel);
|
glGetTexParameteriv(_target, GL_TEXTURE_MAX_LEVEL, &maxLevel);
|
||||||
|
|
||||||
for (GLint level = baseLevel; level < maxLevel; level++) {
|
for (GLint level = baseLevel; level <= maxLevel; level++) {
|
||||||
GLint levelSize{ 0 };
|
GLint levelSize{ 0 };
|
||||||
glGetTexLevelParameteriv(_target, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &levelSize);
|
if (_target == GL_TEXTURE_CUBE_MAP) {
|
||||||
|
for (int face = 0; face < CUBE_NUM_FACES; face++) {
|
||||||
|
GLint faceSize{ 0 };
|
||||||
|
glGetTexLevelParameteriv(CUBE_FACE_LAYOUT[face], level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &faceSize);
|
||||||
|
levelSize += faceSize;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
glGetTexLevelParameteriv(_target, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &levelSize);
|
||||||
|
}
|
||||||
if (levelSize <= 0) {
|
if (levelSize <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -158,6 +176,10 @@ void GLBackend::GLTexture::updateSize(GLuint virtualSize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool GLBackend::GLTexture::isInvalid() const {
|
||||||
|
return _storageStamp < _gpuTexture.getStamp();
|
||||||
|
}
|
||||||
|
|
||||||
bool GLBackend::GLTexture::isOutdated() const {
|
bool GLBackend::GLTexture::isOutdated() const {
|
||||||
return _contentStamp < _gpuTexture.getDataStamp();
|
return _contentStamp < _gpuTexture.getDataStamp();
|
||||||
}
|
}
|
||||||
|
@ -247,7 +269,7 @@ void GLBackend::GLTexture::postTransfer() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GLBackend::GLTexture* GLBackend::syncGPUObject(const TexturePointer& texturePointer) {
|
GLBackend::GLTexture* GLBackend::syncGPUObject(const TexturePointer& texturePointer, bool needTransfer) {
|
||||||
const Texture& texture = *texturePointer;
|
const Texture& texture = *texturePointer;
|
||||||
if (!texture.isDefined()) {
|
if (!texture.isDefined()) {
|
||||||
// NO texture definition yet so let's avoid thinking
|
// NO texture definition yet so let's avoid thinking
|
||||||
|
@ -269,8 +291,9 @@ GLBackend::GLTexture* GLBackend::syncGPUObject(const TexturePointer& texturePoin
|
||||||
object = new GLTexture(texture);
|
object = new GLTexture(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
// need to have a gpu object?
|
// Object maybe doens't neet to be tranasferred after creation
|
||||||
if (texture.getNumSlices() != 1) {
|
if (!needTransfer) {
|
||||||
|
object->_contentStamp = texturePointer->getDataStamp();
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +406,8 @@ void GLBackend::do_generateTextureMips(Batch& batch, size_t paramOffset) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLTexture* object = GLBackend::syncGPUObject(resourceTexture);
|
// DO not transfer the texture, this call is expected for rendering texture
|
||||||
|
GLTexture* object = GLBackend::syncGPUObject(resourceTexture, false);
|
||||||
if (!object) {
|
if (!object) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,15 +162,15 @@ gpu::Texture* TextureUsage::create2DTextureFromImage(const QImage& srcImage, con
|
||||||
|
|
||||||
|
|
||||||
gpu::Texture* TextureUsage::createAlbedoTextureFromImage(const QImage& srcImage, const std::string& srcImageName) {
|
gpu::Texture* TextureUsage::createAlbedoTextureFromImage(const QImage& srcImage, const std::string& srcImageName) {
|
||||||
return process2DTextureColorFromImage(srcImage, true, true, true);
|
return process2DTextureColorFromImage(srcImage, true, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
gpu::Texture* TextureUsage::createEmissiveTextureFromImage(const QImage& srcImage, const std::string& srcImageName) {
|
gpu::Texture* TextureUsage::createEmissiveTextureFromImage(const QImage& srcImage, const std::string& srcImageName) {
|
||||||
return process2DTextureColorFromImage(srcImage, true, true, true);
|
return process2DTextureColorFromImage(srcImage, true, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
gpu::Texture* TextureUsage::createLightmapTextureFromImage(const QImage& srcImage, const std::string& srcImageName) {
|
gpu::Texture* TextureUsage::createLightmapTextureFromImage(const QImage& srcImage, const std::string& srcImageName) {
|
||||||
return process2DTextureColorFromImage(srcImage, true, true, true);
|
return process2DTextureColorFromImage(srcImage, true, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue