graphics: forward declarations;

This commit is contained in:
bjorn 2019-04-05 04:58:29 -07:00
parent 323f9b3fb0
commit ee27af1a85
26 changed files with 168 additions and 126 deletions

View File

@ -4,6 +4,7 @@
#include "api/math.h"
#include "graphics/graphics.h"
#include "graphics/animator.h"
#include "graphics/buffer.h"
#include "graphics/canvas.h"
#include "graphics/material.h"
#include "graphics/mesh.h"

View File

@ -1,7 +1,10 @@
#include "api.h"
#include "api/data.h"
#include "api/math.h"
#include "graphics/buffer.h"
#include "graphics/graphics.h"
#include "graphics/material.h"
#include "graphics/mesh.h"
#include <limits.h>
static int l_lovrMeshAttachAttributes(lua_State* L) {

View File

@ -1,5 +1,7 @@
#include "api.h"
#include "api/math.h"
#include "graphics/animator.h"
#include "graphics/material.h"
#include "graphics/model.h"
static int l_lovrModelDraw(lua_State* L) {

View File

@ -1,6 +1,7 @@
#include "api.h"
#include "api/graphics.h"
#include "api/math.h"
#include "graphics/buffer.h"
#include "graphics/shader.h"
struct TempData {

View File

@ -1,5 +1,6 @@
#include "api.h"
#include "api/graphics.h"
#include "graphics/buffer.h"
#include "graphics/shader.h"
static int l_lovrShaderBlockGetType(lua_State* L) {

View File

@ -175,7 +175,7 @@ typedef struct {
float* inverseBindMatrices;
} ModelSkin;
typedef struct {
typedef struct ModelData {
Ref ref;
void* data;
struct Blob** blobs;

View File

@ -10,7 +10,7 @@
struct Blob;
struct TextureData;
typedef struct {
typedef struct Rasterizer {
Ref ref;
stbtt_fontinfo font;
struct Blob* blob;

View File

@ -1,6 +1,7 @@
#include "graphics/animator.h"
#include <math.h>
#include "data/modelData.h"
#include <stdlib.h>
#include <math.h>
static int trackSortCallback(const void* a, const void* b) {
return ((Track*) a)->priority < ((Track*) b)->priority;

View File

@ -1,5 +1,4 @@
#include "data/modelData.h"
#include "util.h"
#include "types.h"
#include "lib/math.h"
#include "lib/map/map.h"
#include "lib/vec/vec.h"
@ -7,6 +6,8 @@
#pragma once
struct ModelData;
typedef struct {
float time;
float speed;
@ -18,15 +19,15 @@ typedef struct {
typedef vec_t(Track) vec_track_t;
typedef struct {
typedef struct Animator {
Ref ref;
ModelData* data;
struct ModelData* data;
map_int_t animations;
vec_track_t tracks;
float speed;
} Animator;
Animator* lovrAnimatorInit(Animator* animator, ModelData* modelData);
Animator* lovrAnimatorInit(Animator* animator, struct ModelData* modelData);
#define lovrAnimatorCreate(...) lovrAnimatorInit(lovrAlloc(Animator), __VA_ARGS__)
void lovrAnimatorDestroy(void* ref);
void lovrAnimatorReset(Animator* animator);

View File

@ -1,4 +1,5 @@
#include "graphics/buffer.h"
#include "util.h"
size_t lovrBufferGetSize(Buffer* buffer) {
return buffer->size;

View File

@ -1,6 +1,6 @@
#include "graphics/opengl.h"
#include "util.h"
#include <stdlib.h>
#include "types.h"
#include <stddef.h>
#include <stdbool.h>
#pragma once
@ -20,7 +20,7 @@ typedef enum {
USAGE_STREAM
} BufferUsage;
typedef struct {
typedef struct Buffer {
Ref ref;
void* data;
size_t size;

View File

@ -5,8 +5,11 @@
#define MAX_CANVAS_ATTACHMENTS 4
struct Texture;
struct TextureData;
typedef struct {
Texture* texture;
struct Texture* texture;
int slice;
int level;
} Attachment;
@ -22,7 +25,7 @@ typedef struct {
bool mipmaps;
} CanvasFlags;
typedef struct {
typedef struct Canvas {
Ref ref;
int width;
int height;
@ -47,5 +50,5 @@ bool lovrCanvasIsStereo(Canvas* canvas);
int lovrCanvasGetWidth(Canvas* canvas);
int lovrCanvasGetHeight(Canvas* canvas);
int lovrCanvasGetMSAA(Canvas* canvas);
Texture* lovrCanvasGetDepthTexture(Canvas* canvas);
TextureData* lovrCanvasNewTextureData(Canvas* canvas, int index);
struct Texture* lovrCanvasGetDepthTexture(Canvas* canvas);
struct TextureData* lovrCanvasNewTextureData(Canvas* canvas, int index);

View File

@ -1,7 +1,5 @@
#include "graphics/font.h"
#include "graphics/graphics.h"
#include "graphics/texture.h"
#include "data/rasterizer.h"
#include "data/textureData.h"
#include "lib/utf.h"
#include <string.h>

View File

@ -1,12 +1,14 @@
#include "data/rasterizer.h"
#include "util.h"
#include "graphics/texture.h"
#include "types.h"
#include "lib/map/map.h"
#include <stdint.h>
#include <stdbool.h>
#pragma once
struct Rasterizer;
struct Texture;
typedef map_t(Glyph) map_glyph_t;
typedef enum {
@ -31,10 +33,10 @@ typedef struct {
map_glyph_t glyphs;
} FontAtlas;
typedef struct {
typedef struct Font {
Ref ref;
Rasterizer* rasterizer;
Texture* texture;
struct Rasterizer* rasterizer;
struct Texture* texture;
FontAtlas atlas;
map_int_t kerning;
float lineHeight;
@ -42,10 +44,10 @@ typedef struct {
bool flip;
} Font;
Font* lovrFontInit(Font* font, Rasterizer* rasterizer);
Font* lovrFontInit(Font* font, struct Rasterizer* rasterizer);
#define lovrFontCreate(...) lovrFontInit(lovrAlloc(Font), __VA_ARGS__)
void lovrFontDestroy(void* ref);
Rasterizer* lovrFontGetRasterizer(Font* font);
struct Rasterizer* lovrFontGetRasterizer(Font* font);
void lovrFontRender(Font* font, const char* str, size_t length, float wrap, HorizontalAlign halign, float* vertices, uint16_t* indices, uint16_t baseVertex);
void lovrFontMeasure(Font* font, const char* string, size_t length, float wrap, float* width, uint32_t* lineCount, uint32_t* glyphCount);
float lovrFontGetHeight(Font* font);

View File

@ -1,11 +1,13 @@
#include "graphics/graphics.h"
#include "graphics/buffer.h"
#include "graphics/canvas.h"
#include "graphics/material.h"
#include "graphics/mesh.h"
#include "graphics/texture.h"
#include "data/rasterizer.h"
#include "event/event.h"
#include "filesystem/filesystem.h"
#include "math/math.h"
#include "util.h"
#include "lib/math.h"
#include "lib/stb/stb_image.h"
#include <stdlib.h>
#include <string.h>
#include <math.h>

View File

@ -1,9 +1,5 @@
#include "graphics/canvas.h"
#include "graphics/font.h"
#include "graphics/material.h"
#include "graphics/mesh.h"
#include "graphics/shader.h"
#include "graphics/texture.h"
#include "lib/math.h"
#include "util.h"
#include "platform.h"
@ -17,6 +13,14 @@
#define MAX_DRAWS 256
#define MAX_LOCKS 4
struct Buffer;
struct Canvas;
struct Font;
struct Material;
struct Mesh;
struct Shader;
struct Texture;
typedef void (*StencilCallback)(void* userdata);
typedef enum {
@ -72,7 +76,7 @@ typedef enum {
typedef struct {
bool stereo;
Canvas* canvas;
struct Canvas* canvas;
float viewMatrix[2][16];
float projection[2][16];
} Camera;
@ -128,7 +132,7 @@ typedef union {
struct { float r1; float r2; bool capped; int segments; } cylinder;
struct { int segments; } sphere;
struct { float u; float v; float w; float h; } fill;
struct { Mesh* object; DrawMode mode; uint32_t rangeStart; uint32_t rangeCount; uint32_t instances; float* pose; } mesh;
struct { struct Mesh* object; DrawMode mode; uint32_t rangeStart; uint32_t rangeCount; uint32_t instances; float* pose; } mesh;
} BatchParams;
typedef struct {
@ -137,9 +141,9 @@ typedef struct {
DrawMode drawMode;
DefaultShader shader;
Pipeline* pipeline;
Material* material;
Texture* diffuseTexture;
Texture* environmentMap;
struct Material* material;
struct Texture* diffuseTexture;
struct Texture* environmentMap;
mat4 transform;
uint32_t vertexCount;
uint32_t indexCount;
@ -153,10 +157,10 @@ typedef struct {
BatchType type;
BatchParams params;
DrawMode drawMode;
Canvas* canvas;
Shader* shader;
struct Canvas* canvas;
struct Shader* shader;
Pipeline pipeline;
Material* material;
struct Material* material;
mat4 transforms;
Color* colors;
struct { uint32_t start; uint32_t count; } cursors[MAX_BUFFER_ROLES];
@ -170,23 +174,23 @@ typedef struct {
int width;
int height;
Camera camera;
Shader* defaultShaders[MAX_DEFAULT_SHADERS];
Material* defaultMaterial;
Font* defaultFont;
struct Shader* defaultShaders[MAX_DEFAULT_SHADERS];
struct Material* defaultMaterial;
struct Font* defaultFont;
TextureFilter defaultFilter;
float transforms[MAX_TRANSFORMS][16];
int transform;
Color backgroundColor;
Canvas* canvas;
struct Canvas* canvas;
Color color;
Font* font;
struct Font* font;
Pipeline pipeline;
float pointSize;
Shader* shader;
Mesh* mesh;
Mesh* instancedMesh;
Buffer* identityBuffer;
Buffer* buffers[MAX_BUFFER_ROLES];
struct Shader* shader;
struct Mesh* mesh;
struct Mesh* instancedMesh;
struct Buffer* identityBuffer;
struct Buffer* buffers[MAX_BUFFER_ROLES];
uint32_t cursors[MAX_BUFFER_ROLES];
void* locks[MAX_BUFFER_ROLES][MAX_LOCKS];
Batch batches[MAX_BATCHES];
@ -202,7 +206,7 @@ int lovrGraphicsGetWidth(void);
int lovrGraphicsGetHeight(void);
float lovrGraphicsGetPixelDensity(void);
void lovrGraphicsSetCamera(Camera* camera, bool clear);
Buffer* lovrGraphicsGetIdentityBuffer(void);
struct Buffer* lovrGraphicsGetIdentityBuffer(void);
#define lovrGraphicsGetFeatures lovrGpuGetFeatures
#define lovrGraphicsGetLimits lovrGpuGetLimits
#define lovrGraphicsGetStats lovrGpuGetStats
@ -215,8 +219,8 @@ Color lovrGraphicsGetBackgroundColor(void);
void lovrGraphicsSetBackgroundColor(Color color);
void lovrGraphicsGetBlendMode(BlendMode* mode, BlendAlphaMode* alphaMode);
void lovrGraphicsSetBlendMode(BlendMode mode, BlendAlphaMode alphaMode);
Canvas* lovrGraphicsGetCanvas(void);
void lovrGraphicsSetCanvas(Canvas* canvas);
struct Canvas* lovrGraphicsGetCanvas(void);
void lovrGraphicsSetCanvas(struct Canvas* canvas);
Color lovrGraphicsGetColor(void);
void lovrGraphicsSetColor(Color color);
bool lovrGraphicsIsCullingEnabled(void);
@ -225,15 +229,15 @@ TextureFilter lovrGraphicsGetDefaultFilter(void);
void lovrGraphicsSetDefaultFilter(TextureFilter filter);
void lovrGraphicsGetDepthTest(CompareMode* mode, bool* write);
void lovrGraphicsSetDepthTest(CompareMode depthTest, bool write);
Font* lovrGraphicsGetFont(void);
void lovrGraphicsSetFont(Font* font);
struct Font* lovrGraphicsGetFont(void);
void lovrGraphicsSetFont(struct Font* font);
bool lovrGraphicsIsGammaCorrect(void);
float lovrGraphicsGetLineWidth(void);
void lovrGraphicsSetLineWidth(uint8_t width);
float lovrGraphicsGetPointSize(void);
void lovrGraphicsSetPointSize(float size);
Shader* lovrGraphicsGetShader(void);
void lovrGraphicsSetShader(Shader* shader);
struct Shader* lovrGraphicsGetShader(void);
void lovrGraphicsSetShader(struct Shader* shader);
void lovrGraphicsGetStencilTest(CompareMode* mode, int* value);
void lovrGraphicsSetStencilTest(CompareMode mode, int value);
Winding lovrGraphicsGetWinding(void);
@ -256,22 +260,22 @@ void lovrGraphicsClear(Color* color, float* depth, int* stencil);
void lovrGraphicsDiscard(bool color, bool depth, bool stencil);
void lovrGraphicsBatch(BatchRequest* req);
void lovrGraphicsFlush(void);
void lovrGraphicsFlushCanvas(Canvas* canvas);
void lovrGraphicsFlushShader(Shader* shader);
void lovrGraphicsFlushMaterial(Material* material);
void lovrGraphicsFlushMesh(Mesh* mesh);
void lovrGraphicsFlushCanvas(struct Canvas* canvas);
void lovrGraphicsFlushShader(struct Shader* shader);
void lovrGraphicsFlushMaterial(struct Material* material);
void lovrGraphicsFlushMesh(struct Mesh* mesh);
void lovrGraphicsPoints(uint32_t count, float** vertices);
void lovrGraphicsLine(uint32_t count, float** vertices);
void lovrGraphicsTriangle(DrawStyle style, Material* material, uint32_t count, float** vertices);
void lovrGraphicsPlane(DrawStyle style, Material* material, mat4 transform);
void lovrGraphicsBox(DrawStyle style, Material* material, mat4 transform);
void lovrGraphicsArc(DrawStyle style, ArcMode mode, Material* material, mat4 transform, float r1, float r2, int segments);
void lovrGraphicsCircle(DrawStyle style, Material* material, mat4 transform, int segments);
void lovrGraphicsCylinder(Material* material, mat4 transform, float r1, float r2, bool capped, int segments);
void lovrGraphicsSphere(Material* material, mat4 transform, int segments);
void lovrGraphicsSkybox(Texture* texture, float angle, float ax, float ay, float az);
void lovrGraphicsTriangle(DrawStyle style, struct Material* material, uint32_t count, float** vertices);
void lovrGraphicsPlane(DrawStyle style, struct Material* material, mat4 transform);
void lovrGraphicsBox(DrawStyle style, struct Material* material, mat4 transform);
void lovrGraphicsArc(DrawStyle style, ArcMode mode, struct Material* material, mat4 transform, float r1, float r2, int segments);
void lovrGraphicsCircle(DrawStyle style, struct Material* material, mat4 transform, int segments);
void lovrGraphicsCylinder(struct Material* material, mat4 transform, float r1, float r2, bool capped, int segments);
void lovrGraphicsSphere(struct Material* material, mat4 transform, int segments);
void lovrGraphicsSkybox(struct Texture* texture, float angle, float ax, float ay, float az);
void lovrGraphicsPrint(const char* str, size_t length, mat4 transform, float wrap, HorizontalAlign halign, VerticalAlign valign);
void lovrGraphicsFill(Texture* texture, float u, float v, float w, float h);
void lovrGraphicsFill(struct Texture* texture, float u, float v, float w, float h);
#define lovrGraphicsStencil lovrGpuStencil
#define lovrGraphicsCompute lovrGpuCompute
@ -298,9 +302,9 @@ typedef struct {
} GpuStats;
typedef struct {
Mesh* mesh;
Canvas* canvas;
Shader* shader;
struct Mesh* mesh;
struct Canvas* canvas;
struct Shader* shader;
Pipeline pipeline;
DrawMode drawMode;
uint32_t instances;
@ -313,9 +317,9 @@ typedef struct {
void lovrGpuInit(bool srgb, getProcAddressProc getProcAddress);
void lovrGpuDestroy(void);
void lovrGpuClear(Canvas* canvas, Color* color, float* depth, int* stencil);
void lovrGpuCompute(Shader* shader, int x, int y, int z);
void lovrGpuDiscard(Canvas* canvas, bool color, bool depth, bool stencil);
void lovrGpuClear(struct Canvas* canvas, Color* color, float* depth, int* stencil);
void lovrGpuCompute(struct Shader* shader, int x, int y, int z);
void lovrGpuDiscard(struct Canvas* canvas, bool color, bool depth, bool stencil);
void lovrGpuDraw(DrawCommand* draw);
void lovrGpuStencil(StencilAction action, int replaceValue, StencilCallback callback, void* userdata);
void lovrGpuPresent(void);

View File

@ -1,8 +1,10 @@
#include "graphics/material.h"
#include "graphics/graphics.h"
#include "graphics/shader.h"
#include "graphics/texture.h"
#include "resources/shaders.h"
#include <math.h>
#include <stdlib.h>
#include <math.h>
Material* lovrMaterialInit(Material* material) {
for (int i = 0; i < MAX_MATERIAL_SCALARS; i++) {

View File

@ -1,28 +1,29 @@
#include "data/modelData.h"
#include "graphics/texture.h"
#include "graphics/shader.h"
#include "types.h"
#include "util.h"
#include <stdbool.h>
#pragma once
typedef struct {
struct Texture;
struct Shader;
typedef struct Material {
Ref ref;
float scalars[MAX_MATERIAL_SCALARS];
Color colors[MAX_MATERIAL_COLORS];
Texture* textures[MAX_MATERIAL_TEXTURES];
struct Texture* textures[MAX_MATERIAL_TEXTURES];
float transform[9];
} Material;
Material* lovrMaterialInit(Material* material);
#define lovrMaterialCreate() lovrMaterialInit(lovrAlloc(Material))
void lovrMaterialDestroy(void* ref);
void lovrMaterialBind(Material* material, Shader* shader);
void lovrMaterialBind(Material* material, struct Shader* shader);
float lovrMaterialGetScalar(Material* material, MaterialScalar scalarType);
void lovrMaterialSetScalar(Material* material, MaterialScalar scalarType, float value);
Color lovrMaterialGetColor(Material* material, MaterialColor colorType);
void lovrMaterialSetColor(Material* material, MaterialColor colorType, Color color);
Texture* lovrMaterialGetTexture(Material* material, MaterialTexture textureType);
void lovrMaterialSetTexture(Material* material, MaterialTexture textureType, Texture* texture);
struct Texture* lovrMaterialGetTexture(Material* material, MaterialTexture textureType);
void lovrMaterialSetTexture(Material* material, MaterialTexture textureType, struct Texture* texture);
void lovrMaterialGetTransform(Material* material, float* ox, float* oy, float* sx, float* sy, float* angle);
void lovrMaterialSetTransform(Material* material, float ox, float oy, float sx, float sy, float angle);

View File

@ -1,5 +1,7 @@
#include "graphics/mesh.h"
#include "Graphics/buffer.h"
#include "graphics/graphics.h"
#include "graphics/material.h"
Buffer* lovrMeshGetVertexBuffer(Mesh* mesh) {
return mesh->vertexBuffer;

View File

@ -1,7 +1,6 @@
#include "data/modelData.h"
#include "graphics/material.h"
#include "graphics/shader.h"
#include "graphics/opengl.h"
#include "types.h"
#include "lib/map/map.h"
#include <stdbool.h>
@ -10,8 +9,11 @@
#define MAX_ATTRIBUTES 16
#define MAX_ATTRIBUTE_NAME_LENGTH 32
struct Buffer;
struct Material;
typedef struct {
Buffer* buffer;
struct Buffer* buffer;
uint32_t offset;
unsigned stride : 8;
unsigned divisor : 8;
@ -22,7 +24,7 @@ typedef struct {
unsigned disabled : 1;
} MeshAttribute;
typedef struct {
typedef struct Mesh {
Ref ref;
DrawMode mode;
char attributeNames[MAX_ATTRIBUTES][MAX_ATTRIBUTE_NAME_LENGTH];
@ -32,24 +34,24 @@ typedef struct {
uint16_t divisors[MAX_ATTRIBUTES];
map_int_t attributeMap;
int attributeCount;
Buffer* vertexBuffer;
Buffer* indexBuffer;
struct Buffer* vertexBuffer;
struct Buffer* indexBuffer;
uint32_t vertexCount;
uint32_t indexCount;
size_t indexSize;
size_t indexOffset;
uint32_t drawStart;
uint32_t drawCount;
Material* material;
struct Material* material;
GPU_MESH_FIELDS
} Mesh;
Mesh* lovrMeshInit(Mesh* mesh, DrawMode mode, Buffer* vertexBuffer, uint32_t vertexCount);
Mesh* lovrMeshInit(Mesh* mesh, DrawMode mode, struct Buffer* vertexBuffer, uint32_t vertexCount);
#define lovrMeshCreate(...) lovrMeshInit(lovrAlloc(Mesh), __VA_ARGS__)
void lovrMeshDestroy(void* ref);
Buffer* lovrMeshGetVertexBuffer(Mesh* mesh);
Buffer* lovrMeshGetIndexBuffer(Mesh* mesh);
void lovrMeshSetIndexBuffer(Mesh* mesh, Buffer* buffer, uint32_t indexCount, size_t indexSize, size_t offset);
struct Buffer* lovrMeshGetVertexBuffer(Mesh* mesh);
struct Buffer* lovrMeshGetIndexBuffer(Mesh* mesh);
void lovrMeshSetIndexBuffer(Mesh* mesh, struct Buffer* buffer, uint32_t indexCount, size_t indexSize, size_t offset);
uint32_t lovrMeshGetVertexCount(Mesh* mesh);
uint32_t lovrMeshGetIndexCount(Mesh* mesh);
size_t lovrMeshGetIndexSize(Mesh* mesh);
@ -62,5 +64,5 @@ DrawMode lovrMeshGetDrawMode(Mesh* mesh);
void lovrMeshSetDrawMode(Mesh* mesh, DrawMode mode);
void lovrMeshGetDrawRange(Mesh* mesh, uint32_t* start, uint32_t* count);
void lovrMeshSetDrawRange(Mesh* mesh, uint32_t start, uint32_t count);
Material* lovrMeshGetMaterial(Mesh* mesh);
void lovrMeshSetMaterial(Mesh* mesh, Material* material);
struct Material* lovrMeshGetMaterial(Mesh* mesh);
void lovrMeshSetMaterial(Mesh* mesh, struct Material* material);

View File

@ -1,5 +1,9 @@
#include "graphics/model.h"
#include "graphics/animator.h"
#include "graphics/buffer.h"
#include "graphics/graphics.h"
#include "graphics/material.h"
#include "graphics/mesh.h"
#include "resources/shaders.h"
#include <float.h>

View File

@ -1,29 +1,33 @@
#include "data/modelData.h"
#include "graphics/animator.h"
#include "graphics/mesh.h"
#include "lib/math.h"
#include "util.h"
#include "types.h"
#pragma once
struct Animator;
struct Buffer;
struct Material;
struct Mesh;
struct ModelData;
struct Texture;
typedef struct {
Ref ref;
ModelData* data;
Animator* animator;
Buffer** buffers;
Mesh** meshes;
Texture** textures;
Material** materials;
Material* userMaterial;
struct ModelData* data;
struct Animator* animator;
struct Buffer** buffers;
struct Mesh** meshes;
struct Texture** textures;
struct Material** materials;
struct Material* userMaterial;
float* globalNodeTransforms;
} Model;
Model* lovrModelInit(Model* model, ModelData* data);
Model* lovrModelInit(Model* model, struct ModelData* data);
#define lovrModelCreate(...) lovrModelInit(lovrAlloc(Model), __VA_ARGS__)
void lovrModelDestroy(void* ref);
void lovrModelDraw(Model* model, mat4 transform, int instances);
Animator* lovrModelGetAnimator(Model* model);
void lovrModelSetAnimator(Model* model, Animator* animator);
Material* lovrModelGetMaterial(Model* model);
void lovrModelSetMaterial(Model* model, Material* material);
struct Animator* lovrModelGetAnimator(Model* model);
void lovrModelSetAnimator(Model* model, struct Animator* animator);
struct Material* lovrModelGetMaterial(Model* model);
void lovrModelSetMaterial(Model* model, struct Material* material);
void lovrModelGetAABB(Model* model, float aabb[6]);

View File

@ -2,6 +2,7 @@
#include "graphics/graphics.h"
#include "graphics/buffer.h"
#include "graphics/canvas.h"
#include "graphics/material.h"
#include "graphics/mesh.h"
#include "graphics/shader.h"
#include "graphics/texture.h"

View File

@ -1,5 +1,6 @@
#include "graphics/shader.h"
#include "graphics/graphics.h"
#include "graphics/buffer.h"
#include "math/math.h"
#include "resources/shaders.h"
#include <math.h>

View File

@ -1,4 +1,3 @@
#include "graphics/buffer.h"
#include "graphics/texture.h"
#include "graphics/opengl.h"
#include "lib/map/map.h"
@ -10,6 +9,9 @@
#define LOVR_MAX_UNIFORM_LENGTH 64
#define LOVR_MAX_ATTRIBUTE_LENGTH 64
struct Buffer;
struct Texture;
typedef enum {
ACCESS_READ,
ACCESS_WRITE,
@ -44,7 +46,7 @@ typedef enum {
} DefaultShader;
typedef struct {
Texture* texture;
struct Texture* texture;
int slice;
int mipmap;
UniformAccess access;
@ -63,7 +65,7 @@ typedef struct {
char* bytes;
int* ints;
float* floats;
Texture** textures;
struct Texture** textures;
Image* images;
} value;
TextureType textureType;
@ -79,13 +81,13 @@ typedef struct {
BlockType type;
vec_uniform_t uniforms;
map_int_t uniformMap;
Buffer* buffer;
struct Buffer* buffer;
} ShaderBlock;
typedef struct {
vec_uniform_t uniforms;
UniformAccess access;
Buffer* source;
struct Buffer* source;
size_t offset;
size_t size;
int slot;
@ -93,7 +95,7 @@ typedef struct {
typedef vec_t(UniformBlock) vec_block_t;
typedef struct {
typedef struct Shader {
Ref ref;
ShaderType type;
vec_uniform_t uniforms;
@ -120,19 +122,19 @@ const Uniform* lovrShaderGetUniform(Shader* shader, const char* name);
void lovrShaderSetFloats(Shader* shader, const char* name, float* data, int start, int count);
void lovrShaderSetInts(Shader* shader, const char* name, int* data, int start, int count);
void lovrShaderSetMatrices(Shader* shader, const char* name, float* data, int start, int count);
void lovrShaderSetTextures(Shader* shader, const char* name, Texture** data, int start, int count);
void lovrShaderSetTextures(Shader* shader, const char* name, struct Texture** data, int start, int count);
void lovrShaderSetImages(Shader* shader, const char* name, Image* data, int start, int count);
void lovrShaderSetColor(Shader* shader, const char* name, Color color);
void lovrShaderSetBlock(Shader* shader, const char* name, Buffer* buffer, size_t offset, size_t size, UniformAccess access);
void lovrShaderSetBlock(Shader* shader, const char* name, struct Buffer* buffer, size_t offset, size_t size, UniformAccess access);
// ShaderBlock
size_t lovrShaderComputeUniformLayout(vec_uniform_t* uniforms);
ShaderBlock* lovrShaderBlockInit(ShaderBlock* block, BlockType type, Buffer* buffer, vec_uniform_t* uniforms);
ShaderBlock* lovrShaderBlockInit(ShaderBlock* block, BlockType type, struct Buffer* buffer, vec_uniform_t* uniforms);
#define lovrShaderBlockCreate(...) lovrShaderBlockInit(lovrAlloc(ShaderBlock), __VA_ARGS__)
void lovrShaderBlockDestroy(void* ref);
BlockType lovrShaderBlockGetType(ShaderBlock* block);
char* lovrShaderBlockGetShaderCode(ShaderBlock* block, const char* blockName, size_t* length);
const Uniform* lovrShaderBlockGetUniform(ShaderBlock* block, const char* name);
Buffer* lovrShaderBlockGetBuffer(ShaderBlock* block);
struct Buffer* lovrShaderBlockGetBuffer(ShaderBlock* block);

View File

@ -1,10 +1,13 @@
#include "data/textureData.h"
#include "graphics/opengl.h"
#include "data/modelData.h"
#include "types.h"
#include <stdbool.h>
#pragma once
struct TextureData;
typedef enum {
TEXTURE_2D,
TEXTURE_CUBE,
@ -12,7 +15,7 @@ typedef enum {
TEXTURE_VOLUME
} TextureType;
typedef struct {
typedef struct Texture {
Ref ref;
TextureType type;
TextureFormat format;
@ -29,13 +32,13 @@ typedef struct {
GPU_TEXTURE_FIELDS
} Texture;
Texture* lovrTextureInit(Texture* texture, TextureType type, TextureData** slices, int sliceCount, bool srgb, bool mipmaps, int msaa);
Texture* lovrTextureInit(Texture* texture, TextureType type, struct TextureData** slices, int sliceCount, bool srgb, bool mipmaps, int msaa);
Texture* lovrTextureInitFromHandle(Texture* texture, uint32_t handle, TextureType type);
#define lovrTextureCreate(...) lovrTextureInit(lovrAlloc(Texture), __VA_ARGS__)
#define lovrTextureCreateFromHandle(...) lovrTextureInitFromHandle(lovrAlloc(Texture), __VA_ARGS__)
void lovrTextureDestroy(void* ref);
void lovrTextureAllocate(Texture* texture, int width, int height, int depth, TextureFormat format);
void lovrTextureReplacePixels(Texture* texture, TextureData* data, int x, int y, int slice, int mipmap);
void lovrTextureReplacePixels(Texture* texture, struct TextureData* data, int x, int y, int slice, int mipmap);
int lovrTextureGetWidth(Texture* texture, int mipmap);
int lovrTextureGetHeight(Texture* texture, int mipmap);
int lovrTextureGetDepth(Texture* texture, int mipmap);