1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-03 04:53:35 +00:00

Fix texture reference counting;

This commit is contained in:
bjorn 2016-11-19 14:21:17 -08:00
parent 00656b928e
commit d014daaa53
2 changed files with 8 additions and 4 deletions

View file

@ -33,19 +33,23 @@ Texture* lovrTextureCreateFromBuffer(Buffer* buffer) {
return NULL; return NULL;
} }
Texture* texture = malloc(sizeof(Texture)); Texture* texture = lovrAlloc(sizeof(Texture), lovrTextureDestroy);
if (!texture) return NULL; if (!texture) return NULL;
glGenTextures(1, &texture->id); glGenTextures(1, &texture->id);
texture->buffer = buffer->vbo; texture->buffer = buffer;
lovrTextureBind(texture); lovrTextureBind(texture);
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, buffer->vbo); glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, buffer->vbo);
lovrRetain(&buffer->ref);
return texture; return texture;
} }
void lovrTextureDestroy(const Ref* ref) { void lovrTextureDestroy(const Ref* ref) {
Texture* texture = containerof(ref, Texture); Texture* texture = containerof(ref, Texture);
if (texture->buffer) {
lovrRelease(&texture->buffer->ref);
}
glDeleteTextures(1, &texture->id); glDeleteTextures(1, &texture->id);
free(texture); free(texture);
} }
@ -60,7 +64,7 @@ void lovrTextureRefresh(Texture* texture) {
} }
lovrTextureBind(texture); lovrTextureBind(texture);
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, texture->buffer); glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, texture->buffer->vbo);
} }
int lovrTextureGetHeight(Texture* texture) { int lovrTextureGetHeight(Texture* texture) {

View file

@ -21,7 +21,7 @@ typedef enum {
typedef struct { typedef struct {
Ref ref; Ref ref;
GLuint id; GLuint id;
GLuint buffer; struct Buffer* buffer;
int width; int width;
int height; int height;
FilterMode filterMin; FilterMode filterMin;