mirror of https://github.com/bjornbytes/lovr.git
Refactor texture filter structure;
This commit is contained in:
parent
bb2ec5b49c
commit
ef06a19fa4
|
@ -332,21 +332,20 @@ int l_lovrGraphicsSetWireframe(lua_State* L) {
|
|||
}
|
||||
|
||||
int l_lovrGraphicsGetDefaultFilter(lua_State* L) {
|
||||
FilterMode filter;
|
||||
float anisotropy;
|
||||
lovrGraphicsGetDefaultFilter(&filter, &anisotropy);
|
||||
luax_pushenum(L, &FilterModes, filter);
|
||||
if (filter == FILTER_ANISOTROPIC) {
|
||||
lua_pushnumber(L, anisotropy);
|
||||
TextureFilter filter = lovrGraphicsGetDefaultFilter();
|
||||
luax_pushenum(L, &FilterModes, filter.mode);
|
||||
if (filter.mode == FILTER_ANISOTROPIC) {
|
||||
lua_pushnumber(L, filter.anisotropy);
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrGraphicsSetDefaultFilter(lua_State* L) {
|
||||
FilterMode filter = *(FilterMode*) luax_checkenum(L, 1, &FilterModes, "filter mode");
|
||||
FilterMode mode = *(FilterMode*) luax_checkenum(L, 1, &FilterModes, "filter mode");
|
||||
float anisotropy = luaL_optnumber(L, 2, 1.);
|
||||
lovrGraphicsSetDefaultFilter(filter, anisotropy);
|
||||
TextureFilter filter = { .mode = mode, .anisotropy = anisotropy };
|
||||
lovrGraphicsSetDefaultFilter(filter);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,12 +16,10 @@ int l_lovrTextureGetDimensions(lua_State* L) {
|
|||
|
||||
int l_lovrTextureGetFilter(lua_State* L) {
|
||||
Texture* texture = luax_checktype(L, 1, Texture);
|
||||
FilterMode filter;
|
||||
float anisotropy;
|
||||
lovrTextureGetFilter(texture, &filter, &anisotropy);
|
||||
luax_pushenum(L, &FilterModes, filter);
|
||||
if (filter == FILTER_ANISOTROPIC) {
|
||||
lua_pushnumber(L, anisotropy);
|
||||
TextureFilter filter = lovrTextureGetFilter(texture);
|
||||
luax_pushenum(L, &FilterModes, filter.mode);
|
||||
if (filter.mode == FILTER_ANISOTROPIC) {
|
||||
lua_pushnumber(L, filter.anisotropy);
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
|
@ -61,9 +59,10 @@ int l_lovrTextureRenderTo(lua_State* L) {
|
|||
|
||||
int l_lovrTextureSetFilter(lua_State* L) {
|
||||
Texture* texture = luax_checktype(L, 1, Texture);
|
||||
FilterMode filter = *(FilterMode*) luax_checkenum(L, 2, &FilterModes, "filter mode");
|
||||
FilterMode mode = *(FilterMode*) luax_checkenum(L, 2, &FilterModes, "filter mode");
|
||||
float anisotropy = luaL_optnumber(L, 3, 1.);
|
||||
lovrTextureSetFilter(texture, filter, anisotropy);
|
||||
TextureFilter filter = { .mode = mode, .anisotropy = anisotropy };
|
||||
lovrTextureSetFilter(texture, filter);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,8 +48,9 @@ Font* lovrFontCreate(FontData* fontData) {
|
|||
|
||||
// Texture
|
||||
TextureData* textureData = lovrTextureDataGetBlank(font->atlas.width, font->atlas.height, 0x0, FORMAT_RGB);
|
||||
TextureFilter filter = { .mode = FILTER_BILINEAR };
|
||||
font->texture = lovrTextureCreate(textureData);
|
||||
lovrTextureSetFilter(font->texture, FILTER_BILINEAR, 1.);
|
||||
lovrTextureSetFilter(font->texture, filter);
|
||||
lovrTextureSetWrap(font->texture, WRAP_CLAMP, WRAP_CLAMP);
|
||||
|
||||
return font;
|
||||
|
|
|
@ -81,8 +81,7 @@ void lovrGraphicsInit() {
|
|||
|
||||
// Objects
|
||||
state.depthTest = -1;
|
||||
state.defaultFilter = FILTER_TRILINEAR;
|
||||
state.defaultAnisotropy = 1.;
|
||||
state.defaultFilter.mode = FILTER_TRILINEAR;
|
||||
state.defaultShader = lovrShaderCreate(lovrDefaultVertexShader, lovrDefaultFragmentShader);
|
||||
state.skyboxShader = lovrShaderCreate(lovrSkyboxVertexShader, lovrSkyboxFragmentShader);
|
||||
int uniformId = lovrShaderGetUniformId(state.skyboxShader, "cube");
|
||||
|
@ -363,18 +362,12 @@ void lovrGraphicsSetWireframe(int wireframe) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void lovrGraphicsGetDefaultFilter(FilterMode* filter, float* anisotropy) {
|
||||
*filter = state.defaultFilter;
|
||||
if (state.defaultFilter == FILTER_ANISOTROPIC) {
|
||||
*anisotropy = state.defaultAnisotropy;
|
||||
}
|
||||
TextureFilter lovrGraphicsGetDefaultFilter() {
|
||||
return state.defaultFilter;
|
||||
}
|
||||
|
||||
void lovrGraphicsSetDefaultFilter(FilterMode filter, float anisotropy) {
|
||||
void lovrGraphicsSetDefaultFilter(TextureFilter filter) {
|
||||
state.defaultFilter = filter;
|
||||
if (filter == FILTER_ANISOTROPIC) {
|
||||
state.defaultAnisotropy = anisotropy;
|
||||
}
|
||||
}
|
||||
|
||||
int lovrGraphicsGetWidth() {
|
||||
|
|
|
@ -92,8 +92,7 @@ typedef struct {
|
|||
PolygonWinding polygonWinding;
|
||||
CompareMode depthTest;
|
||||
int isWireframe;
|
||||
FilterMode defaultFilter;
|
||||
float defaultAnisotropy;
|
||||
TextureFilter defaultFilter;
|
||||
GraphicsLimits limits;
|
||||
} GraphicsState;
|
||||
|
||||
|
@ -132,8 +131,8 @@ CompareMode lovrGraphicsGetDepthTest();
|
|||
void lovrGraphicsSetDepthTest(CompareMode depthTest);
|
||||
int lovrGraphicsIsWireframe();
|
||||
void lovrGraphicsSetWireframe(int wireframe);
|
||||
void lovrGraphicsGetDefaultFilter(FilterMode* filter, float* anisotropy);
|
||||
void lovrGraphicsSetDefaultFilter(FilterMode filter, float anisotropy);
|
||||
TextureFilter lovrGraphicsGetDefaultFilter();
|
||||
void lovrGraphicsSetDefaultFilter(TextureFilter filter);
|
||||
int lovrGraphicsGetWidth();
|
||||
int lovrGraphicsGetHeight();
|
||||
GraphicsLimits lovrGraphicsGetLimits();
|
||||
|
|
|
@ -43,8 +43,7 @@ Texture* lovrTextureCreate(TextureData* textureData) {
|
|||
lovrGraphicsBindTexture(texture);
|
||||
lovrTextureCreateStorage(texture);
|
||||
lovrTextureRefresh(texture);
|
||||
lovrGraphicsGetDefaultFilter(&texture->filter, &texture->anisotropy);
|
||||
lovrTextureSetFilter(texture, texture->filter, texture->anisotropy);
|
||||
lovrTextureSetFilter(texture, lovrGraphicsGetDefaultFilter());
|
||||
lovrTextureSetWrap(texture, WRAP_REPEAT, WRAP_REPEAT);
|
||||
|
||||
return texture;
|
||||
|
@ -189,20 +188,17 @@ int lovrTextureGetWidth(Texture* texture) {
|
|||
return texture->textureData->width;
|
||||
}
|
||||
|
||||
void lovrTextureGetFilter(Texture* texture, FilterMode* filter, float* anisotropy) {
|
||||
*filter = texture->filter;
|
||||
if (texture->filter == FILTER_ANISOTROPIC) {
|
||||
*anisotropy = texture->anisotropy;
|
||||
}
|
||||
TextureFilter lovrTextureGetFilter(Texture* texture) {
|
||||
return texture->filter;
|
||||
}
|
||||
|
||||
void lovrTextureSetFilter(Texture* texture, FilterMode filter, float anisotropy) {
|
||||
void lovrTextureSetFilter(Texture* texture, TextureFilter filter) {
|
||||
int hasMipmaps = texture->textureData->format.compressed || texture->textureData->mipmaps.generated;
|
||||
float anisotropy = filter.mode == FILTER_ANISOTROPIC ? MAX(filter.anisotropy, 1.) : 1.;
|
||||
lovrGraphicsBindTexture(texture);
|
||||
texture->filter = filter;
|
||||
texture->anisotropy = filter == FILTER_ANISOTROPIC ? anisotropy : 1;
|
||||
|
||||
switch (filter) {
|
||||
switch (filter.mode) {
|
||||
case FILTER_NEAREST:
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
@ -230,7 +226,7 @@ void lovrTextureSetFilter(Texture* texture, FilterMode filter, float anisotropy)
|
|||
break;
|
||||
}
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, MAX(anisotropy, 1.0));
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy);
|
||||
}
|
||||
|
||||
void lovrTextureGetWrap(Texture* texture, WrapMode* horizontal, WrapMode* vertical) {
|
||||
|
|
|
@ -11,6 +11,11 @@ typedef enum {
|
|||
FILTER_ANISOTROPIC
|
||||
} FilterMode;
|
||||
|
||||
typedef struct {
|
||||
FilterMode mode;
|
||||
float anisotropy;
|
||||
} TextureFilter;
|
||||
|
||||
typedef enum {
|
||||
WRAP_CLAMP = GL_CLAMP_TO_EDGE,
|
||||
WRAP_REPEAT = GL_REPEAT,
|
||||
|
@ -31,8 +36,7 @@ typedef struct {
|
|||
GLuint resolveFramebuffer;
|
||||
GLuint depthBuffer;
|
||||
TextureProjection projection;
|
||||
FilterMode filter;
|
||||
float anisotropy;
|
||||
TextureFilter filter;
|
||||
WrapMode wrapHorizontal;
|
||||
WrapMode wrapVertical;
|
||||
int msaa;
|
||||
|
@ -48,7 +52,7 @@ void lovrTextureResolveMSAA(Texture* texture);
|
|||
void lovrTextureRefresh(Texture* texture);
|
||||
int lovrTextureGetHeight(Texture* texture);
|
||||
int lovrTextureGetWidth(Texture* texture);
|
||||
void lovrTextureGetFilter(Texture* texture, FilterMode* filter, float* anisotropy);
|
||||
void lovrTextureSetFilter(Texture* texture, FilterMode filter, float anisotropy);
|
||||
TextureFilter lovrTextureGetFilter(Texture* texture);
|
||||
void lovrTextureSetFilter(Texture* texture, TextureFilter filter);
|
||||
void lovrTextureGetWrap(Texture* texture, WrapMode* horizontal, WrapMode* vertical);
|
||||
void lovrTextureSetWrap(Texture* texture, WrapMode horizontal, WrapMode vertical);
|
||||
|
|
Loading…
Reference in New Issue