[Feat] (...): Add BufferState and VertexBufferState while implementing these gl functions.

This commit is contained in:
BZLZHH
2025-05-01 22:20:34 +08:00
parent 369b9b320b
commit 33104f699a
16 changed files with 702 additions and 23 deletions
@@ -0,0 +1,53 @@
//
// Created by BZLZHH on 2025/5/1.
//
#ifndef MOBILEGL_VERTEXARRAYSTATE_H
#define MOBILEGL_VERTEXARRAYSTATE_H
#define MOBILEGL_GLSTATE_H
#include "../../../Includes.h"
struct VertexAttribState {
bool enabled = false;
GLint size = 4;
GLenum type = GL_FLOAT;
GLboolean normalized = GL_FALSE;
GLsizei stride = 0;
const GLvoid* pointer = nullptr;
GLuint buffer = 0;
bool isInteger = false;
};
struct VertexArrayObject {
bool generated = false;
GLuint elementBuffer = 0;
std::unordered_map<GLuint, VertexAttribState> attribs;
};
class VertexArrayState {
public:
VertexArrayState();
// Return: the validity of the operation, according to OpenGL 3 standard
GLenum Create(GLuint* array);
GLenum CreateN(GLsizei n, GLuint* arrays);
GLenum Bind(GLuint array);
GLenum EnableAttrib(GLuint index);
GLenum DisableAttrib(GLuint index);
GLenum SetAttribPointer(GLuint index, GLint size, GLenum type,
GLboolean normalized, GLsizei stride,
const void* pointer, bool isInteger,
GLuint currentArrayBuffer);
GLuint GetBoundElementBuffer();
VertexArrayObject* GetCurrentVAO();
private:
std::unordered_map<GLuint, VertexArrayObject> vaos_;
std::set<GLuint> freeIds_;
GLuint lastId_ = 0;
GLuint currentVao_ = 0;
};
#endif //MOBILEGL_VERTEXARRAYSTATE_H