/
Zamar_Terrier
/
TigorEngineWeb2
Обзор
Документация
Войти
/
Zamar_Terrier
/
TigorEngineWeb2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/graphicsObject.c
82 строки
3 KB
Ilia Zamaruev
wasi integration
16 фев 2026, 18:50
16 фев 2026, 18:50
17d4fd0
Код
Авторство
О чём код?
#include "graphicsObject.h" #include "e_memory.h" #include "e_vertex.h" extern TEngine engine; void GraphicsObjectInit(GraphicsObject* graphObj, uint32_t type) { if(graphObj->num_shapes == 0) memset(&graphObj->shapes, 0, sizeof(Shape) * MAX_SHAPES); } void GraphicsObjectSetVertex(GraphicsObject* graphObj, void *vertices, int vertCount, uint32_t *indices, int indxCount, VertexType type){ uint32_t num = graphObj->num_shapes; int res = 0; uint32_t size = 0; switch (type) { case TIGOR_VERTEX_TYPE_2D_OBJECT: size = sizeof(Vertex2D); break; case TIGOR_VERTEX_TYPE_3D_OBJECT: size = sizeof(Vertex3D); break; default: break; } graphObj->shapes[num].vParam.size = size; graphObj->shapes[num].iParam.size = sizeof(uint32_t); if(vertices != NULL) { graphObj->shapes[num].vParam.vertices = AllocateMemoryP(vertCount, size, graphObj); memcpy(graphObj->shapes[num].vParam.vertices, vertices, size * vertCount); graphObj->shapes[num].vParam.count = vertCount; } if(indices != NULL) { graphObj->shapes[num].iParam.indices = AllocateMemoryP(indxCount, sizeof(uint32_t), graphObj); memcpy(graphObj->shapes[num].iParam.indices, indices, sizeof(uint32_t) * indxCount); graphObj->shapes[num].iParam.count = indxCount; } GraphicsObjectGenBuffers(graphObj); graphObj->num_shapes ++; } void GraphicsObjectGenBuffers(GraphicsObject* graphObj){ glGenVertexArrays(1, &graphObj->shapes[0].VAO); glGenBuffers(1, &graphObj->shapes[0].vParam.buffer); glGenBuffers(1, &graphObj->shapes[0].iParam.buffer); // bind the Vertex Array Object first, then bind and set vertex buffer(s), and then configure vertex attributes(s). glBindVertexArray(graphObj->shapes[0].VAO); glBindBuffer(GL_ARRAY_BUFFER, graphObj->shapes[0].vParam.buffer); glBufferData(GL_ARRAY_BUFFER, graphObj->shapes[0].vParam.size * graphObj->shapes[0].vParam.count, graphObj->shapes[0].vParam.vertices, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, graphObj->shapes[0].iParam.buffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, graphObj->shapes[0].iParam.size * graphObj->shapes[0].iParam.count, graphObj->shapes[0].iParam.indices, GL_STATIC_DRAW); } void GraphicsObjectSetShadersPath(GraphicsObject *graphObj, const char *vert, const char *frag) { int len = strlen(vert); memset(graphObj->aShader.vertShader, 0, 256); memcpy(graphObj->aShader.vertShader, vert, len); len = strlen(frag); memset(graphObj->aShader.fragShader, 0, 256); memcpy(graphObj->aShader.fragShader, frag, len); }