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

View File

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