Writing a few more asserts.
This commit is contained in:
@ -41,6 +41,7 @@ queueaction_t * queueAdd(queue_t *queue) {
|
|||||||
queueaction_t *action;
|
queueaction_t *action;
|
||||||
|
|
||||||
ASSERT_NOT_NULL(queue);
|
ASSERT_NOT_NULL(queue);
|
||||||
|
ASSERT_LESS_THAN(queue->count, ANIMATION_QUEUE_ITEM_MAX);
|
||||||
|
|
||||||
action = queue->items + queue->count;
|
action = queue->items + queue->count;
|
||||||
action->index = queue->count;
|
action->index = queue->count;
|
||||||
@ -79,9 +80,12 @@ void queueDispose(queue_t *queue) {
|
|||||||
|
|
||||||
void queueRestack(queue_t *queue) {
|
void queueRestack(queue_t *queue) {
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
ASSERT_NOT_NULL(queue);
|
ASSERT_NOT_NULL(queue);
|
||||||
|
|
||||||
|
|
||||||
// Rewind the array.
|
// Rewind the array.
|
||||||
|
if(queue->current == 0) return;
|
||||||
arrayRewind(sizeof(queueaction_t), queue->items, ANIMATION_QUEUE_START,
|
arrayRewind(sizeof(queueaction_t), queue->items, ANIMATION_QUEUE_START,
|
||||||
queue->current, queue->count
|
queue->current, queue->count
|
||||||
);
|
);
|
||||||
|
@ -120,7 +120,9 @@ timelineaction_t * timelineAddAction(timeline_t *timeline, float start,
|
|||||||
timelineaction_t *action;
|
timelineaction_t *action;
|
||||||
|
|
||||||
ASSERT_NOT_NULL(timeline);
|
ASSERT_NOT_NULL(timeline);
|
||||||
|
ASSERT_LESS_THAN(timeline->actionCount, TIMELINE_ACTION_COUNT_MAX);
|
||||||
ASSERT_GREATER_THAN_EQUAL_TO(start, 0);
|
ASSERT_GREATER_THAN_EQUAL_TO(start, 0);
|
||||||
|
ASSERT_IF(duration < 0, ASSERT_EQUAL(duration, -1));
|
||||||
|
|
||||||
action = timeline->actions + (timeline->actionCount++);
|
action = timeline->actions + (timeline->actionCount++);
|
||||||
action->loop = false;
|
action->loop = false;
|
||||||
|
@ -14,6 +14,10 @@ void shaderInit(shaderprogram_t *shader,
|
|||||||
char *error;
|
char *error;
|
||||||
GLuint shaderVertex, shaderFragment, shaderProgram;
|
GLuint shaderVertex, shaderFragment, shaderProgram;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(shader);
|
||||||
|
ASSERT_NOT_NULL(vertexShaderSource);
|
||||||
|
ASSERT_NOT_NULL(fragmentShaderSource);
|
||||||
|
|
||||||
// Load the vertex shader first
|
// Load the vertex shader first
|
||||||
shaderVertex = glCreateShader(GL_VERTEX_SHADER);
|
shaderVertex = glCreateShader(GL_VERTEX_SHADER);
|
||||||
glShaderSource(shaderVertex, 1, &vertexShaderSource, 0);
|
glShaderSource(shaderVertex, 1, &vertexShaderSource, 0);
|
||||||
@ -74,12 +78,15 @@ void shaderInit(shaderprogram_t *shader,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void shaderDispose(shaderprogram_t *shader) {
|
void shaderDispose(shaderprogram_t *shader) {
|
||||||
|
ASSERT_NOT_NULL(shader);
|
||||||
|
|
||||||
glDeleteProgram(shader->shaderProgram);
|
glDeleteProgram(shader->shaderProgram);
|
||||||
glDeleteShader(shader->shaderVertex);
|
glDeleteShader(shader->shaderVertex);
|
||||||
glDeleteShader(shader->shaderFrag);
|
glDeleteShader(shader->shaderFrag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void shaderUse(shaderprogram_t *shader) {
|
void shaderUse(shaderprogram_t *shader) {
|
||||||
|
ASSERT_NOT_NULL(shader);
|
||||||
glUseProgram(shader->shaderProgram);
|
glUseProgram(shader->shaderProgram);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +94,11 @@ void shaderUseCamera(
|
|||||||
shaderprogram_t *shader, shaderuniform_t uniformView,
|
shaderprogram_t *shader, shaderuniform_t uniformView,
|
||||||
shaderuniform_t uniformProjection, camera_t *camera
|
shaderuniform_t uniformProjection, camera_t *camera
|
||||||
) {
|
) {
|
||||||
|
ASSERT_NOT_NULL(shader);
|
||||||
|
ASSERT_NOT_NULL(camera);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(uniformView, 0);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(uniformProjection, 0);
|
||||||
|
|
||||||
shaderUseMatrix(shader, uniformView, &camera->view);
|
shaderUseMatrix(shader, uniformView, &camera->view);
|
||||||
shaderUseMatrix(shader, uniformProjection, &camera->projection);
|
shaderUseMatrix(shader, uniformProjection, &camera->projection);
|
||||||
}
|
}
|
||||||
@ -94,18 +106,27 @@ void shaderUseCamera(
|
|||||||
void shaderUseTexture(
|
void shaderUseTexture(
|
||||||
shaderprogram_t *shader, shaderuniform_t uniform, textureslot_t slot
|
shaderprogram_t *shader, shaderuniform_t uniform, textureslot_t slot
|
||||||
) {
|
) {
|
||||||
|
ASSERT_NOT_NULL(shader);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(uniform, 0);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(slot, 0);
|
||||||
|
ASSERT_LESS_THAN(slot, TEXTURE_SLOTS_MAX);
|
||||||
glUniform1i(uniform, slot);
|
glUniform1i(uniform, slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
void shaderUseMatrix(
|
void shaderUseMatrix(
|
||||||
shaderprogram_t *shader, shaderuniform_t uniform, matrix_t *matrix
|
shaderprogram_t *shader, shaderuniform_t uniform, matrix_t *matrix
|
||||||
) {
|
) {
|
||||||
|
ASSERT_NOT_NULL(shader);
|
||||||
|
ASSERT_NOT_NULL(matrix);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(uniform, 0);
|
||||||
glUniformMatrix4fv(uniform, 1, GL_FALSE, matrix->internalMatrix[0]);
|
glUniformMatrix4fv(uniform, 1, GL_FALSE, matrix->internalMatrix[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void shaderUseColor(
|
void shaderUseColor(
|
||||||
shaderprogram_t *shader, shaderuniform_t uniform, pixel_t color
|
shaderprogram_t *shader, shaderuniform_t uniform, pixel_t color
|
||||||
) {
|
) {
|
||||||
|
ASSERT_NOT_NULL(shader);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(uniform, 0);
|
||||||
glUniform4f(uniform,
|
glUniform4f(uniform,
|
||||||
(float)color.r / 255.0f,
|
(float)color.r / 255.0f,
|
||||||
(float)color.g / 255.0f,
|
(float)color.g / 255.0f,
|
||||||
@ -115,5 +136,7 @@ void shaderUseColor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
shaderuniform_t shaderGetUniformByName(shaderprogram_t *sp, const char *name) {
|
shaderuniform_t shaderGetUniformByName(shaderprogram_t *sp, const char *name) {
|
||||||
|
ASSERT_NOT_NULL(sp);
|
||||||
|
ASSERT_NOT_NULL(name);
|
||||||
return glGetUniformLocation(sp->shaderProgram, name);
|
return glGetUniformLocation(sp->shaderProgram, name);
|
||||||
}
|
}
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../libs.h"
|
#include "../libs.h"
|
||||||
|
#include "../assert/assert.h"
|
||||||
#include "matrix.h"
|
#include "matrix.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
|
@ -87,6 +87,7 @@ void standardShaderSetTexture(standardshader_t *stds, texture_t *texture) {
|
|||||||
ASSERT_NOT_NULL(texture);
|
ASSERT_NOT_NULL(texture);
|
||||||
if(!assetManagerItemIsFinished(stds->shaderProgram)) return;
|
if(!assetManagerItemIsFinished(stds->shaderProgram)) return;
|
||||||
|
|
||||||
|
textureBind(texture, 0);
|
||||||
shaderUseTexture(STANDARD_SHADER_SHADER(stds), stds->uniformTexture, 0);
|
shaderUseTexture(STANDARD_SHADER_SHADER(stds), stds->uniformTexture, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,10 +35,57 @@ typedef struct {
|
|||||||
shaderuniform_t uniformColor;
|
shaderuniform_t uniformColor;
|
||||||
} standardshader_t;
|
} standardshader_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the standard shader.
|
||||||
|
*
|
||||||
|
* @param stds Standard Shader Instance.
|
||||||
|
* @param assetManager Asset Manager to load the shaders' assets.
|
||||||
|
*/
|
||||||
void standardShaderInit(standardshader_t *stds, assetmanager_t *assetManager);
|
void standardShaderInit(standardshader_t *stds, assetmanager_t *assetManager);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bind the standard shader as the currently active shader.
|
||||||
|
*
|
||||||
|
* @param stds Standard shader to bind.
|
||||||
|
*/
|
||||||
void standardShaderUse(standardshader_t *stds);
|
void standardShaderUse(standardshader_t *stds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the camera for the standard shader.
|
||||||
|
*
|
||||||
|
* @param stds Standard shader instance.
|
||||||
|
* @param camera Camera to bind.
|
||||||
|
*/
|
||||||
void standardShaderSetCamera(standardshader_t *stds, camera_t *camera);
|
void standardShaderSetCamera(standardshader_t *stds, camera_t *camera);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the texture for the standard shader.
|
||||||
|
*
|
||||||
|
* @param stds Standard shader instance.
|
||||||
|
* @param texture Texture to bind.
|
||||||
|
*/
|
||||||
void standardShaderSetTexture(standardshader_t *stds, texture_t *texture);
|
void standardShaderSetTexture(standardshader_t *stds, texture_t *texture);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the color for the standard shader.
|
||||||
|
*
|
||||||
|
* @param stds Standard shader instance.
|
||||||
|
* @param color Color to bind.
|
||||||
|
*/
|
||||||
void standardShaderSetColor(standardshader_t *stds, pixel_t color);
|
void standardShaderSetColor(standardshader_t *stds, pixel_t color);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the position matrix for the standard shader.
|
||||||
|
*
|
||||||
|
* @param stds Standard shader to use.
|
||||||
|
* @param matrix Matrix to use.
|
||||||
|
*/
|
||||||
void standardShaderSetPosition(standardshader_t *stds, matrix_t *matrix);
|
void standardShaderSetPosition(standardshader_t *stds, matrix_t *matrix);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispose/cleanup the standard shader.
|
||||||
|
*
|
||||||
|
* @param stds Standard shader instance.
|
||||||
|
* @param assMan Asset manager instance.
|
||||||
|
*/
|
||||||
void standardShaderDispose(standardshader_t *stds, assetmanager_t *assMan);
|
void standardShaderDispose(standardshader_t *stds, assetmanager_t *assMan);
|
@ -16,6 +16,10 @@
|
|||||||
void textureInit(texture_t *texture, int32_t width, int32_t height,
|
void textureInit(texture_t *texture, int32_t width, int32_t height,
|
||||||
pixel_t *pixels
|
pixel_t *pixels
|
||||||
) {
|
) {
|
||||||
|
ASSERT_NOT_NULL(texture);
|
||||||
|
ASSERT_GREATER_THAN(width, 0);
|
||||||
|
ASSERT_GREATER_THAN(height, 0);
|
||||||
|
|
||||||
texture->width = width;
|
texture->width = width;
|
||||||
texture->height = height;
|
texture->height = height;
|
||||||
|
|
||||||
@ -50,6 +54,10 @@ void textureInit(texture_t *texture, int32_t width, int32_t height,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void textureBind(texture_t *texture, textureslot_t slot) {
|
void textureBind(texture_t *texture, textureslot_t slot) {
|
||||||
|
ASSERT_NOT_NULL(texture);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(slot, 0);
|
||||||
|
ASSERT_LESS_THAN(slot, TEXTURE_SLOTS_MAX);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0 + slot);
|
glActiveTexture(GL_TEXTURE0 + slot);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture->id);
|
glBindTexture(GL_TEXTURE_2D, texture->id);
|
||||||
}
|
}
|
||||||
@ -57,6 +65,15 @@ void textureBind(texture_t *texture, textureslot_t slot) {
|
|||||||
void textureBufferPixels(texture_t *texture,
|
void textureBufferPixels(texture_t *texture,
|
||||||
int32_t x, int32_t y, int32_t width, int32_t height, pixel_t *pixels
|
int32_t x, int32_t y, int32_t width, int32_t height, pixel_t *pixels
|
||||||
) {
|
) {
|
||||||
|
ASSERT_NOT_NULL(texture);
|
||||||
|
ASSERT_NOT_NULL(pixels);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(x, 0);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(y, 0);
|
||||||
|
ASSERT_GREATER_THAN(width, 0);
|
||||||
|
ASSERT_GREATER_THAN(height, 0);
|
||||||
|
ASSERT_LESS_THAN_EQUAL_TO(width, texture->width);
|
||||||
|
ASSERT_LESS_THAN_EQUAL_TO(height, texture->height);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texture->id);
|
glBindTexture(GL_TEXTURE_2D, texture->id);
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0,
|
glTexSubImage2D(GL_TEXTURE_2D, 0,
|
||||||
x, y, width, height,
|
x, y, width, height,
|
||||||
@ -65,5 +82,6 @@ void textureBufferPixels(texture_t *texture,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void textureDispose(texture_t *texture) {
|
void textureDispose(texture_t *texture) {
|
||||||
|
ASSERT_NOT_NULL(texture);
|
||||||
glDeleteTextures(1, &texture->id);
|
glDeleteTextures(1, &texture->id);
|
||||||
}
|
}
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../libs.h"
|
#include "../libs.h"
|
||||||
|
#include "../assert/assert.h"
|
||||||
|
|
||||||
#define TEXTURE_SLOTS_MAX 8
|
#define TEXTURE_SLOTS_MAX 8
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user