113 lines
3.3 KiB
C++
113 lines
3.3 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "../RHITexture.h"
|
|
|
|
namespace XCEngine {
|
|
namespace RHI {
|
|
|
|
enum class OpenGLTextureType {
|
|
Texture1D,
|
|
Texture2D,
|
|
Texture2DArray,
|
|
Texture3D,
|
|
TextureCube,
|
|
TextureCubeArray
|
|
};
|
|
|
|
enum class OpenGLFormat {
|
|
R8,
|
|
RG8,
|
|
RG32F,
|
|
RGBA8,
|
|
RGBA16F,
|
|
RGBA32F,
|
|
Depth24Stencil8,
|
|
Depth32F,
|
|
CompressedDXT1,
|
|
CompressedDXT5,
|
|
RGBA8_SRGB
|
|
};
|
|
|
|
enum class OpenGLInternalFormat {
|
|
R8 = 1,
|
|
RG8 = 2,
|
|
RG32F = 13,
|
|
RGBA8 = 4,
|
|
RGBA16F = 11,
|
|
RGBA32F = 16,
|
|
Depth24Stencil8 = 38,
|
|
Depth32F = 31,
|
|
CompressedDXT1 = 21,
|
|
CompressedDXT5 = 22,
|
|
RGBA8_SRGB = 39
|
|
};
|
|
|
|
class OpenGLTexture : public RHITexture {
|
|
public:
|
|
OpenGLTexture();
|
|
~OpenGLTexture() override;
|
|
|
|
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 = false);
|
|
void Shutdown() override;
|
|
|
|
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 GetOpenGLType() const { return m_type; }
|
|
|
|
uint32_t GetWidth() const override { return static_cast<uint32_t>(m_width); }
|
|
uint32_t GetHeight() const override { return static_cast<uint32_t>(m_height); }
|
|
uint32_t GetDepth() const override { return static_cast<uint32_t>(m_depth); }
|
|
uint32_t GetMipLevels() const override { return static_cast<uint32_t>(m_mipLevels); }
|
|
|
|
TextureType GetTextureType() const override {
|
|
switch (m_type) {
|
|
case OpenGLTextureType::Texture1D: return TextureType::Texture1D;
|
|
case OpenGLTextureType::Texture2D: return TextureType::Texture2D;
|
|
case OpenGLTextureType::Texture2DArray: return TextureType::Texture2DArray;
|
|
case OpenGLTextureType::Texture3D: return TextureType::Texture3D;
|
|
case OpenGLTextureType::TextureCube: return TextureType::TextureCube;
|
|
case OpenGLTextureType::TextureCubeArray: return TextureType::TextureCubeArray;
|
|
default: return TextureType::Texture2D;
|
|
}
|
|
}
|
|
|
|
void* GetNativeHandle() override { return reinterpret_cast<void*>(static_cast<uintptr_t>(m_texture)); }
|
|
|
|
ResourceStates GetState() const override { return m_state; }
|
|
void SetState(ResourceStates state) override { m_state = state; }
|
|
|
|
const std::string& GetName() const override { return m_name; }
|
|
void SetName(const std::string& name) override { m_name = name; }
|
|
|
|
Format GetFormat() const override { return m_format; }
|
|
void SetFormat(Format format) { m_format = format; }
|
|
|
|
private:
|
|
unsigned int m_texture;
|
|
OpenGLTextureType m_type;
|
|
int m_width;
|
|
int m_height;
|
|
int m_depth;
|
|
int m_mipLevels;
|
|
int m_channels;
|
|
Format m_format = Format::Unknown;
|
|
std::string m_name;
|
|
ResourceStates m_state = ResourceStates::Common;
|
|
};
|
|
|
|
} // namespace RHI
|
|
} // namespace XCEngine
|