mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:14:59 +02:00
work in progress
This commit is contained in:
parent
35e216ee19
commit
69a90d6f86
2 changed files with 46 additions and 25 deletions
|
@ -37,8 +37,9 @@ class GL41Backend : public GLBackend {
|
|||
public:
|
||||
static const GLint TRANSFORM_OBJECT_SLOT { 31 };
|
||||
static const GLint RESOURCE_TRANSFER_TEX_UNIT { 32 };
|
||||
static const GLint RESOURCE_BUFFER_TEXBUF_TEX_UNIT { 33 };
|
||||
static const GLint RESOURCE_BUFFER_SLOT0_TEX_UNIT { 34 };
|
||||
static const GLint RESOURCE_TRANSFER_EXTRA_TEX_UNIT { 33 };
|
||||
static const GLint RESOURCE_BUFFER_TEXBUF_TEX_UNIT { 34 };
|
||||
static const GLint RESOURCE_BUFFER_SLOT0_TEX_UNIT { 35 };
|
||||
|
||||
explicit GL41Backend(bool syncCache) : Parent(syncCache) {}
|
||||
GL41Backend() : Parent() {}
|
||||
|
|
|
@ -386,28 +386,47 @@ void GL41VariableAllocationTexture::demote() {
|
|||
allocateStorage(_allocatedMip + 1);
|
||||
_populatedMip = std::max(_populatedMip, _allocatedMip);
|
||||
|
||||
withPreservedTexture([&] {
|
||||
if (_texelFormat.isCompressed()) {
|
||||
|
||||
// copy pre-existing mips
|
||||
uint16_t mips = _gpuObject.getNumMips();
|
||||
for (uint16_t mip = _populatedMip; mip < mips; ++mip) {
|
||||
auto mipDimensions = _gpuObject.evalMipDimensions(mip);
|
||||
uint16_t targetMip = mip - _allocatedMip;
|
||||
uint16_t sourceMip = targetMip + 1;
|
||||
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();
|
||||
}
|
||||
if (_texelFormat.isCompressed()) {
|
||||
GLuint pbo { 0 };
|
||||
glGenBuffers(1, &pbo);
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_EXTRA_TEX_UNIT);
|
||||
glBindTexture(_target, oldId);
|
||||
|
||||
glGetTexLevelParameteriv(_target, sourceMip, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &size);
|
||||
|
||||
// copy pre-existing mips
|
||||
uint16_t mips = _gpuObject.getNumMips();
|
||||
for (uint16_t mip = _populatedMip; mip < mips; ++mip) {
|
||||
auto mipDimensions = _gpuObject.evalMipDimensions(mip);
|
||||
uint16_t targetMip = mip - _allocatedMip;
|
||||
uint16_t sourceMip = targetMip + 1;
|
||||
GLint size { 0 };
|
||||
GLint internalFormat;
|
||||
glGetTexLevelParameteriv(_target, sourceMip, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &size);
|
||||
|
||||
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 {
|
||||
}
|
||||
|
||||
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||
glDeleteBuffers(1, &pbo);
|
||||
|
||||
} else {
|
||||
withPreservedTexture([&] {
|
||||
GLuint fbo { 0 };
|
||||
glCreateFramebuffers(1, &fbo);
|
||||
glGenFramebuffers(1, &fbo);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
|
||||
|
||||
uint16_t mips = _gpuObject.getNumMips();
|
||||
|
@ -427,9 +446,10 @@ void GL41VariableAllocationTexture::demote() {
|
|||
// destroy the transfer framebuffer
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
glDeleteFramebuffers(1, &fbo);
|
||||
}
|
||||
syncSampler();
|
||||
});
|
||||
|
||||
syncSampler();
|
||||
});
|
||||
}
|
||||
|
||||
// destroy the old texture
|
||||
glDeleteTextures(1, &oldId);
|
||||
|
|
Loading…
Reference in a new issue