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