mirror of https://github.com/bjornbytes/lovr.git
Texture filters;
This commit is contained in:
parent
b69a7be1ba
commit
8267733a42
|
@ -18,10 +18,8 @@ Texture* lovrTextureCreate(void* data, int size) {
|
|||
|
||||
glBindTexture(GL_TEXTURE_2D, texture->id);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture->width, texture->height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
lovrTextureSetFilter(texture, FILTER_LINEAR, FILTER_LINEAR);
|
||||
lovrTextureSetWrap(texture, WRAP_REPEAT, WRAP_REPEAT);
|
||||
free(image);
|
||||
}
|
||||
|
||||
|
@ -40,3 +38,29 @@ int lovrTextureGetHeight(Texture* texture) {
|
|||
int lovrTextureGetWidth(Texture* texture) {
|
||||
return texture->width;
|
||||
}
|
||||
|
||||
void lovrTextureGetFilter(Texture* texture, FilterMode* min, FilterMode* mag) {
|
||||
*min = texture->filterMin;
|
||||
*mag = texture->filterMag;
|
||||
}
|
||||
|
||||
void lovrTextureSetFilter(Texture* texture, FilterMode min, FilterMode mag) {
|
||||
texture->filterMin = min;
|
||||
texture->filterMag = mag;
|
||||
glBindTexture(GL_TEXTURE_2D, texture->id);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag);
|
||||
}
|
||||
|
||||
void lovrTextureGetWrap(Texture* texture, WrapMode* horizontal, WrapMode* vertical) {
|
||||
*horizontal = texture->wrapHorizontal;
|
||||
*vertical = texture->wrapVertical;
|
||||
}
|
||||
|
||||
void lovrTextureSetWrap(Texture* texture, WrapMode horizontal, WrapMode vertical) {
|
||||
texture->wrapHorizontal = horizontal;
|
||||
texture->wrapVertical = vertical;
|
||||
glBindTexture(GL_TEXTURE_2D, texture->id);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, horizontal);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, vertical);
|
||||
}
|
||||
|
|
|
@ -3,10 +3,26 @@
|
|||
#ifndef LOVR_TEXTURE_TYPES
|
||||
#define LOVR_TEXTURE_TYPES
|
||||
|
||||
typedef enum {
|
||||
FILTER_NEAREST = GL_NEAREST,
|
||||
FILTER_LINEAR = GL_LINEAR
|
||||
} FilterMode;
|
||||
|
||||
typedef enum {
|
||||
WRAP_CLAMP = GL_CLAMP_TO_EDGE,
|
||||
WRAP_REPEAT = GL_REPEAT,
|
||||
WRAP_MIRRORED_REPEAT = GL_MIRRORED_REPEAT,
|
||||
WRAP_CLAMP_ZERO = GL_CLAMP_TO_BORDER
|
||||
} WrapMode;
|
||||
|
||||
typedef struct {
|
||||
GLuint id;
|
||||
int width;
|
||||
int height;
|
||||
FilterMode filterMin;
|
||||
FilterMode filterMag;
|
||||
WrapMode wrapHorizontal;
|
||||
WrapMode wrapVertical;
|
||||
} Texture;
|
||||
|
||||
#endif
|
||||
|
@ -15,3 +31,7 @@ Texture* lovrTextureCreate(void* data, int size);
|
|||
void lovrTextureDestroy(Texture* texture);
|
||||
int lovrTextureGetHeight(Texture* texture);
|
||||
int lovrTextureGetWidth(Texture* texture);
|
||||
void lovrTextureGetFilter(Texture* texture, FilterMode* min, FilterMode* mag);
|
||||
void lovrTextureSetFilter(Texture* texture, FilterMode min, FilterMode mag);
|
||||
void lovrTextureGetWrap(Texture* texture, WrapMode* horizontal, WrapMode* vertical);
|
||||
void lovrTextureSetWrap(Texture* texture, WrapMode horizontal, WrapMode vertical);
|
||||
|
|
|
@ -113,6 +113,16 @@ int l_lovrGraphicsInit(lua_State* L) {
|
|||
map_set(&PolygonWindings, "clockwise", POLYGON_WINDING_CLOCKWISE);
|
||||
map_set(&PolygonWindings, "counterclockwise", POLYGON_WINDING_COUNTERCLOCKWISE);
|
||||
|
||||
map_init(&FilterModes);
|
||||
map_set(&FilterModes, "nearest", FILTER_NEAREST);
|
||||
map_set(&FilterModes, "linear", FILTER_LINEAR);
|
||||
|
||||
map_init(&WrapModes);
|
||||
map_set(&WrapModes, "clamp", WRAP_CLAMP);
|
||||
map_set(&WrapModes, "repeat", WRAP_REPEAT);
|
||||
map_set(&WrapModes, "mirroredrepeat", WRAP_MIRRORED_REPEAT);
|
||||
map_set(&WrapModes, "clampzero", WRAP_CLAMP_ZERO);
|
||||
|
||||
lovrGraphicsInit();
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ map_int_t BufferDrawModes;
|
|||
map_int_t BufferUsages;
|
||||
map_int_t DrawModes;
|
||||
map_int_t PolygonWindings;
|
||||
map_int_t FilterModes;
|
||||
map_int_t WrapModes;
|
||||
|
||||
extern const luaL_Reg lovrGraphics[];
|
||||
int l_lovrGraphicsInit(lua_State* L);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include "texture.h"
|
||||
#include "../graphics.h"
|
||||
#include "../../util.h"
|
||||
|
||||
void luax_pushtexture(lua_State* L, Texture* texture) {
|
||||
if (texture == NULL) {
|
||||
|
@ -23,8 +25,12 @@ int luax_destroytexture(lua_State* L) {
|
|||
|
||||
const luaL_Reg lovrTexture[] = {
|
||||
{ "getDimensions", l_lovrTextureGetDimensions },
|
||||
{ "getWidth", l_lovrTextureGetWidth },
|
||||
{ "getFilter", l_lovrTextureGetFilter },
|
||||
{ "getHeight", l_lovrTextureGetHeight },
|
||||
{ "getWidth", l_lovrTextureGetWidth },
|
||||
{ "getWrap", l_lovrTextureGetWrap },
|
||||
{ "setFilter", l_lovrTextureSetFilter },
|
||||
{ "setWrap", l_lovrTextureSetWrap },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
@ -35,10 +41,13 @@ int l_lovrTextureGetDimensions(lua_State* L) {
|
|||
return 2;
|
||||
}
|
||||
|
||||
int l_lovrTextureGetWidth(lua_State* L) {
|
||||
int l_lovrTextureGetFilter(lua_State* L) {
|
||||
Texture* texture = luax_checktexture(L, 1);
|
||||
lua_pushnumber(L, lovrTextureGetWidth(texture));
|
||||
return 1;
|
||||
FilterMode min, mag;
|
||||
lovrTextureGetFilter(texture, &min, &mag);
|
||||
lua_pushstring(L, map_int_find(&FilterModes, min));
|
||||
lua_pushstring(L, map_int_find(&FilterModes, mag));
|
||||
return 2;
|
||||
}
|
||||
|
||||
int l_lovrTextureGetHeight(lua_State* L) {
|
||||
|
@ -46,3 +55,34 @@ int l_lovrTextureGetHeight(lua_State* L) {
|
|||
lua_pushnumber(L, lovrTextureGetHeight(texture));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrTextureGetWidth(lua_State* L) {
|
||||
Texture* texture = luax_checktexture(L, 1);
|
||||
lua_pushnumber(L, lovrTextureGetWidth(texture));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrTextureGetWrap(lua_State* L) {
|
||||
Texture* texture = luax_checktexture(L, 1);
|
||||
WrapMode horizontal, vertical;
|
||||
lovrTextureGetWrap(texture, &horizontal, &vertical);
|
||||
lua_pushstring(L, map_int_find(&WrapModes, horizontal));
|
||||
lua_pushstring(L, map_int_find(&WrapModes, vertical));
|
||||
return 2;
|
||||
}
|
||||
|
||||
int l_lovrTextureSetFilter(lua_State* L) {
|
||||
Texture* texture = luax_checktexture(L, 1);
|
||||
FilterMode* min = (FilterMode*) luax_checkenum(L, 2, &FilterModes, "filter mode");
|
||||
FilterMode* mag = (FilterMode*) luax_optenum(L, 3, luaL_checkstring(L, 2), &FilterModes, "filter mode");
|
||||
lovrTextureSetFilter(texture, *min, *mag);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrTextureSetWrap(lua_State* L) {
|
||||
Texture* texture = luax_checktexture(L, 1);
|
||||
WrapMode* horizontal = (WrapMode*) luax_checkenum(L, 2, &WrapModes, "wrap mode");
|
||||
WrapMode* vertical = (WrapMode*) luax_optenum(L, 3, luaL_checkstring(L, 2), &WrapModes, "wrap mode");
|
||||
lovrTextureSetWrap(texture, *horizontal, *vertical);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -10,4 +10,8 @@ extern const luaL_Reg lovrTexture[];
|
|||
|
||||
int l_lovrTextureGetDimensions(lua_State* L);
|
||||
int l_lovrTextureGetHeight(lua_State* L);
|
||||
int l_lovrTextureGetFilter(lua_State* L);
|
||||
int l_lovrTextureGetWidth(lua_State* L);
|
||||
int l_lovrTextureGetWrap(lua_State* L);
|
||||
int l_lovrTextureSetFilter(lua_State* L);
|
||||
int l_lovrTextureSetWrap(lua_State* L);
|
||||
|
|
Loading…
Reference in New Issue