mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 12:28:02 +02:00
still finding a good implementation for the compressed texel copy
This commit is contained in:
parent
63c5eea26a
commit
d99f635880
4 changed files with 102 additions and 80 deletions
|
@ -11,6 +11,20 @@
|
||||||
using namespace gpu;
|
using namespace gpu;
|
||||||
using namespace gpu::gl;
|
using namespace gpu::gl;
|
||||||
|
|
||||||
|
bool GLTexelFormat::isCompressed() const {
|
||||||
|
switch (internalFormat) {
|
||||||
|
case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
|
||||||
|
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
|
||||||
|
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
|
||||||
|
case GL_COMPRESSED_RED_RGTC1:
|
||||||
|
case GL_COMPRESSED_RG_RGTC2:
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GLenum GLTexelFormat::evalGLTexelFormatInternal(const gpu::Element& dstFormat) {
|
GLenum GLTexelFormat::evalGLTexelFormatInternal(const gpu::Element& dstFormat) {
|
||||||
GLenum result = GL_RGBA8;
|
GLenum result = GL_RGBA8;
|
||||||
|
|
|
@ -18,6 +18,8 @@ public:
|
||||||
GLenum format;
|
GLenum format;
|
||||||
GLenum type;
|
GLenum type;
|
||||||
|
|
||||||
|
bool isCompressed() const;
|
||||||
|
|
||||||
static GLTexelFormat evalGLTexelFormat(const Element& dstFormat) {
|
static GLTexelFormat evalGLTexelFormat(const Element& dstFormat) {
|
||||||
return evalGLTexelFormat(dstFormat, dstFormat);
|
return evalGLTexelFormat(dstFormat, dstFormat);
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,7 @@ public:
|
||||||
|
|
||||||
Size size() const override { return _size; }
|
Size size() const override { return _size; }
|
||||||
Size _size { 0 };
|
Size _size { 0 };
|
||||||
|
GLTexelFormat _texelFormat;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GL41ResourceTexture : public GL41VariableAllocationTexture {
|
class GL41ResourceTexture : public GL41VariableAllocationTexture {
|
||||||
|
|
|
@ -240,7 +240,10 @@ GL41StrictResourceTexture::GL41StrictResourceTexture(const std::weak_ptr<GLBacke
|
||||||
|
|
||||||
using GL41VariableAllocationTexture = GL41Backend::GL41VariableAllocationTexture;
|
using GL41VariableAllocationTexture = GL41Backend::GL41VariableAllocationTexture;
|
||||||
|
|
||||||
GL41VariableAllocationTexture::GL41VariableAllocationTexture(const std::weak_ptr<GLBackend>& backend, const Texture& texture) : GL41Texture(backend, texture) {
|
GL41VariableAllocationTexture::GL41VariableAllocationTexture(const std::weak_ptr<GLBackend>& backend, const Texture& texture) :
|
||||||
|
GL41Texture(backend, texture),
|
||||||
|
_texelFormat(GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat(), texture.getStoredMipFormat()))
|
||||||
|
{
|
||||||
auto mipLevels = texture.getNumMips();
|
auto mipLevels = texture.getNumMips();
|
||||||
_allocatedMip = mipLevels;
|
_allocatedMip = mipLevels;
|
||||||
_maxAllocatedMip = _populatedMip = mipLevels;
|
_maxAllocatedMip = _populatedMip = mipLevels;
|
||||||
|
@ -321,8 +324,26 @@ void GL41VariableAllocationTexture::promote() {
|
||||||
|
|
||||||
// allocate storage for new level
|
// allocate storage for new level
|
||||||
allocateStorage(targetAllocatedMip);
|
allocateStorage(targetAllocatedMip);
|
||||||
/*
|
|
||||||
withPreservedTexture([&] {
|
withPreservedTexture([&] {
|
||||||
|
if (false && _texelFormat.isCompressed()) {
|
||||||
|
uint16_t mips = _gpuObject.getNumMips();
|
||||||
|
// copy pre-existing mips
|
||||||
|
for (uint16_t mip = _populatedMip; mip < mips; ++mip) {
|
||||||
|
auto mipDimensions = _gpuObject.evalMipDimensions(mip);
|
||||||
|
uint16_t targetMip = mip - _allocatedMip;
|
||||||
|
uint16_t sourceMip = mip - oldAllocatedMip;
|
||||||
|
auto faces = getFaceCount(_target);
|
||||||
|
for (uint8_t face = 0; face < faces; ++face) {
|
||||||
|
glCopyImageSubData(
|
||||||
|
oldId, _target, sourceMip, 0, 0, face,
|
||||||
|
_id, _target, targetMip, 0, 0, face,
|
||||||
|
mipDimensions.x, mipDimensions.y, 1
|
||||||
|
);
|
||||||
|
(void)CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
GLuint fbo { 0 };
|
GLuint fbo { 0 };
|
||||||
glGenFramebuffers(1, &fbo);
|
glGenFramebuffers(1, &fbo);
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
|
||||||
|
@ -344,26 +365,9 @@ void GL41VariableAllocationTexture::promote() {
|
||||||
// destroy the transfer framebuffer
|
// destroy the transfer framebuffer
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||||
glDeleteFramebuffers(1, &fbo);
|
glDeleteFramebuffers(1, &fbo);
|
||||||
|
}
|
||||||
syncSampler();
|
syncSampler();
|
||||||
});*/
|
});
|
||||||
|
|
||||||
uint16_t mips = _gpuObject.getNumMips();
|
|
||||||
// copy pre-existing mips
|
|
||||||
for (uint16_t mip = _populatedMip; mip < mips; ++mip) {
|
|
||||||
auto mipDimensions = _gpuObject.evalMipDimensions(mip);
|
|
||||||
uint16_t targetMip = mip - _allocatedMip;
|
|
||||||
uint16_t sourceMip = mip - oldAllocatedMip;
|
|
||||||
auto faces = getFaceCount(_target);
|
|
||||||
for (uint8_t face = 0; face < faces; ++face) {
|
|
||||||
glCopyImageSubData(
|
|
||||||
oldId, _target, sourceMip, 0, 0, face,
|
|
||||||
_id, _target, targetMip, 0, 0, face,
|
|
||||||
mipDimensions.x, mipDimensions.y, 1
|
|
||||||
);
|
|
||||||
(void)CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// destroy the old texture
|
// destroy the old texture
|
||||||
glDeleteTextures(1, &oldId);
|
glDeleteTextures(1, &oldId);
|
||||||
|
@ -381,32 +385,9 @@ void GL41VariableAllocationTexture::demote() {
|
||||||
uint16_t oldAllocatedMip = _allocatedMip;
|
uint16_t oldAllocatedMip = _allocatedMip;
|
||||||
allocateStorage(_allocatedMip + 1);
|
allocateStorage(_allocatedMip + 1);
|
||||||
_populatedMip = std::max(_populatedMip, _allocatedMip);
|
_populatedMip = std::max(_populatedMip, _allocatedMip);
|
||||||
/*
|
|
||||||
withPreservedTexture([&] {
|
withPreservedTexture([&] {
|
||||||
GLuint fbo { 0 };
|
if (_texelFormat.isCompressed()) {
|
||||||
glCreateFramebuffers(1, &fbo);
|
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
|
|
||||||
|
|
||||||
uint16_t mips = _gpuObject.getNumMips();
|
|
||||||
// copy pre-existing mips
|
|
||||||
for (uint16_t mip = _populatedMip; mip < mips; ++mip) {
|
|
||||||
auto mipDimensions = _gpuObject.evalMipDimensions(mip);
|
|
||||||
uint16_t targetMip = mip - _allocatedMip;
|
|
||||||
uint16_t sourceMip = mip - oldAllocatedMip;
|
|
||||||
for (GLenum target : getFaceTargets(_target)) {
|
|
||||||
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, oldId, sourceMip);
|
|
||||||
(void)CHECK_GL_ERROR();
|
|
||||||
glCopyTexSubImage2D(target, targetMip, 0, 0, 0, 0, mipDimensions.x, mipDimensions.y);
|
|
||||||
(void)CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// destroy the transfer framebuffer
|
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
|
||||||
glDeleteFramebuffers(1, &fbo);
|
|
||||||
|
|
||||||
syncSampler();
|
|
||||||
});*/
|
|
||||||
|
|
||||||
// copy pre-existing mips
|
// copy pre-existing mips
|
||||||
uint16_t mips = _gpuObject.getNumMips();
|
uint16_t mips = _gpuObject.getNumMips();
|
||||||
|
@ -424,7 +405,31 @@ void GL41VariableAllocationTexture::demote() {
|
||||||
(void)CHECK_GL_ERROR();
|
(void)CHECK_GL_ERROR();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
GLuint fbo { 0 };
|
||||||
|
glCreateFramebuffers(1, &fbo);
|
||||||
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
|
||||||
|
|
||||||
|
uint16_t mips = _gpuObject.getNumMips();
|
||||||
|
// copy pre-existing mips
|
||||||
|
for (uint16_t mip = _populatedMip; mip < mips; ++mip) {
|
||||||
|
auto mipDimensions = _gpuObject.evalMipDimensions(mip);
|
||||||
|
uint16_t targetMip = mip - _allocatedMip;
|
||||||
|
uint16_t sourceMip = targetMip + 1;
|
||||||
|
for (GLenum target : getFaceTargets(_target)) {
|
||||||
|
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, oldId, sourceMip);
|
||||||
|
(void)CHECK_GL_ERROR();
|
||||||
|
glCopyTexSubImage2D(target, targetMip, 0, 0, 0, 0, mipDimensions.x, mipDimensions.y);
|
||||||
|
(void)CHECK_GL_ERROR();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// destroy the transfer framebuffer
|
||||||
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||||
|
glDeleteFramebuffers(1, &fbo);
|
||||||
|
}
|
||||||
|
syncSampler();
|
||||||
|
});
|
||||||
|
|
||||||
// destroy the old texture
|
// destroy the old texture
|
||||||
glDeleteTextures(1, &oldId);
|
glDeleteTextures(1, &oldId);
|
||||||
|
|
Loading…
Reference in a new issue