mirror of https://github.com/bjornbytes/lovr.git
Deprecate Buffer Textures;
This commit is contained in:
parent
e73e3fc5c4
commit
2a8d40abd6
|
@ -22,7 +22,7 @@ void lovrGraphicsInit() {
|
|||
state.skyboxShader = lovrShaderCreate(lovrSkyboxVertexShader, lovrSkyboxFragmentShader);
|
||||
int uniformId = lovrShaderGetUniformId(state.skyboxShader, "cube");
|
||||
lovrShaderSendInt(state.skyboxShader, uniformId, 1);
|
||||
state.defaultTexture = lovrTextureCreateFromData(lovrTextureDataGetEmpty());
|
||||
state.defaultTexture = lovrTextureCreate(lovrTextureDataGetEmpty(1, 1, 0xff));
|
||||
glGenBuffers(1, &state.shapeBuffer);
|
||||
glGenBuffers(1, &state.shapeIndexBuffer);
|
||||
glGenVertexArrays(1, &state.shapeArray);
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
#include "graphics/texture.h"
|
||||
#include "graphics/buffer.h"
|
||||
#include "util.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
Texture* lovrTextureCreateFromData(TextureData* textureData) {
|
||||
Texture* lovrTextureCreate(TextureData* textureData) {
|
||||
Texture* texture = lovrAlloc(sizeof(Texture), lovrTextureDestroy);
|
||||
if (!texture) return NULL;
|
||||
|
||||
texture->textureData = textureData;
|
||||
texture->type = TEXTURE_IMAGE;
|
||||
texture->buffer = NULL;
|
||||
glGenTextures(1, &texture->id);
|
||||
|
||||
if (textureData) {
|
||||
|
@ -22,30 +19,8 @@ Texture* lovrTextureCreateFromData(TextureData* textureData) {
|
|||
return texture;
|
||||
}
|
||||
|
||||
Texture* lovrTextureCreateFromBuffer(Buffer* buffer) {
|
||||
if (!buffer) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Texture* texture = lovrAlloc(sizeof(Texture), lovrTextureDestroy);
|
||||
if (!texture) return NULL;
|
||||
|
||||
glGenTextures(1, &texture->id);
|
||||
texture->textureData = NULL;
|
||||
texture->type = TEXTURE_BUFFER;
|
||||
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);
|
||||
}
|
||||
lovrTextureDataDestroy(texture->textureData);
|
||||
glDeleteTextures(1, &texture->id);
|
||||
free(texture);
|
||||
|
@ -57,16 +32,7 @@ void lovrTextureDataDestroy(TextureData* textureData) {
|
|||
}
|
||||
|
||||
void lovrTextureBind(Texture* texture) {
|
||||
glBindTexture(texture->type, texture->id);
|
||||
}
|
||||
|
||||
void lovrTextureRefresh(Texture* texture) {
|
||||
if (!texture->buffer) {
|
||||
return;
|
||||
}
|
||||
|
||||
lovrTextureBind(texture);
|
||||
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, texture->buffer->vbo);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->id);
|
||||
}
|
||||
|
||||
int lovrTextureGetHeight(Texture* texture) {
|
||||
|
|
|
@ -13,11 +13,6 @@ typedef struct {
|
|||
int channels;
|
||||
} TextureData;
|
||||
|
||||
typedef enum {
|
||||
TEXTURE_IMAGE = GL_TEXTURE_2D,
|
||||
TEXTURE_BUFFER = GL_TEXTURE_BUFFER
|
||||
} TextureType;
|
||||
|
||||
typedef enum {
|
||||
FILTER_NEAREST = GL_NEAREST,
|
||||
FILTER_LINEAR = GL_LINEAR
|
||||
|
@ -33,7 +28,6 @@ typedef enum {
|
|||
typedef struct {
|
||||
Ref ref;
|
||||
TextureData* textureData;
|
||||
TextureType type;
|
||||
GLuint id;
|
||||
int width;
|
||||
int height;
|
||||
|
@ -41,13 +35,11 @@ typedef struct {
|
|||
FilterMode filterMag;
|
||||
WrapMode wrapHorizontal;
|
||||
WrapMode wrapVertical;
|
||||
struct Buffer* buffer;
|
||||
} Texture;
|
||||
|
||||
#endif
|
||||
|
||||
Texture* lovrTextureCreateFromData(TextureData* textureData);
|
||||
Texture* lovrTextureCreateFromBuffer(struct Buffer* buffer);
|
||||
Texture* lovrTextureCreate(TextureData* textureData);
|
||||
void lovrTextureDestroy(const Ref* ref);
|
||||
void lovrTextureDataDestroy(TextureData* textureData);
|
||||
void lovrTextureBind(Texture* texture);
|
||||
|
|
|
@ -2,17 +2,19 @@
|
|||
#include "util.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
TextureData* lovrTextureDataGetEmpty() {
|
||||
TextureData* lovrTextureDataGetEmpty(int width, int height, uint8_t value) {
|
||||
TextureData* textureData = malloc(sizeof(TextureData));
|
||||
if (!textureData) return NULL;
|
||||
|
||||
uint8_t* pixel = malloc(4 * sizeof(uint8_t));
|
||||
pixel[0] = pixel[1] = pixel[2] = pixel[3] = 0xff;
|
||||
int channels = 4;
|
||||
int size = sizeof(uint8_t) * width * height * channels;
|
||||
uint8_t* data = malloc(size);
|
||||
memset(data, value, size);
|
||||
|
||||
textureData->width = 1;
|
||||
textureData->height = 1;
|
||||
textureData->channels = 4;
|
||||
textureData->data = pixel;
|
||||
textureData->data = data;
|
||||
textureData->width = width;
|
||||
textureData->height = height;
|
||||
textureData->channels = channels;
|
||||
|
||||
return textureData;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "graphics/texture.h"
|
||||
#include "openvr.h"
|
||||
#include <stdint.h>
|
||||
|
||||
TextureData* lovrTextureDataGetEmpty();
|
||||
TextureData* lovrTextureDataGetEmpty(int width, int height, uint8_t value);
|
||||
TextureData* lovrTextureDataFromFile(void* data, int size);
|
||||
TextureData* lovrTextureDataFromOpenVRModel(OpenVRModel* vrModel);
|
||||
|
|
|
@ -641,23 +641,19 @@ int l_lovrGraphicsNewSkybox(lua_State* L) {
|
|||
|
||||
int l_lovrGraphicsNewTexture(lua_State* L) {
|
||||
Texture* texture;
|
||||
const char* path = luaL_checkstring(L, 1);
|
||||
|
||||
if (lua_isstring(L, 1)) {
|
||||
const char* path = luaL_checkstring(L, 1);
|
||||
int size;
|
||||
void* data = lovrFilesystemRead(path, &size);
|
||||
if (!data) {
|
||||
return luaL_error(L, "Could not load texture file '%s'", path);
|
||||
}
|
||||
TextureData* textureData = lovrTextureDataFromFile(data, size);
|
||||
texture = lovrTextureCreateFromData(textureData);
|
||||
free(data);
|
||||
} else {
|
||||
Buffer* buffer = luax_checktype(L, 1, Buffer); // TODO don't error if it's not a buffer
|
||||
texture = lovrTextureCreateFromBuffer(buffer);
|
||||
int size;
|
||||
void* data = lovrFilesystemRead(path, &size);
|
||||
if (!data) {
|
||||
return luaL_error(L, "Could not load texture file '%s'", path);
|
||||
}
|
||||
|
||||
TextureData* textureData = lovrTextureDataFromFile(data, size);
|
||||
texture = lovrTextureCreate(textureData);
|
||||
free(data);
|
||||
luax_pushtype(L, Texture, texture);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ int l_lovrControllerNewModel(lua_State* L) {
|
|||
ModelData* modelData = lovrModelDataFromOpenVRModel(rawData);
|
||||
TextureData* textureData = lovrTextureDataFromOpenVRModel(rawData);
|
||||
Model* model = lovrModelCreate(modelData);
|
||||
Texture* texture = lovrTextureCreateFromData(textureData);
|
||||
Texture* texture = lovrTextureCreate(textureData);
|
||||
lovrModelSetTexture(model, texture);
|
||||
luax_pushtype(L, Model, model);
|
||||
} else {
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
const luaL_Reg lovrTexture[] = {
|
||||
{ "bind", l_lovrTextureBind },
|
||||
{ "refresh", l_lovrTextureRefresh },
|
||||
{ "getDimensions", l_lovrTextureGetDimensions },
|
||||
{ "getFilter", l_lovrTextureGetFilter },
|
||||
{ "getHeight", l_lovrTextureGetHeight },
|
||||
|
@ -21,12 +20,6 @@ int l_lovrTextureBind(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrTextureRefresh(lua_State* L) {
|
||||
Texture* texture = luax_checktype(L, 1, Texture);
|
||||
lovrTextureRefresh(texture);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrTextureGetDimensions(lua_State* L) {
|
||||
Texture* texture = luax_checktype(L, 1, Texture);
|
||||
lua_pushnumber(L, lovrTextureGetWidth(texture));
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
extern const luaL_Reg lovrTexture[];
|
||||
int l_lovrTextureBind(lua_State* L);
|
||||
int l_lovrTextureRefresh(lua_State* L);
|
||||
int l_lovrTextureGetDimensions(lua_State* L);
|
||||
int l_lovrTextureGetHeight(lua_State* L);
|
||||
int l_lovrTextureGetFilter(lua_State* L);
|
||||
|
|
Loading…
Reference in New Issue