Commit 63e4360f authored by hybrid's avatar hybrid

Fixed the clamping problems in OpenGL, thanks to ikam. Also cleaned up the 2d render state init.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1424 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 17d5f8a3
...@@ -1574,8 +1574,8 @@ void COpenGLDriver::setRenderStates3DMode() ...@@ -1574,8 +1574,8 @@ void COpenGLDriver::setRenderStates3DMode()
if (FeatureAvailable[IRR_ARB_texture_env_combine]) if (FeatureAvailable[IRR_ARB_texture_env_combine])
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE ); glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE );
glDisable(GL_ALPHA_TEST); glDisable(GL_ALPHA_TEST);
glDisable( GL_BLEND ); glDisable(GL_BLEND);
glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_COLOR ); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
// switch back the matrices // switch back the matrices
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
...@@ -1673,8 +1673,6 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater ...@@ -1673,8 +1673,6 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
// Filtering has to be set for each texture layer // Filtering has to be set for each texture layer
for (u32 i=0; i<MaxTextureUnits; ++i) for (u32 i=0; i<MaxTextureUnits; ++i)
{ {
if (!material.getTexture(i))
continue;
if (MultiTextureExtension) if (MultiTextureExtension)
extGlActiveTexture(GL_TEXTURE0_ARB + i); extGlActiveTexture(GL_TEXTURE0_ARB + i);
else if (i>0) else if (i>0)
...@@ -1801,80 +1799,78 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater ...@@ -1801,80 +1799,78 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
} }
// texture address mode // texture address mode
// Has to be checked always because it depends on the textures
for (u32 u=0; u<MaxTextureUnits; ++u) for (u32 u=0; u<MaxTextureUnits; ++u)
{ {
if (resetAllRenderStates || (lastmaterial.TextureLayer[u].TextureWrap != material.TextureLayer[u].TextureWrap)) if (MultiTextureExtension)
{ extGlActiveTexture(GL_TEXTURE0_ARB + u);
if (MultiTextureExtension) else if (u>0)
extGlActiveTexture(GL_TEXTURE0_ARB + u); break; // stop loop
else if (u>0)
break; // stop loop
GLint mode=GL_REPEAT; GLint mode=GL_REPEAT;
switch (material.TextureLayer[u].TextureWrap) switch (material.TextureLayer[u].TextureWrap)
{ {
case ETC_REPEAT: case ETC_REPEAT:
mode=GL_REPEAT; mode=GL_REPEAT;
break; break;
case ETC_CLAMP: case ETC_CLAMP:
mode=GL_CLAMP; mode=GL_CLAMP;
break; break;
case ETC_CLAMP_TO_EDGE: case ETC_CLAMP_TO_EDGE:
#ifdef GL_VERSION_1_2 #ifdef GL_VERSION_1_2
if (Version>101) if (Version>101)
mode=GL_CLAMP_TO_EDGE; mode=GL_CLAMP_TO_EDGE;
else else
#endif #endif
#ifdef GL_SGIS_texture_edge_clamp #ifdef GL_SGIS_texture_edge_clamp
if (FeatureAvailable[IRR_SGIS_texture_edge_clamp]) if (FeatureAvailable[IRR_SGIS_texture_edge_clamp])
mode=GL_CLAMP_TO_EDGE_SGIS; mode=GL_CLAMP_TO_EDGE_SGIS;
else else
#endif #endif
// fallback // fallback
mode=GL_CLAMP; mode=GL_CLAMP;
break; break;
case ETC_CLAMP_TO_BORDER: case ETC_CLAMP_TO_BORDER:
#ifdef GL_VERSION_1_3 #ifdef GL_VERSION_1_3
if (Version>102) if (Version>102)
mode=GL_CLAMP_TO_BORDER; mode=GL_CLAMP_TO_BORDER;
else else
#endif #endif
#ifdef GL_ARB_texture_border_clamp #ifdef GL_ARB_texture_border_clamp
if (FeatureAvailable[IRR_ARB_texture_border_clamp]) if (FeatureAvailable[IRR_ARB_texture_border_clamp])
mode=GL_CLAMP_TO_BORDER_ARB; mode=GL_CLAMP_TO_BORDER_ARB;
else else
#endif #endif
#ifdef GL_SGIS_texture_border_clamp #ifdef GL_SGIS_texture_border_clamp
if (FeatureAvailable[IRR_SGIS_texture_border_clamp]) if (FeatureAvailable[IRR_SGIS_texture_border_clamp])
mode=GL_CLAMP_TO_BORDER_SGIS; mode=GL_CLAMP_TO_BORDER_SGIS;
else else
#endif #endif
// fallback // fallback
mode=GL_CLAMP; mode=GL_CLAMP;
break; break;
case ETC_MIRROR: case ETC_MIRROR:
#ifdef GL_VERSION_1_4 #ifdef GL_VERSION_1_4
if (Version>103) if (Version>103)
mode=GL_MIRRORED_REPEAT; mode=GL_MIRRORED_REPEAT;
else else
#endif #endif
#ifdef GL_ARB_texture_border_clamp #ifdef GL_ARB_texture_border_clamp
if (FeatureAvailable[IRR_ARB_texture_mirrored_repeat]) if (FeatureAvailable[IRR_ARB_texture_mirrored_repeat])
mode=GL_MIRRORED_REPEAT_ARB; mode=GL_MIRRORED_REPEAT_ARB;
else else
#endif #endif
#ifdef GL_IBM_texture_mirrored_repeat #ifdef GL_IBM_texture_mirrored_repeat
if (FeatureAvailable[IRR_IBM_texture_mirrored_repeat]) if (FeatureAvailable[IRR_IBM_texture_mirrored_repeat])
mode=GL_MIRRORED_REPEAT_IBM; mode=GL_MIRRORED_REPEAT_IBM;
else else
#endif #endif
mode=GL_REPEAT; mode=GL_REPEAT;
break; break;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mode);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mode);
} }
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mode);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mode);
} }
// be sure to leave in texture stage 0 // be sure to leave in texture stage 0
if (MultiTextureExtension) if (MultiTextureExtension)
...@@ -1895,8 +1891,10 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh ...@@ -1895,8 +1891,10 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh
SMaterial mat; SMaterial mat;
mat.ZBuffer=0; mat.ZBuffer=0;
mat.Lighting=false; mat.Lighting=false;
mat.TextureLayer[0].BilinearFilter=false;
setBasicRenderStates(mat, mat, true); setBasicRenderStates(mat, mat, true);
LastMaterial = mat; LastMaterial = mat;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
} }
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
...@@ -1917,30 +1915,25 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh ...@@ -1917,30 +1915,25 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh
Transformation3DChanged = false; Transformation3DChanged = false;
} }
if (alphaChannel || alpha)
glEnable(GL_BLEND);
else
glDisable(GL_BLEND);
if (texture) if (texture)
{ {
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
if (alphaChannel) if (alphaChannel)
{ {
if (alpha) if (alpha)
{ {
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, GL_PRIMARY_COLOR_EXT); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, GL_PRIMARY_COLOR_EXT);
} }
else else
{ {
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE);
} }
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
...@@ -1954,35 +1947,19 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh ...@@ -1954,35 +1947,19 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PRIMARY_COLOR_EXT); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PRIMARY_COLOR_EXT);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
} }
else else
{ {
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glDisable(GL_BLEND);
} }
} }
} }
else
{
if (alpha)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
else
{
glDisable(GL_BLEND);
}
}
CurrentRenderMode = ERM_2D; CurrentRenderMode = ERM_2D;
} }
//! \return Returns the name of the video driver. Example: In case of the Direct3D8 //! \return Returns the name of the video driver.
//! driver, it would return "Direct3D8.1".
const wchar_t* COpenGLDriver::getName() const const wchar_t* COpenGLDriver::getName() const
{ {
return Name.c_str(); return Name.c_str();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment