Working on the new refactor of primitive and shader
This commit is contained in:
82
src/display/primitive/primitive.h
Normal file
82
src/display/primitive/primitive.h
Normal file
@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
|
||||
#define PRIMITIVE_POSITIONS_PER_VERTICE 3
|
||||
#define PRIMITIVE_COORDINATES_PER_VERTICE 2
|
||||
|
||||
/** Structure containing information about a primitive */
|
||||
typedef struct {
|
||||
/** How many vertices are in the primitive */
|
||||
int32_t verticeCount;
|
||||
/** How many indices are in the primitive */
|
||||
int32_t indiceCount;
|
||||
|
||||
/** Pointer to the vertex buffer on the GPU */
|
||||
GLuint vertexBuffer;
|
||||
/** Pointer to the index buffer on the GPU */
|
||||
GLuint indexBuffer;
|
||||
} primitive_t;
|
||||
|
||||
/** Structure containing vertice position information */
|
||||
typedef struct {
|
||||
/** Coordinates */
|
||||
float x, y, z;
|
||||
/** Texture UVs */
|
||||
float u, v;
|
||||
} vertice_t;
|
||||
|
||||
/** Indice that references a specific vertice */
|
||||
typedef unsigned int indice_t;
|
||||
|
||||
/**
|
||||
* Creates a new primitive.
|
||||
* @param primitive Primitive to initialize.
|
||||
* @param verticeCount How many vertices can the primitive hold.
|
||||
* @param indiceCount How many indices can the primitive hold.
|
||||
*/
|
||||
void primitiveInit(primitive_t *primitive,
|
||||
int32_t verticeCount, int32_t indiceCount
|
||||
);
|
||||
|
||||
/**
|
||||
* Buffer Vertices to a primitive for use in rendering.
|
||||
* @param primitive The primitive to buffer vertices into.
|
||||
* @param position The position (index) to overwrite the vertices of.
|
||||
* @param count The count of vertices to buffer.
|
||||
* @param vertices Array of vertices to buffer into the primitive.
|
||||
*/
|
||||
void primitiveBufferVertices(primitive_t *primitive,
|
||||
int32_t position, int32_t count, vertice_t *vertices
|
||||
);
|
||||
|
||||
/**
|
||||
* Buffer Indices to a primitive for use in rendering.
|
||||
* @param primitive The primitive to buffer indices into.
|
||||
* @param position The position (index) to overwrite the indices of.
|
||||
* @param count The count of indices to buffer.
|
||||
* @param indices Array of indices to buffer into the primitive.
|
||||
*/
|
||||
void primitiveBufferIndices(primitive_t *primitive,
|
||||
int32_t position, int32_t count, indice_t *indices
|
||||
);
|
||||
|
||||
/**
|
||||
* Draw a primitive. Primitives are drawn by their indices.
|
||||
* @param primitive Primitive to draw.
|
||||
* @param start Start indice (index) to draw.
|
||||
* @param count Count of indices to draw. Use -1 to draw all.
|
||||
*/
|
||||
void primitiveDraw(primitive_t *primitive, int32_t start, int32_t count);
|
||||
|
||||
/**
|
||||
* Cleanup a previously initialized primitive.
|
||||
* @param primitive Primitive to cleanup.
|
||||
*/
|
||||
void primitiveDispose(primitive_t *primitive);
|
Reference in New Issue
Block a user