Add OpenGLCommandList
This commit is contained in:
74
engine/src/RHI/OpenGL/OpenGLCommandList.cpp
Normal file
74
engine/src/RHI/OpenGL/OpenGLCommandList.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLCommandList.h"
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
OpenGLCommandList::OpenGLCommandList()
|
||||
: m_primitiveType(GL_TRIANGLES)
|
||||
, m_currentVAO(0)
|
||||
, m_currentProgram(0)
|
||||
{
|
||||
}
|
||||
|
||||
OpenGLCommandList::~OpenGLCommandList() {
|
||||
}
|
||||
|
||||
void OpenGLCommandList::Clear(float r, float g, float b, float a, unsigned int buffers) {
|
||||
glClearColor(r, g, b, a);
|
||||
unsigned int glBuffers = 0;
|
||||
if (buffers & 0x1) glBuffers |= GL_COLOR_BUFFER_BIT;
|
||||
if (buffers & 0x2) glBuffers |= GL_DEPTH_BUFFER_BIT;
|
||||
if (buffers & 0x4) glBuffers |= GL_STENCIL_BUFFER_BIT;
|
||||
glClear(glBuffers);
|
||||
}
|
||||
|
||||
void OpenGLCommandList::SetPipelineState(void* pipelineState) {
|
||||
}
|
||||
|
||||
void OpenGLCommandList::SetVertexBuffer(unsigned int buffer, size_t offset, size_t stride) {
|
||||
}
|
||||
|
||||
void OpenGLCommandList::SetIndexBuffer(unsigned int buffer, unsigned int type) {
|
||||
}
|
||||
|
||||
static unsigned int ToGLPrimitiveType(PrimitiveType type) {
|
||||
switch (type) {
|
||||
case PrimitiveType::Points: return GL_POINTS;
|
||||
case PrimitiveType::Lines: return GL_LINES;
|
||||
case PrimitiveType::LineStrip: return GL_LINE_STRIP;
|
||||
case PrimitiveType::Triangles: return GL_TRIANGLES;
|
||||
case PrimitiveType::TriangleStrip: return GL_TRIANGLE_STRIP;
|
||||
case PrimitiveType::TriangleFan: return GL_TRIANGLE_FAN;
|
||||
default: return GL_TRIANGLES;
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLCommandList::Draw(PrimitiveType type, unsigned int vertexCount, unsigned int startVertex) {
|
||||
m_primitiveType = ToGLPrimitiveType(type);
|
||||
glDrawArrays(m_primitiveType, startVertex, vertexCount);
|
||||
}
|
||||
|
||||
void OpenGLCommandList::DrawIndexed(PrimitiveType type, unsigned int indexCount, unsigned int startIndex, int baseVertex) {
|
||||
m_primitiveType = ToGLPrimitiveType(type);
|
||||
glDrawElements(m_primitiveType, indexCount, GL_UNSIGNED_INT, (void*)(startIndex * sizeof(unsigned int)));
|
||||
}
|
||||
|
||||
void OpenGLCommandList::BindVertexArray(unsigned int vao) {
|
||||
m_currentVAO = vao;
|
||||
glBindVertexArray(vao);
|
||||
}
|
||||
|
||||
void OpenGLCommandList::UseShader(unsigned int program) {
|
||||
m_currentProgram = program;
|
||||
glUseProgram(program);
|
||||
}
|
||||
|
||||
void OpenGLCommandList::SetViewport(int x, int y, int width, int height) {
|
||||
glViewport(x, y, width, height);
|
||||
}
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user