fix: encapsulate OpenGL types in VertexAttribute to eliminate raw GL API usage in tests
- Add VertexAttributeType and VertexAttributeNormalized enums in OpenGLVertexArray.h - Add ToGLAttributeType() converter in OpenGLVertexArray.cpp - Remove glActiveTexture() call from quad test (already handled by texture.Bind()) - Remove #include <glad/glad.h> from triangle test - Update unit tests to use encapsulated enums All three OpenGL integration tests (minimal, triangle, quad) pass with 0% pixel difference.
This commit is contained in:
@@ -6,11 +6,32 @@
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
enum class VertexAttributeType {
|
||||
Float = 0,
|
||||
Int,
|
||||
UnsignedInt,
|
||||
Short,
|
||||
UnsignedShort,
|
||||
Byte,
|
||||
UnsignedByte,
|
||||
Double,
|
||||
HalfFloat,
|
||||
Fixed,
|
||||
Int2101010Rev,
|
||||
UnsignedInt2101010Rev,
|
||||
UnsignedInt10F11F11FRev
|
||||
};
|
||||
|
||||
enum class VertexAttributeNormalized {
|
||||
False = 0,
|
||||
True
|
||||
};
|
||||
|
||||
struct VertexAttribute {
|
||||
unsigned int index;
|
||||
int count;
|
||||
unsigned int type;
|
||||
bool normalized;
|
||||
VertexAttributeType type;
|
||||
VertexAttributeNormalized normalized;
|
||||
size_t stride;
|
||||
size_t offset;
|
||||
};
|
||||
|
||||
@@ -4,6 +4,25 @@
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
static unsigned int ToGLAttributeType(VertexAttributeType type) {
|
||||
switch (type) {
|
||||
case VertexAttributeType::Float: return GL_FLOAT;
|
||||
case VertexAttributeType::Int: return GL_INT;
|
||||
case VertexAttributeType::UnsignedInt: return GL_UNSIGNED_INT;
|
||||
case VertexAttributeType::Short: return GL_SHORT;
|
||||
case VertexAttributeType::UnsignedShort: return GL_UNSIGNED_SHORT;
|
||||
case VertexAttributeType::Byte: return GL_BYTE;
|
||||
case VertexAttributeType::UnsignedByte: return GL_UNSIGNED_BYTE;
|
||||
case VertexAttributeType::Double: return GL_DOUBLE;
|
||||
case VertexAttributeType::HalfFloat: return GL_HALF_FLOAT;
|
||||
case VertexAttributeType::Fixed: return GL_FIXED;
|
||||
case VertexAttributeType::Int2101010Rev: return GL_INT_2_10_10_10_REV;
|
||||
case VertexAttributeType::UnsignedInt2101010Rev: return GL_UNSIGNED_INT_2_10_10_10_REV;
|
||||
case VertexAttributeType::UnsignedInt10F11F11FRev: return GL_UNSIGNED_INT_10F_11F_11F_REV;
|
||||
default: return GL_FLOAT;
|
||||
}
|
||||
}
|
||||
|
||||
OpenGLVertexArray::OpenGLVertexArray()
|
||||
: m_vao(0)
|
||||
, m_indexBuffer(0)
|
||||
@@ -24,8 +43,9 @@ void OpenGLVertexArray::AddVertexBuffer(unsigned int buffer, const VertexAttribu
|
||||
glBindVertexArray(m_vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
glEnableVertexAttribArray(attribute.index);
|
||||
glVertexAttribPointer(attribute.index, attribute.count, attribute.type,
|
||||
attribute.normalized ? GL_TRUE : GL_FALSE,
|
||||
glVertexAttribPointer(attribute.index, attribute.count,
|
||||
ToGLAttributeType(attribute.type),
|
||||
attribute.normalized == VertexAttributeNormalized::True ? GL_TRUE : GL_FALSE,
|
||||
attribute.stride, (void*)attribute.offset);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
Reference in New Issue
Block a user