Fixed texture filter modes not applying.

This commit is contained in:
2023-05-22 11:52:10 -07:00
parent fd6d6ab677
commit b65f52878a
2 changed files with 74 additions and 62 deletions

View File

@ -36,12 +36,16 @@ namespace Dawn {
StateProperty<enum TextureWrapMode> wrapModeY;
StateProperty<enum TextureFilterMode> filterModeMin;
StateProperty<enum TextureFilterMode> filterModeMag;
StateProperty<enum TextureFilterMode> mipmapFilterModeMin;
StateProperty<enum TextureFilterMode> mipmapFilterModeMag;
ITexture() :
wrapModeX(TEXTURE_WRAP_MODE_CLAMP_TO_EDGE),
wrapModeY(TEXTURE_WRAP_MODE_CLAMP_TO_EDGE),
filterModeMin(TEXTURE_FILTER_MODE_LINEAR),
filterModeMag(TEXTURE_FILTER_MODE_LINEAR)
filterModeMag(TEXTURE_FILTER_MODE_LINEAR),
mipmapFilterModeMin(TEXTURE_FILTER_MODE_NEAREST),
mipmapFilterModeMag(TEXTURE_FILTER_MODE_NEAREST)
{
}

View File

@ -8,6 +8,13 @@
using namespace Dawn;
Texture::Texture() : ITexture() {
useEffect([&]{
this->texturePropertiesNeedUpdating = true;
}, {
&this->wrapModeX, &this->wrapModeY,
&this->filterModeMin, &this->filterModeMag,
&this->mipmapFilterModeMin, &this->mipmapFilterModeMag
});
}
void Texture::bind(textureslot_t slot) {
@ -60,77 +67,78 @@ bool_t Texture::isReady() {
}
void Texture::updateTextureProperties() {
switch(((enum TextureWrapMode)this->wrapModeX)) {
case TEXTURE_WRAP_MODE_REPEAT:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
break;
case TEXTURE_WRAP_MODE_MIRRORED_REPEAT:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
break;
auto setWrapMode = [&](GLenum axis, enum TextureWrapMode wm) {
switch(wm) {
case TEXTURE_WRAP_MODE_REPEAT:
glTexParameteri(GL_TEXTURE_2D, axis, GL_REPEAT);
break;
case TEXTURE_WRAP_MODE_MIRRORED_REPEAT:
glTexParameteri(GL_TEXTURE_2D, axis, GL_MIRRORED_REPEAT);
break;
case TEXTURE_WRAP_MODE_CLAMP_TO_EDGE:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
break;
case TEXTURE_WRAP_MODE_CLAMP_TO_EDGE:
glTexParameteri(GL_TEXTURE_2D, axis, GL_CLAMP_TO_EDGE);
break;
case TEXTURE_WRAP_MODE_CLAMP_TO_BORDER:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
break;
case TEXTURE_WRAP_MODE_CLAMP_TO_BORDER:
glTexParameteri(GL_TEXTURE_2D, axis, GL_CLAMP_TO_BORDER);
break;
default:
assertUnreachable();
}
default:
assertUnreachable();
}
};
switch(((enum TextureWrapMode)this->wrapModeY)) {
case TEXTURE_WRAP_MODE_REPEAT:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T ,GL_REPEAT);
break;
case TEXTURE_WRAP_MODE_MIRRORED_REPEAT:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
break;
setWrapMode(GL_TEXTURE_WRAP_S, this->wrapModeX);
setWrapMode(GL_TEXTURE_WRAP_T, this->wrapModeY);
case TEXTURE_WRAP_MODE_CLAMP_TO_EDGE:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
break;
auto setFilterMode = [&](
GLenum minMag,
enum TextureFilterMode filter,
enum TextureFilterMode mapFilterMode
) {
switch(filter) {
case TEXTURE_FILTER_MODE_NEAREST: {
switch(mapFilterMode) {
case TEXTURE_FILTER_MODE_NEAREST:
glTexParameteri(GL_TEXTURE_2D, minMag, GL_NEAREST_MIPMAP_NEAREST);
break;
case TEXTURE_WRAP_MODE_CLAMP_TO_BORDER:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
break;
case TEXTURE_FILTER_MODE_LINEAR:
glTexParameteri(GL_TEXTURE_2D, minMag, GL_LINEAR_MIPMAP_NEAREST);
break;
default:
assertUnreachable();
}
default:
assertUnreachable();
}
break;
}
case TEXTURE_FILTER_MODE_LINEAR: {
switch(mapFilterMode) {
case TEXTURE_FILTER_MODE_NEAREST:
glTexParameteri(GL_TEXTURE_2D, minMag, GL_NEAREST_MIPMAP_LINEAR);
break;
switch(((enum TextureFilterMode)this->filterModeMin)) {
case TEXTURE_FILTER_MODE_NEAREST:
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
break;
case TEXTURE_FILTER_MODE_LINEAR:
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
break;
case TEXTURE_FILTER_MODE_LINEAR:
glTexParameteri(GL_TEXTURE_2D, minMag, GL_LINEAR_MIPMAP_LINEAR);
break;
default:
assertUnreachable();
}
default:
assertUnreachable();
}
break;
}
switch(((enum TextureFilterMode)this->filterModeMag)) {
case TEXTURE_FILTER_MODE_NEAREST:
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
break;
case TEXTURE_FILTER_MODE_LINEAR:
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
break;
default: {
assertUnreachable();
}
}
};
default:
assertUnreachable();
}
setFilterMode(GL_TEXTURE_MIN_FILTER, this->filterModeMin, this->mipmapFilterModeMin);
setFilterMode(GL_TEXTURE_MAG_FILTER, this->filterModeMag, this->mipmapFilterModeMag);
}
void Texture::bufferRaw(void *data) {
@ -164,7 +172,7 @@ void Texture::bufferRaw(void *data) {
this->width, this->height,
0, format, GL_UNSIGNED_BYTE, data
);
// glGenerateMipmap(GL_TEXTURE_2D);
glGenerateMipmap(GL_TEXTURE_2D);
this->texturePropertiesNeedUpdating = true;
}