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