From b43ecacfc4e2f38e6d704ca76cbce27cfc357883 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Tue, 15 Dec 2020 18:29:26 -0800 Subject: [PATCH] draw functions --- include/Refresh.h | 142 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 3 deletions(-) diff --git a/include/Refresh.h b/include/Refresh.h index a7b5fc0..e20e6a0 100644 --- a/include/Refresh.h +++ b/include/Refresh.h @@ -24,8 +24,6 @@ * */ -#include - #ifndef REFRESH_H #define REFRESH_H @@ -54,6 +52,7 @@ extern "C" { /* Type Declarations */ +typedef struct REFRESH_Device REFRESH_Device; typedef struct REFRESH_Texture REFRESH_Texture; typedef struct REFRESH_Buffer REFRESH_Buffer; typedef struct REFRESH_ColorTarget REFRESH_ColorTarget; @@ -62,6 +61,16 @@ typedef struct REFRESH_Framebuffer REFRESH_Framebuffer; typedef struct REFRESH_RenderPass REFRESH_RenderPass; typedef struct REFRESH_Pipeline REFRESH_Pipeline; +typedef enum REFRESH_PrimitiveType +{ + REFRESH_PRIMITIVETYPE_POINTLIST, + REFRESH_PRIMITIVETYPE_LINELIST, + REFRESH_PRIMITIVETYPE_LINESTRIP, + REFRESH_PRIMITIVETYPE_TRIANGLELIST, + REFRESH_PRIMITIVETYPE_TRIANGLESTRIP, + REFRESH_PRIMITIVETYPE_TRIANGLEFAN +} REFRESH_PrimitiveType; + typedef enum REFRESH_LoadOp { REFRESH_LOADOP_LOAD, @@ -136,10 +145,60 @@ typedef enum REFRESH_BufferUsage /* Structures */ +typedef struct REFRESH_Color +{ + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t a; +} REFRESH_Color; + +typedef struct REFRESH_Rect +{ + int32_t x; + int32_t y; + int32_t w; + int32_t h; +} REFRESH_Rect; + +typedef struct REFRESH_Vec4 +{ + float x; + float y; + float z; + float w; +} REFRESH_Vec4; + +typedef struct REFRESH_Viewport +{ + int32_t x; + int32_t y; + int32_t w; + int32_t h; + float minDepth; + float maxDepth; +} REFRESH_Viewport; + +typedef enum REFRESH_VertexElementFormat +{ + REFRESH_VERTEXELEMENTFORMAT_SINGLE, + REFRESH_VERTEXELEMENTFORMAT_VECTOR2, + REFRESH_VERTEXELEMENTFORMAT_VECTOR3, + REFRESH_VERTEXELEMENTFORMAT_VECTOR4, + REFRESH_VERTEXELEMENTFORMAT_COLOR, + REFRESH_VERTEXELEMENTFORMAT_BYTE4, + REFRESH_VERTEXELEMENTFORMAT_SHORT2, + REFRESH_VERTEXELEMENTFORMAT_SHORT4, + REFRESH_VERTEXELEMENTFORMAT_NORMALIZEDSHORT2, + REFRESH_VERTEXELEMENTFORMAT_NORMALIZEDSHORT4, + REFRESH_VERTEXELEMENTFORMAT_HALFVECTOR2, + REFRESH_VERTEXELEMENTFORMAT_HALFVECTOR4 +} REFRESH_VertexElementFormat; + typedef struct REFRESH_VertexElement { int32_t offset; - FNA3D_VertexElementFormat vertexElementFormat; + REFRESH_VertexElementFormat vertexElementFormat; int32_t usageIndex; } REFRESH_VertexElement; @@ -176,6 +235,83 @@ REFRESHAPI uint32_t REFRESH_LinkedVersion(void); /* Functions */ +/* Drawing */ + +/* Clears the active draw buffers of any previous contents. + * + * options: Bitflags to specify color/depth/stencil buffers for clearing. + * color: The new value of the cleared color buffer. + * depth: The new value of the cleared depth buffer. + * stencil: The new value of the cleared stencil buffer. + */ +REFRESHAPI void REFRESH_Clear( + REFRESH_Device *device, + REFRESH_Vec4 **colors, + uint32_t colorCount, + float depth, + int32_t stencil +); + +/* Draws data from vertex/index buffers. + * + * primitiveType: The primitive topology of the vertex data. + * baseVertex: The starting offset to read from the vertex buffer. + * minVertexIndex: The lowest index value expected from the index buffer. + * numVertices: The highest offset expected from the index buffer. + * startIndex: The starting offset to read from the index buffer. + * primitiveCount: The number of primitives to draw. + * indices: The index buffer to bind for this draw call. + * indexElementSize: The size of the index type for this index buffer. + */ +REFRESHAPI void REFRESH_DrawIndexedPrimitives( + REFRESH_Device *device, + REFRESH_PrimitiveType primitiveType, + int32_t baseVertex, + int32_t minVertexIndex, + int32_t numVertices, + int32_t startIndex, + int32_t primitiveCount, + REFRESH_Buffer *indices, + REFRESH_IndexElementSize indexElementSize +); + +/* Draws data from vertex/index buffers with instancing enabled. + * + * primitiveType: The primitive topology of the vertex data. + * baseVertex: The starting offset to read from the vertex buffer. + * minVertexIndex: The lowest index value expected from the index buffer. + * numVertices: The highest offset expected from the index buffer. + * startIndex: The starting offset to read from the index buffer. + * primitiveCount: The number of primitives to draw. + * instanceCount: The number of instances that will be drawn. + * indices: The index buffer to bind for this draw call. + * indexElementSize: The size of the index type for this index buffer. + */ +REFRESHAPI void REFRESH_DrawInstancedPrimitives( + REFRESH_Device *device, + REFRESH_PrimitiveType primitiveType, + int32_t baseVertex, + int32_t minVertexIndex, + int32_t numVertices, + int32_t startIndex, + int32_t primitiveCount, + int32_t instanceCount, + REFRESH_Buffer *indices, + REFRESH_IndexElementSize indexElementSize +); + +/* Draws data from vertex buffers. + * primitiveType: The primitive topology of the vertex data. + * vertexStart: The starting offset to read from the vertex buffer. + * primitiveCount: The number of primitives to draw. + */ +REFRESHAPI void REFRESH_DrawPrimitives( + REFRESH_Device *device, + REFRESH_PrimitiveType primitiveType, + int32_t vertexStart, + int32_t primitiveCount +); + #ifdef __cplusplus } #endif /* __cplusplus */