Enhance OpenGLTexture with more texture types

- Add OpenGLTextureType enum (1D, 2D, 2DArray, 3D, Cube, CubeArray)
- Add OpenGLFormat enum for texture formats
- Add Initialize() method for generic texture creation
- Add InitializeCubeMap() for cubemap textures
- Add BindImage() for image load/store
- Add GenerateMipmap(), SetFiltering(), SetWrapping() methods
- Add GetType(), GetMipLevels(), GetDepth() getters
This commit is contained in:
2026-03-17 02:10:53 +08:00
parent 56c32bfbde
commit a54666df11
2 changed files with 206 additions and 12 deletions

View File

@@ -2,30 +2,77 @@
#include <string>
#include <GLFW/glfw3.h>
#include <vector>
namespace XCEngine {
namespace RHI {
enum class OpenGLTextureType {
Texture1D,
Texture2D,
Texture2DArray,
Texture3D,
TextureCube,
TextureCubeArray
};
enum class OpenGLFormat {
R8,
RG8,
RGBA8,
RGBA16F,
RGBA32F,
Depth24Stencil8,
Depth32F,
CompressedDXT1,
CompressedDXT5
};
enum class OpenGLInternalFormat {
R8 = 1,
RG8 = 2,
RGBA8 = 4,
RGBA16F = 11,
RGBA32F = 16,
Depth24Stencil8 = 38,
Depth32F = 31,
CompressedDXT1 = 21,
CompressedDXT5 = 22
};
class OpenGLTexture {
public:
OpenGLTexture();
~OpenGLTexture();
bool Initialize(OpenGLTextureType type, int width, int height, int depth, int mipLevels, OpenGLFormat format, const void* data = nullptr);
bool Initialize2D(int width, int height, int channels, const void* data, bool generateMipmap = true);
bool InitializeCubeMap(int size, int mipLevels, OpenGLFormat format, const void* data = nullptr);
bool LoadFromFile(const char* path, bool flipVertical = true);
void Shutdown();
void Bind(int slot = 0) const;
void Unbind() const;
void BindImage(int slot, bool read, bool write) const;
void GenerateMipmap();
void SetFiltering(int minFilter, int magFilter);
void SetWrapping(int wrapS, int wrapT, int wrapR = -1);
unsigned int GetID() const { return m_texture; }
OpenGLTextureType GetType() const { return m_type; }
int GetWidth() const { return m_width; }
int GetHeight() const { return m_height; }
int GetDepth() const { return m_depth; }
int GetMipLevels() const { return m_mipLevels; }
private:
unsigned int m_texture;
OpenGLTextureType m_type;
int m_width;
int m_height;
int m_depth;
int m_mipLevels;
int m_channels;
};