diff options
Diffstat (limited to 'Client/Source/Graphics/GfxDevice.cpp')
-rw-r--r-- | Client/Source/Graphics/GfxDevice.cpp | 169 |
1 files changed, 169 insertions, 0 deletions
diff --git a/Client/Source/Graphics/GfxDevice.cpp b/Client/Source/Graphics/GfxDevice.cpp new file mode 100644 index 0000000..231ee71 --- /dev/null +++ b/Client/Source/Graphics/GfxDevice.cpp @@ -0,0 +1,169 @@ +#include <vector> +#include "GfxDevice.h" +#include "../Math/Math.h" + +static bool deviceInited = false; +// +//static const std::vector<byte> s_AvailableTextureUnitPreset = {0,1,2,3,4,5,6,7}; // 最多支持8个贴图 +//static std::vector<byte> s_TextureUnitBucket = s_AvailableTextureUnitPreset; + +static const int kMaxAvailableTextureUnitCount = 8; // 最多支持8个贴图 +static int s_CurAvailableTextureUnit = 0; + +static int ClaimTextureUnit() +{ + int unit = s_CurAvailableTextureUnit; + s_CurAvailableTextureUnit = (s_CurAvailableTextureUnit + 1) % kMaxAvailableTextureUnitCount; + return unit; +} + +GfxDevice g_GfxDevice; + +GfxDevice::GfxDevice() +{ + Assert(!deviceInited); + deviceInited = true; +} + +GfxDevice::~GfxDevice() +{ +} + +void GfxDevice::Initialize(GfxDeviceSetting setting) +{ +} + +void GfxDevice::Enable(EDeviceEnable enabled) +{ + +} + +void GfxDevice::Disable(EDeviceEnable enabled) +{ + +} + +void GfxDevice::IsEnable(uint flag) +{ + +} + +void GfxDevice::SetDepthTest(EDepthTest testing) +{ + +} + +void GfxDevice::SetCullFace(ECullFace face) +{ + +} + +void GfxDevice::SetStencilMask(byte stencilMask) +{ + +} + +void GfxDevice::SetStencilOp(EStencilOp op) +{ + +} + +void GfxDevice::SetAntiAliasing(int level /*= 0*/) +{ + +} + +void GfxDevice::Clear(int clearFlag) +{ + +} + +void GfxDevice::UseShader(Shader* shader, int idx) +{ + if (shader == NULL) + return; + + GLuint id = shader->GetID(); + if (id == 0) + return; + + glUseProgram(id); + + shader->ExecuteCommand(); + + m_Shader.shader = shader; +} + +void GfxDevice::UnuseShader() +{ + if (m_Shader) + { + m_Shader.shader = NULL; + } + glUseProgram(0); +} + +void GfxDevice::SetUniformVec2(const char* name, Vector2f vec2) +{ + if (!m_Shader) + return; + GLint loc = glGetUniformLocation(m_Shader.GetID(), name); + glUniform2f(loc, vec2.x, vec2.y); +} + +void GfxDevice::SetUniformVec3(const char* name, Vector3f vec3) +{ + if (!m_Shader) + return; + GLint loc = glGetUniformLocation(m_Shader.GetID(), name); + glUniform3f(loc, vec3.x, vec3.y, vec3.z); +} + +void GfxDevice::SetUniformVec4(const char* name, Vector4f vec4) +{ + if (!m_Shader) + return; + GLint loc = glGetUniformLocation(m_Shader.GetID(), name); + glUniform4f(loc, vec4.x, vec4.y, vec4.z, vec4.w); +} + +void GfxDevice::SetUniformMat4(const char* name, Matrix44 mat4) +{ + if (!m_Shader) + return; + GLint loc = glGetUniformLocation(m_Shader.GetID(), name); + glUniformMatrix4fv(loc, 1, GL_TRUE, &mat4.m[0][0]); +} + +void GfxDevice::SetUniformTexture(const char* name, Texture* texture) +{ + int texUnit = ClaimTextureUnit(); + glActiveTexture(GL_TEXTURE0 + texUnit); + glBindTexture(GL_TEXTURE_2D, texture->GetGpuID()); + + GLint loc = glGetUniformLocation(m_Shader.GetID(), name); + glUniform1i(loc, texUnit); +} + +void GfxDevice::BeginFrame() +{ + m_IsInsideFrame = true; + +} + +void GfxDevice::EndFrame() +{ + //GPU::BufferPool::Instance()->OnEndFrame(); + + m_IsInsideFrame = false; +} + +void GfxDevice::PresentFrame() +{ +// swap buffers +} + +bool GfxDevice::IsInsideFrame() +{ + return m_IsInsideFrame; +} |