Fixed texture filter modes not applying.
This commit is contained in:
		| @@ -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; | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user