Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use texture compression in ResourceManager::LoadTexture #20

Merged
merged 3 commits into from
Jan 6, 2022

Conversation

htmlboss
Copy link
Owner

@htmlboss htmlboss commented Dec 31, 2021

Was playing around with Valgrind to track down what I felt was excessive memory usage by the engine, which brought me to learn about on-the-fly texture compression offered by the OpenGL driver. Figured we should use that to reduce system memory usage, with the downside being we will have longer startup time as now the driver has to compress the images on the fly before uploading to the GPU.

  • Loads/saves compressed textures to disk in Data/cache/textures/*.bin.

Used the corresponding enums from Table 3 in https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexImage2D.xhtml

With the OOB PBR Sponza scene, here are the results:

RAM VRAM
Without compression 610 MB 1657 MB
With compression 397 MB 1464 MB
Difference -35% -12%

Screenshots

Before

Compiled with -g
Screenshot from 2021-12-30 20-30-10

Compiled without -g
image

After

Compiled with -g
Screenshot from 2021-12-30 20-32-05

Compiled without -g
Screenshot from 2021-12-30 20-34-15

@htmlboss htmlboss self-assigned this Dec 31, 2021
Use compressed images during subsequent loads
in.read((char*)compressedData.get(), size);

glBindTexture(GL_TEXTURE_2D, textureID);
glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, size, compressedData.get());
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format = GL_RGBA;
break;
}
GLint compressed = GL_FALSE;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out.write((char*)(&desc.width), sizeof(CompressedImageDesc::width));
out.write((char*)(&desc.height), sizeof(CompressedImageDesc::height));
out.write((char*)(&desc.format), sizeof(CompressedImageDesc::format));
out.write((char*)(desc.data.get()), desc.size);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use c-style cast since reinterpret_case cannot cast away const and I'd rather not nest a const_cast in here since it's very verbose

@htmlboss htmlboss merged commit 9a6c5fb into master Jan 6, 2022
@htmlboss htmlboss deleted the enable-texture-compression branch January 6, 2022 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant