Create empty texture idea, change function scopes

Some functions which should not be exposed in the API have been switched
to INTERNAL scope. We have a notion of an empty texture in World Traveller
that we can pass in situations where we just want to render a solid
colour with no associated texture.

The alternative to this was creating a separate shader for rendering
primitives but would require at some point to expose the AssetManager to
the renderer or the user on behalf has to manually switch shaders before
rendering (non-intuitive).
This commit is contained in:
2016-07-16 17:15:03 +10:00
parent 86b4d1e206
commit d0b4c99787
13 changed files with 198 additions and 164 deletions
+1
View File
@@ -8,6 +8,7 @@
enum TexList
{
texlist_empty,
texlist_hero,
texlist_terrain,
texlist_font,
+1 -1
View File
@@ -54,7 +54,7 @@ typedef struct Entity
INTERNAL inline v4 getEntityScreenRect(Entity entity)
{
v4 result = getRect(entity.pos, entity.size);
v4 result = math_getRect(entity.pos, entity.size);
return result;
}
+2 -2
View File
@@ -269,7 +269,7 @@ INTERNAL inline v4 mat4_mul_v4(const mat4 a, const v4 b)
return result;
}
INTERNAL inline v4 getRect(v2 origin, v2 size)
INTERNAL inline v4 math_getRect(v2 origin, v2 size)
{
v2 upperLeftBound = v2_add(origin, V2(0.0f, size.y));
v2 lowerRightBound = v2_add(origin, V2(size.x, 0.0f));
@@ -280,7 +280,7 @@ INTERNAL inline v4 getRect(v2 origin, v2 size)
return result;
}
INTERNAL inline v2 getRectSize(v4 rect)
INTERNAL inline v2 math_getRectSize(v4 rect)
{
f32 width = ABS(rect.x - rect.z);
f32 height = ABS(rect.y - rect.w);
+6 -16
View File
@@ -19,6 +19,12 @@ typedef struct RenderQuad
v4 vertex[4];
} RenderQuad;
// TODO(doyle): Clean up lines
// Renderer::~Renderer() { glDeleteVertexArrays(1, &this->quadVAO); }
void renderer_rect(Renderer *const renderer, v4 cameraBounds, v2 pos, v2 size,
f32 rotate, Texture *tex, v4 texRect, v4 color);
void renderer_string(Renderer *const renderer, v4 cameraBounds,
Font *const font, const char *const string, v2 pos,
f32 rotate, v4 color);
@@ -34,12 +40,6 @@ inline void renderer_staticString(Renderer *const renderer, Font *const font,
void renderer_entity(Renderer *renderer, v4 cameraBounds, Entity *entity,
f32 dt, f32 rotate, v4 color);
void renderer_object(Renderer *renderer, v2 pos, v2 size, f32 rotate, v4 color,
Texture *tex);
RenderQuad renderer_createQuad(Renderer *renderer, v4 quadRect, v4 texRect,
Texture *tex);
INTERNAL inline void renderer_flipTexCoord(v4 *texCoords, b32 flipX, b32 flipY)
{
if (flipX)
@@ -56,14 +56,4 @@ INTERNAL inline void renderer_flipTexCoord(v4 *texCoords, b32 flipX, b32 flipY)
texCoords->w = tmp.y;
}
}
INTERNAL inline RenderQuad renderer_createDefaultQuad(Renderer *renderer,
v4 texRect, Texture *tex)
{
RenderQuad result = {0};
v4 defaultQuad = V4(0.0f, renderer->size.h, renderer->size.w, 0.0f);
result = renderer_createQuad(renderer, defaultQuad, texRect, tex);
return result;
}
#endif
-4
View File
@@ -9,10 +9,6 @@ typedef struct Shader
GLuint id;
} Shader;
const i32 shader_loadProgram(Shader *const shader,
const GLuint vertexShader,
const GLuint fragmentShader);
void shader_uniformSet1i(Shader *const shader, const GLchar *name,
const GLuint data);
void shader_uniformSetMat4fv(Shader *const shader, const GLchar *name,
+2 -2
View File
@@ -32,7 +32,7 @@ typedef struct Texture
} Texture;
// Generates texture from image data
Texture genTexture(const GLuint width, const GLuint height,
const GLint bytesPerPixel, const u8 *const image);
Texture texture_gen(const GLuint width, const GLuint height,
const GLint bytesPerPixel, const u8 *const image);
#endif