Refactoring structs Part 1

This commit is contained in:
2021-05-20 22:20:52 -07:00
parent 17ddb4246a
commit 9bcf6223b6
56 changed files with 484 additions and 422 deletions

View File

@ -7,10 +7,9 @@
#include "texture.h"
texture_t * textureCreate(int32_t width, int32_t height, pixel_t *pixels) {
texture_t *texture = malloc(sizeof(texture_t));
if(texture == NULL) return NULL;
void textureInit(texture_t *texture, int32_t width, int32_t height,
pixel_t *pixels
) {
texture->width = width;
texture->height = height;
@ -27,13 +26,12 @@ texture_t * textureCreate(int32_t width, int32_t height, pixel_t *pixels) {
// Start by buffering all transparent black pixels.
if(pixels == NULL) {
// TODO: I can optimize this, I think the GPU can default this somehow
pixels = calloc(width * height, sizeof(pixel_t));
glTexImage2D(
GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, pixels
);
free(pixels);
} else {
glTexImage2D(
@ -59,5 +57,4 @@ void textureBufferPixels(texture_t *texture,
void textureDispose(texture_t *texture) {
glDeleteTextures(1, &texture->id);
free(texture);
}