feat(RHI): 实现 RHIBuffer, RHITexture, RHIShader 抽象基类

- 新增 RHIBuffer, RHITexture, RHIShader 抽象基类
- D3D12Buffer/Texture/Shader 继承抽象基类
- OpenGLBuffer/Texture/Shader 继承抽象基类
- 添加 RHICapabilities, RHIDevice 头文件
- RHIEnums 添加 Fragment/TessControl/TessEvaluation
- 文档更新差异处理策略
This commit is contained in:
2026-03-17 17:26:41 +08:00
parent f2ae95e0a7
commit e38d5ccede
17 changed files with 3113 additions and 119 deletions

View File

@@ -4,6 +4,7 @@
#include <wrl/client.h>
#include <string>
#include "../RHIBuffer.h"
#include "D3D12Enum.h"
using Microsoft::WRL::ComPtr;
@@ -11,16 +12,16 @@ using Microsoft::WRL::ComPtr;
namespace XCEngine {
namespace RHI {
class D3D12Buffer {
class D3D12Buffer : public RHIBuffer {
public:
D3D12Buffer();
~D3D12Buffer();
~D3D12Buffer() override;
bool Initialize(ID3D12Device* device, uint64_t size, D3D12_RESOURCE_STATES initialState = D3D12_RESOURCE_STATE_COMMON, D3D12_HEAP_TYPE heapType = D3D12_HEAP_TYPE_DEFAULT);
bool InitializeFromExisting(ID3D12Resource* resource);
bool InitializeWithData(ID3D12Device* device, ID3D12GraphicsCommandList* commandList,
const void* data, uint64_t size, D3D12_RESOURCE_STATES finalState);
void Shutdown();
void Shutdown() override;
ID3D12Resource* GetResource() const { return m_resource.Get(); }
D3D12_RESOURCE_DESC GetDesc() const { return m_resource->GetDesc(); }
@@ -29,21 +30,25 @@ public:
void UpdateData(const void* data, uint64_t size);
void* GetNativeHandle() const { return m_resource.Get(); }
void* GetNativeHandle() override { return m_resource.Get(); }
ResourceStates GetState() const { return m_state; }
void SetState(ResourceStates state) { m_state = state; }
uint64_t GetGPUAddress() const { return m_resource->GetGPUVirtualAddress(); }
size_t GetSize() const { return GetDesc().Width; }
uint64_t GetSize() const override { return GetDesc().Width; }
const std::string& GetName() const { return m_name; }
void SetName(const std::string& name) { m_name = name; }
const std::string& GetName() const override { return m_name; }
void SetName(const std::string& name) override { m_name = name; }
uint32_t GetStride() const { return m_stride; }
BufferType GetBufferType() const { return m_bufferType; }
uint32_t GetStride() const override { return m_stride; }
BufferType GetBufferType() const override { return m_bufferType; }
void SetStride(uint32_t stride) { m_stride = stride; }
void SetBufferType(BufferType type) { m_bufferType = type; }
void SetStride(uint32_t stride) override { m_stride = stride; }
void SetBufferType(BufferType type) override { m_bufferType = type; }
void* Map() override;
void Unmap() override;
void SetData(const void* data, size_t size, size_t offset = 0) override;
private:
ComPtr<ID3D12Resource> m_resource;

View File

@@ -5,6 +5,7 @@
#include <wrl/client.h>
#include <string>
#include "../RHIShader.h"
#include "D3D12Enum.h"
#include "../RHITypes.h"
@@ -13,21 +14,33 @@ using Microsoft::WRL::ComPtr;
namespace XCEngine {
namespace RHI {
class D3D12Shader {
class D3D12Shader : public RHIShader {
public:
D3D12Shader();
~D3D12Shader();
~D3D12Shader() override;
bool CompileFromFile(const wchar_t* filePath, const char* entryPoint, const char* target);
bool Compile(const void* sourceData, size_t sourceSize, const char* entryPoint, const char* target);
void Shutdown();
bool CompileFromFile(const wchar_t* filePath, const char* entryPoint, const char* target) override;
bool Compile(const void* sourceData, size_t sourceSize, const char* entryPoint, const char* target) override;
void Shutdown() override;
const D3D12_SHADER_BYTECODE GetD3D12Bytecode() const;
const void* GetBytecode() const;
size_t GetBytecodeSize() const;
ShaderType GetType() const;
ShaderType GetType() const override;
const InputLayoutDesc& GetInputLayout() const;
void* GetNativeHandle() override { return m_bytecode.Get(); }
bool IsValid() const override { return m_bytecode != nullptr; }
void Bind() override { }
void Unbind() override { }
void SetInt(const char* name, int value) override { }
void SetFloat(const char* name, float value) override { }
void SetVec3(const char* name, float x, float y, float z) override { }
void SetVec4(const char* name, float x, float y, float z, float w) override { }
void SetMat4(const char* name, const float* value) override { }
private:
ComPtr<ID3DBlob> m_bytecode;
ComPtr<ID3DBlob> m_error;

View File

@@ -4,6 +4,7 @@
#include <wrl/client.h>
#include <string>
#include "../RHITexture.h"
#include "D3D12Enum.h"
using Microsoft::WRL::ComPtr;
@@ -11,39 +12,39 @@ using Microsoft::WRL::ComPtr;
namespace XCEngine {
namespace RHI {
class D3D12Texture {
class D3D12Texture : public RHITexture {
public:
D3D12Texture();
~D3D12Texture();
~D3D12Texture() override;
bool Initialize(ID3D12Device* device, const D3D12_RESOURCE_DESC& desc, D3D12_RESOURCE_STATES initialState = D3D12_RESOURCE_STATE_COMMON);
bool InitializeFromExisting(ID3D12Resource* resource);
bool InitializeFromData(ID3D12Device* device, ID3D12GraphicsCommandList* commandList,
const void* pixelData, uint32_t width, uint32_t height, DXGI_FORMAT format);
bool InitializeDepthStencil(ID3D12Device* device, uint32_t width, uint32_t height, DXGI_FORMAT format = DXGI_FORMAT_D24_UNORM_S8_UINT);
void Shutdown();
void Shutdown() override;
ID3D12Resource* GetResource() const { return m_resource.Get(); }
D3D12_RESOURCE_DESC GetDesc() const { return m_resource->GetDesc(); }
uint32_t GetWidth() const { return static_cast<uint32_t>(GetDesc().Width); }
uint32_t GetHeight() const { return GetDesc().Height; }
uint32_t GetDepth() const { return GetDesc().DepthOrArraySize; }
uint32_t GetMipLevels() const { return GetDesc().MipLevels; }
uint32_t GetWidth() const override { return static_cast<uint32_t>(GetDesc().Width); }
uint32_t GetHeight() const override { return GetDesc().Height; }
uint32_t GetDepth() const override { return GetDesc().DepthOrArraySize; }
uint32_t GetMipLevels() const override { return GetDesc().MipLevels; }
void* GetNativeHandle() const { return m_resource.Get(); }
ResourceStates GetState() const { return m_state; }
void SetState(ResourceStates state) { m_state = state; }
void* GetNativeHandle() override { return m_resource.Get(); }
ResourceStates GetState() const override { return m_state; }
void SetState(ResourceStates state) override { m_state = state; }
uint64_t GetGPUAddress() const { return m_resource->GetGPUVirtualAddress(); }
size_t GetSize() const { return GetDesc().Width * GetDesc().Height * GetDesc().DepthOrArraySize; }
const std::string& GetName() const { return m_name; }
void SetName(const std::string& name) { m_name = name; }
const std::string& GetName() const override { return m_name; }
void SetName(const std::string& name) override { m_name = name; }
uint32_t GetArraySize() const { return GetDesc().DepthOrArraySize; }
Format GetFormat() const { return static_cast<Format>(GetDesc().Format); }
TextureType GetTextureType() const { return TextureType::Texture2D; }
Format GetFormat() const override { return static_cast<Format>(GetDesc().Format); }
TextureType GetTextureType() const override { return TextureType::Texture2D; }
private:
ComPtr<ID3D12Resource> m_resource;

View File

@@ -3,6 +3,8 @@
#include <string>
#include <GLFW/glfw3.h>
#include "../RHIBuffer.h"
namespace XCEngine {
namespace RHI {
@@ -18,35 +20,49 @@ enum class OpenGLBufferType {
ShaderBindingTable
};
class OpenGLBuffer {
class OpenGLBuffer : public RHIBuffer {
public:
OpenGLBuffer();
~OpenGLBuffer();
~OpenGLBuffer() override;
bool Initialize(OpenGLBufferType type, size_t size, const void* data = nullptr, bool dynamic = false);
bool InitializeVertexBuffer(const void* data, size_t size);
bool InitializeIndexBuffer(const void* data, size_t size);
void Shutdown();
void Shutdown() override;
void Bind() const;
void Unbind() const;
void BindBase(unsigned int target, unsigned int index) const;
void* Map();
void Unmap();
void SetData(const void* data, size_t size, size_t offset = 0);
void* Map() override;
void Unmap() override;
void SetData(const void* data, size_t size, size_t offset = 0) override;
unsigned int GetID() const { return m_buffer; }
size_t GetSize() const { return m_size; }
uint64_t GetSize() const override { return m_size; }
OpenGLBufferType GetType() const { return m_type; }
bool IsDynamic() const { return m_dynamic; }
BufferType GetBufferType() const override { return m_bufferType; }
void SetBufferType(BufferType type) override { m_bufferType = type; }
uint32_t GetStride() const override { return m_stride; }
void SetStride(uint32_t stride) override { m_stride = stride; }
void* GetNativeHandle() override { return reinterpret_cast<void*>(static_cast<uintptr_t>(m_buffer)); }
const std::string& GetName() const override { return m_name; }
void SetName(const std::string& name) override { m_name = name; }
private:
unsigned int m_buffer;
size_t m_size;
bool m_isIndexBuffer;
bool m_dynamic;
OpenGLBufferType m_type;
BufferType m_bufferType = BufferType::Vertex;
uint32_t m_stride = 0;
std::string m_name;
};
} // namespace RHI

View File

@@ -4,22 +4,19 @@
#include <GLFW/glfw3.h>
#include <vector>
#include "../RHIShader.h"
namespace XCEngine {
namespace RHI {
enum class ShaderType {
Vertex,
Fragment,
Geometry,
Compute,
TessControl,
TessEvaluation
};
class OpenGLShader {
class OpenGLShader : public RHIShader {
public:
OpenGLShader();
~OpenGLShader();
~OpenGLShader() override;
bool CompileFromFile(const wchar_t* filePath, const char* entryPoint, const char* target) override;
bool Compile(const void* sourceData, size_t sourceSize, const char* entryPoint, const char* target) override;
void Shutdown() override;
bool CompileFromFile(const char* vertexPath, const char* fragmentPath);
bool CompileFromFile(const char* vertexPath, const char* fragmentPath, const char* geometryPath);
@@ -27,33 +24,34 @@ public:
bool Compile(const char* vertexSource, const char* fragmentSource, const char* geometrySource);
bool CompileCompute(const char* computeSource);
bool Compile(const char* source, ShaderType type);
void Shutdown();
void Use() const;
void Bind() const { Use(); }
void Unbind() const;
void Bind() override { Use(); }
void Unbind() override;
void SetInt(const std::string& name, int value) const;
void SetIntArray(const std::string& name, const int* values, unsigned int count) const;
void SetFloat(const std::string& name, float value) const;
void SetFloatArray(const std::string& name, const float* values, unsigned int count) const;
void SetVec2(const std::string& name, float x, float y) const;
void SetVec2(const std::string& name, const float* values) const;
void SetVec3(const std::string& name, float x, float y, float z) const;
void SetVec3(const std::string& name, const float* values) const;
void SetVec4(const std::string& name, float x, float y, float z, float w) const;
void SetVec4(const std::string& name, const float* values) const;
void SetMat2(const std::string& name, const float* value) const;
void SetMat3(const std::string& name, const float* value) const;
void SetMat4(const std::string& name, const float* value) const;
void SetMat4Array(const std::string& name, const float* values, unsigned int count) const;
void SetInt(const char* name, int value) override;
void SetIntArray(const char* name, const int* values, unsigned int count);
void SetFloat(const char* name, float value) override;
void SetFloatArray(const char* name, const float* values, unsigned int count);
void SetVec3(const char* name, float x, float y, float z) override;
void SetVec3(const char* name, const float* values);
void SetVec4(const char* name, float x, float y, float z, float w) override;
void SetVec4(const char* name, const float* values);
void SetMat2(const char* name, const float* value);
void SetMat3(const char* name, const float* value);
void SetMat4(const char* name, const float* value) override;
void SetMat4Array(const char* name, const float* values, unsigned int count);
int GetUniformLocation(const std::string& name) const;
int GetUniformLocation(const char* name) const;
unsigned int GetID() const { return m_program; }
bool IsValid() const { return m_program != 0; }
void* GetNativeHandle() override { return reinterpret_cast<void*>(static_cast<uintptr_t>(m_program)); }
bool IsValid() const override { return m_program != 0; }
ShaderType GetType() const override { return m_type; }
private:
unsigned int m_program;
ShaderType m_type = ShaderType::Vertex;
bool CheckCompileErrors(unsigned int shader, const char* type);
bool CheckLinkErrors(unsigned int program);
};

View File

@@ -4,6 +4,8 @@
#include <GLFW/glfw3.h>
#include <vector>
#include "../RHITexture.h"
namespace XCEngine {
namespace RHI {
@@ -40,16 +42,16 @@ enum class OpenGLInternalFormat {
CompressedDXT5 = 22
};
class OpenGLTexture {
class OpenGLTexture : public RHITexture {
public:
OpenGLTexture();
~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 = true);
void Shutdown();
void Shutdown() override;
void Bind(int slot = 0) const;
void Unbind() const;
@@ -60,11 +62,35 @@ public:
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; }
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 ResourceStates::Common; }
void SetState(ResourceStates state) override { }
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;
@@ -74,6 +100,8 @@ private:
int m_depth;
int m_mipLevels;
int m_channels;
Format m_format = Format::Unknown;
std::string m_name;
};
} // namespace RHI

View File

@@ -0,0 +1,33 @@
#pragma once
#include "RHITypes.h"
#include "RHIEnums.h"
#include <string>
namespace XCEngine {
namespace RHI {
class RHIBuffer {
public:
virtual ~RHIBuffer() = default;
virtual void* Map() = 0;
virtual void Unmap() = 0;
virtual void SetData(const void* data, size_t size, size_t offset = 0) = 0;
virtual uint64_t GetSize() const = 0;
virtual BufferType GetBufferType() const = 0;
virtual void SetBufferType(BufferType type) = 0;
virtual uint32_t GetStride() const = 0;
virtual void SetStride(uint32_t stride) = 0;
virtual void* GetNativeHandle() = 0;
virtual const std::string& GetName() const = 0;
virtual void SetName(const std::string& name) = 0;
virtual void Shutdown() = 0;
};
} // namespace RHI
} // namespace XCEngine

View File

@@ -0,0 +1,47 @@
#pragma once
#include <cstdint>
namespace XCEngine {
namespace RHI {
struct RHICapabilities {
bool bSupportsRayTracing = false;
bool bSupportsMeshShaders = false;
bool bSupportsExplicitMultiThreading = false;
bool bSupportsGeometryShaders = false;
bool bSupportsTessellation = false;
bool bSupportsComputeShaders = false;
bool bSupportsDepthBoundsTest = false;
bool bSupportsAlphaToCoverage = false;
bool bSupportsIndependentBlend = false;
bool bSupportsLogicOps = false;
bool bSupportsMultiViewport = false;
bool bSupportsConservativeRasterization = false;
bool bSupportsProgrammableSamplePositions = false;
uint32_t maxTexture2DSize = 0;
uint32_t maxTexture3DSize = 0;
uint32_t maxTextureCubeSize = 0;
uint32_t maxRenderTargets = 0;
uint32_t maxViewports = 0;
uint32_t maxVertexAttribs = 0;
uint32_t maxConstantBufferSize = 0;
uint32_t maxAnisotropy = 0;
uint32_t maxColorAttachments = 0;
float minSmoothedLineWidth = 1.0f;
float maxSmoothedLineWidth = 1.0f;
float minPointSize = 1.0f;
float maxPointSize = 1.0f;
float maxPointSizeAA = 1.0f;
float maxLineWidth = 1.0f;
float maxLineWidthAA = 1.0f;
int majorVersion = 0;
int minorVersion = 0;
std::string shaderModel;
};
} // namespace RHI
} // namespace XCEngine

View File

@@ -0,0 +1,49 @@
#pragma once
#include "RHITypes.h"
#include "RHICapabilities.h"
#include <string>
namespace XCEngine {
namespace RHI {
class RHIBuffer;
class RHITexture;
class RHISwapChain;
class RHICommandList;
class RHICommandQueue;
class RHIShader;
class RHIPipelineState;
class RHIFence;
class RHISampler;
class RHIDevice {
public:
virtual ~RHIDevice() = default;
virtual bool Initialize(const RHIDeviceDesc& desc) = 0;
virtual void Shutdown() = 0;
virtual RHIBuffer* CreateBuffer(const BufferDesc& desc) = 0;
virtual RHITexture* CreateTexture(const TextureDesc& desc) = 0;
virtual RHISwapChain* CreateSwapChain(const SwapChainDesc& desc) = 0;
virtual RHICommandList* CreateCommandList(const CommandListDesc& desc) = 0;
virtual RHICommandQueue* CreateCommandQueue(const CommandQueueDesc& desc) = 0;
virtual RHIShader* CompileShader(const ShaderCompileDesc& desc) = 0;
virtual RHIPipelineState* CreatePipelineState(const PipelineStateDesc& desc) = 0;
virtual RHIFence* CreateFence(const FenceDesc& desc) = 0;
virtual RHISampler* CreateSampler(const SamplerDesc& desc) = 0;
virtual const RHICapabilities& GetCapabilities() const = 0;
virtual const RHIDeviceInfo& GetDeviceInfo() const = 0;
virtual void* GetNativeDevice() = 0;
virtual bool PollEvents() = 0;
virtual void SwapBuffers() = 0;
virtual bool ShouldClose() const = 0;
virtual void SetShouldClose(bool shouldClose) = 0;
};
} // namespace RHI
} // namespace XCEngine

View File

@@ -7,11 +7,13 @@ namespace RHI {
enum class ShaderType : uint8_t {
Vertex,
Fragment,
Geometry,
Compute,
TessControl,
TessEvaluation,
Hull,
Domain,
Geometry,
Pixel,
Compute,
Amplification,
Mesh,
Library
@@ -291,5 +293,12 @@ enum class HeapType : uint8_t {
Custom
};
enum class RHIType : uint8_t {
D3D12,
OpenGL,
Vulkan,
Metal
};
} // namespace RHI
} // namespace XCEngine

View File

@@ -0,0 +1,35 @@
#pragma once
#include "RHITypes.h"
#include "RHIEnums.h"
#include <string>
namespace XCEngine {
namespace RHI {
class RHIShader {
public:
virtual ~RHIShader() = default;
virtual bool CompileFromFile(const wchar_t* filePath, const char* entryPoint, const char* target) = 0;
virtual bool Compile(const void* sourceData, size_t sourceSize, const char* entryPoint, const char* target) = 0;
virtual ShaderType GetType() const = 0;
virtual bool IsValid() const = 0;
virtual void Bind() = 0;
virtual void Unbind() = 0;
virtual void* GetNativeHandle() = 0;
virtual void SetInt(const char* name, int value) = 0;
virtual void SetFloat(const char* name, float value) = 0;
virtual void SetVec3(const char* name, float x, float y, float z) = 0;
virtual void SetVec4(const char* name, float x, float y, float z, float w) = 0;
virtual void SetMat4(const char* name, const float* value) = 0;
virtual void Shutdown() = 0;
};
} // namespace RHI
} // namespace XCEngine

View File

@@ -0,0 +1,33 @@
#pragma once
#include "RHITypes.h"
#include "RHIEnums.h"
#include <string>
namespace XCEngine {
namespace RHI {
class RHITexture {
public:
virtual ~RHITexture() = default;
virtual uint32_t GetWidth() const = 0;
virtual uint32_t GetHeight() const = 0;
virtual uint32_t GetDepth() const = 0;
virtual uint32_t GetMipLevels() const = 0;
virtual Format GetFormat() const = 0;
virtual TextureType GetTextureType() const = 0;
virtual ResourceStates GetState() const = 0;
virtual void SetState(ResourceStates state) = 0;
virtual void* GetNativeHandle() = 0;
virtual const std::string& GetName() const = 0;
virtual void SetName(const std::string& name) = 0;
virtual void Shutdown() = 0;
};
} // namespace RHI
} // namespace XCEngine

View File

@@ -238,5 +238,54 @@ struct PipelineStateDesc {
uint32_t size;
};
struct RHIDeviceDesc {
bool enableDebugLayer = false;
bool enableGPUValidation = false;
uint32_t adapterIndex = 0;
void* windowHandle = nullptr;
uint32_t width = 1280;
uint32_t height = 720;
std::wstring appName = L"XCEngine";
};
struct RHIDeviceInfo {
std::wstring description;
std::wstring vendor;
std::wstring renderer;
std::wstring version;
uint64_t dedicatedVideoMemory = 0;
uint64_t dedicatedSystemMemory = 0;
uint64_t sharedSystemMemory = 0;
uint32_t vendorId = 0;
uint32_t deviceId = 0;
bool isSoftware = false;
};
struct RHIRenderPassDesc {
struct ColorAttachment {
void* texture = nullptr;
uint32_t loadAction = 0;
uint32_t storeAction = 0;
float clearColor[4] = {0.0f, 0.0f, 0.0f, 1.0f};
};
ColorAttachment colorAttachments[8];
uint32_t colorAttachmentCount = 0;
struct DepthStencilAttachment {
void* texture = nullptr;
uint32_t loadAction = 0;
uint32_t storeAction = 0;
float clearDepth = 1.0f;
uint8_t clearStencil = 0;
} depthStencilAttachment;
bool hasDepthStencil = false;
};
struct RHIPipelineLayoutDesc {
uint32_t constantBufferCount = 0;
uint32_t textureCount = 0;
uint32_t samplerCount = 0;
uint32_t uavCount = 0;
};
} // namespace RHI
} // namespace XCEngine

View File

@@ -27,7 +27,7 @@ bool D3D12Shader::CompileFromFile(const wchar_t* filePath, const char* entryPoin
if (strstr(target, "vs_")) {
m_type = ShaderType::Vertex;
} else if (strstr(target, "ps_")) {
m_type = ShaderType::Pixel;
m_type = ShaderType::Fragment;
} else if (strstr(target, "gs_")) {
m_type = ShaderType::Geometry;
} else if (strstr(target, "cs_")) {

View File

@@ -213,68 +213,60 @@ void OpenGLShader::Use() const {
glUseProgram(m_program);
}
void OpenGLShader::Unbind() const {
void OpenGLShader::Unbind() {
glUseProgram(0);
}
void OpenGLShader::SetInt(const std::string& name, int value) const {
glUniform1i(glGetUniformLocation(m_program, name.c_str()), value);
void OpenGLShader::SetInt(const char* name, int value) {
glUniform1i(glGetUniformLocation(m_program, name), value);
}
void OpenGLShader::SetIntArray(const std::string& name, const int* values, unsigned int count) const {
glUniform1iv(glGetUniformLocation(m_program, name.c_str()), count, values);
void OpenGLShader::SetIntArray(const char* name, const int* values, unsigned int count) {
glUniform1iv(glGetUniformLocation(m_program, name), count, values);
}
void OpenGLShader::SetFloat(const std::string& name, float value) const {
glUniform1f(glGetUniformLocation(m_program, name.c_str()), value);
void OpenGLShader::SetFloat(const char* name, float value) {
glUniform1f(glGetUniformLocation(m_program, name), value);
}
void OpenGLShader::SetFloatArray(const std::string& name, const float* values, unsigned int count) const {
glUniform1fv(glGetUniformLocation(m_program, name.c_str()), count, values);
void OpenGLShader::SetFloatArray(const char* name, const float* values, unsigned int count) {
glUniform1fv(glGetUniformLocation(m_program, name), count, values);
}
void OpenGLShader::SetVec2(const std::string& name, float x, float y) const {
glUniform2f(glGetUniformLocation(m_program, name.c_str()), x, y);
void OpenGLShader::SetVec3(const char* name, float x, float y, float z) {
glUniform3f(glGetUniformLocation(m_program, name), x, y, z);
}
void OpenGLShader::SetVec2(const std::string& name, const float* values) const {
glUniform2fv(glGetUniformLocation(m_program, name.c_str()), 1, values);
void OpenGLShader::SetVec3(const char* name, const float* values) {
glUniform3fv(glGetUniformLocation(m_program, name), 1, values);
}
void OpenGLShader::SetVec3(const std::string& name, float x, float y, float z) const {
glUniform3f(glGetUniformLocation(m_program, name.c_str()), x, y, z);
void OpenGLShader::SetVec4(const char* name, float x, float y, float z, float w) {
glUniform4f(glGetUniformLocation(m_program, name), x, y, z, w);
}
void OpenGLShader::SetVec3(const std::string& name, const float* values) const {
glUniform3fv(glGetUniformLocation(m_program, name.c_str()), 1, values);
void OpenGLShader::SetVec4(const char* name, const float* values) {
glUniform4fv(glGetUniformLocation(m_program, name), 1, values);
}
void OpenGLShader::SetVec4(const std::string& name, float x, float y, float z, float w) const {
glUniform4f(glGetUniformLocation(m_program, name.c_str()), x, y, z, w);
void OpenGLShader::SetMat2(const char* name, const float* value) {
glUniformMatrix2fv(glGetUniformLocation(m_program, name), 1, GL_FALSE, value);
}
void OpenGLShader::SetVec4(const std::string& name, const float* values) const {
glUniform4fv(glGetUniformLocation(m_program, name.c_str()), 1, values);
void OpenGLShader::SetMat3(const char* name, const float* value) {
glUniformMatrix3fv(glGetUniformLocation(m_program, name), 1, GL_FALSE, value);
}
void OpenGLShader::SetMat2(const std::string& name, const float* value) const {
glUniformMatrix2fv(glGetUniformLocation(m_program, name.c_str()), 1, GL_FALSE, value);
void OpenGLShader::SetMat4(const char* name, const float* value) {
glUniformMatrix4fv(glGetUniformLocation(m_program, name), 1, GL_FALSE, value);
}
void OpenGLShader::SetMat3(const std::string& name, const float* value) const {
glUniformMatrix3fv(glGetUniformLocation(m_program, name.c_str()), 1, GL_FALSE, value);
void OpenGLShader::SetMat4Array(const char* name, const float* values, unsigned int count) {
glUniformMatrix4fv(glGetUniformLocation(m_program, name), count, GL_FALSE, values);
}
void OpenGLShader::SetMat4(const std::string& name, const float* value) const {
glUniformMatrix4fv(glGetUniformLocation(m_program, name.c_str()), 1, GL_FALSE, value);
}
void OpenGLShader::SetMat4Array(const std::string& name, const float* values, unsigned int count) const {
glUniformMatrix4fv(glGetUniformLocation(m_program, name.c_str()), count, GL_FALSE, values);
}
int OpenGLShader::GetUniformLocation(const std::string& name) const {
return glGetUniformLocation(m_program, name.c_str());
int OpenGLShader::GetUniformLocation(const char* name) const {
return glGetUniformLocation(m_program, name);
}
bool OpenGLShader::CheckCompileErrors(unsigned int shader, const char* type) {