-
Notifications
You must be signed in to change notification settings - Fork 30
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
Conversation
Use compressed images during subsequent loads
MP-APS/ResourceManager.cpp
Outdated
in.read((char*)compressedData.get(), size); | ||
|
||
glBindTexture(GL_TEXTURE_2D, textureID); | ||
glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, size, compressedData.get()); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
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.
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:
Screenshots
Before
Compiled with
![Screenshot from 2021-12-30 20-30-10](https://user-images.githubusercontent.com/5572045/147795564-5957d5c3-0e7d-439f-b8a8-6e3ecb09a24a.png)
-g
Compiled without
![image](https://user-images.githubusercontent.com/5572045/147795754-706dd454-0354-4661-b452-eb507ab4cd91.png)
-g
After
Compiled with
![Screenshot from 2021-12-30 20-32-05](https://user-images.githubusercontent.com/5572045/147795568-7e7e4e56-12e6-433d-82b2-a5e3e7c0056e.png)
-g
Compiled without
![Screenshot from 2021-12-30 20-34-15](https://user-images.githubusercontent.com/5572045/147795570-360b93d9-19c9-43a9-8cbe-16f259d4f958.png)
-g