|
| 1 | +#include "OpenGLCubemap.h" |
| 2 | + |
| 3 | +#include <glad/gl.h> |
| 4 | + |
| 5 | +namespace elv { |
| 6 | + |
| 7 | +OpenGLCubemap::OpenGLCubemap(const std::vector<TextureManager::LoadedTextureInfo>& texturesInfo) |
| 8 | +{ |
| 9 | + // Generate the cubemap texture |
| 10 | + glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &m_id); |
| 11 | + |
| 12 | + // Specify the storage for the cubemap texture |
| 13 | + glTextureStorage2D(m_id, 1, GL_RGB8, texturesInfo[0].width, texturesInfo[0].height); |
| 14 | + |
| 15 | + // Upload the texture data for each face of the cubemap |
| 16 | + for (unsigned int i = 0; i < texturesInfo.size(); ++i) { |
| 17 | + if (texturesInfo[i].data) { |
| 18 | + glTextureSubImage3D( |
| 19 | + m_id, |
| 20 | + 0, // Level of detail |
| 21 | + 0, 0, i, // Offset (x, y, layer) |
| 22 | + texturesInfo[i].width, // Width of the face |
| 23 | + texturesInfo[i].height, // Height of the face |
| 24 | + 1, // Depth (1 for single-layer 2D) |
| 25 | + GL_RGB, // Format of input data |
| 26 | + GL_UNSIGNED_BYTE, // Data type of input data |
| 27 | + texturesInfo[i].data // Pointer to the texture data |
| 28 | + ); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + // Set texture parameters using DSA |
| 33 | + glTextureParameteri(m_id, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 34 | + glTextureParameteri(m_id, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 35 | + glTextureParameteri(m_id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 36 | + glTextureParameteri(m_id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 37 | + glTextureParameteri(m_id, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); |
| 38 | +} |
| 39 | + |
| 40 | +void OpenGLCubemap::Bind() |
| 41 | +{ |
| 42 | + glBindTexture(GL_TEXTURE_CUBE_MAP, m_id); |
| 43 | +} |
| 44 | + |
| 45 | +} // namespace elv |
0 commit comments