From Pavel Moloshtan, added GL_ARB_shadow_support to osg::Texture.

This commit is contained in:
Robert Osfield
2003-12-17 19:26:16 +00:00
parent 1e361017c8
commit 8fefec9f47
2 changed files with 63 additions and 4 deletions

View File

@@ -75,6 +75,11 @@
#define GL_TEXTURE_3D 0x806F
#endif
#ifndef GL_TEXTURE_COMPARE_MODE_ARB
#define GL_TEXTURE_COMPARE_MODE_ARB 0x884C
#define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D
#define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E
#endif
namespace osg {
@@ -232,6 +237,29 @@ class SG_EXPORT Texture : public osg::StateAttribute
void dirtyTextureParameters();
// set mode of GL_TEXTURE_COMPARE_MODE_ARB to GL_COMPARE_R_TO_TEXTURE_ARB
// See http://oss.sgi.com/projects/ogl-sample/registry/ARB/shadow.txt
void setShadowComparison(bool flag) { _use_shadow_comparison = flag; }
enum ShadowCompareFunc {
LEQUAL = GL_LEQUAL,
GEQUAL = GL_GEQUAL
};
// set shadow texture comparison function
void setShadowCompareFunc(ShadowCompareFunc func) { _shadow_compare_func = func; }
ShadowCompareFunc getShadowCompareFunc() { return _shadow_compare_func; }
enum ShadowTextureMode {
LUMINANCE = GL_LUMINANCE,
INTENSITY = GL_INTENSITY,
ALPHA = GL_ALPHA
};
// set shadow texture mode after comparison
void setShadowTextureMode(ShadowTextureMode mode) { _shadow_texture_mode = mode; }
ShadowTextureMode getShadowTextureMode() { return _shadow_texture_mode; }
/** Texture is pure virtual base class, apply must be overriden. */
@@ -278,6 +306,9 @@ class SG_EXPORT Texture : public osg::StateAttribute
void setGenerateMipMapSupported(bool flag) { _isGenerateMipMapSupported=flag; }
bool isGenerateMipMapSupported() const { return _isGenerateMipMapSupported; }
void setShadowSupported(bool flag) { _isShadowSupported = flag; }
bool isShadowSupported() const { return _isShadowSupported; }
void setMaxTextureSize(GLint maxsize) { _maxTextureSize=maxsize; }
GLint maxTextureSize() const { return _maxTextureSize; }
@@ -304,6 +335,7 @@ class SG_EXPORT Texture : public osg::StateAttribute
bool _isTextureEdgeClampSupported;
bool _isTextureBorderClampSupported;
bool _isGenerateMipMapSupported;
bool _isShadowSupported;
GLint _maxTextureSize;
@@ -372,8 +404,11 @@ class SG_EXPORT Texture : public osg::StateAttribute
InternalFormatMode _internalFormatMode;
mutable GLint _internalFormat;
bool _use_shadow_comparison;
ShadowCompareFunc _shadow_compare_func;
ShadowTextureMode _shadow_texture_mode;
public:
class TextureObject : public osg::Referenced

View File

@@ -174,7 +174,10 @@ Texture::Texture():
_unrefImageDataAfterApply(false),
_borderColor(0.0, 0.0, 0.0, 0.0),
_internalFormatMode(USE_IMAGE_DATA_FORMAT),
_internalFormat(0)
_internalFormat(0),
_use_shadow_comparison(false),
_shadow_compare_func(LEQUAL),
_shadow_texture_mode(LUMINANCE)
{
}
@@ -190,7 +193,10 @@ Texture::Texture(const Texture& text,const CopyOp& copyop):
_unrefImageDataAfterApply(text._unrefImageDataAfterApply),
_borderColor(text._borderColor),
_internalFormatMode(text._internalFormatMode),
_internalFormat(text._internalFormat)
_internalFormat(text._internalFormat),
_use_shadow_comparison(text._use_shadow_comparison),
_shadow_compare_func(text._shadow_compare_func),
_shadow_texture_mode(text._shadow_texture_mode)
{
}
@@ -211,6 +217,9 @@ int Texture::compareTexture(const Texture& rhs) const
COMPARE_StateAttribute_Parameter(_useHardwareMipMapGeneration)
COMPARE_StateAttribute_Parameter(_internalFormatMode)
COMPARE_StateAttribute_Parameter(_internalFormat)
COMPARE_StateAttribute_Parameter(_use_shadow_comparison)
COMPARE_StateAttribute_Parameter(_shadow_compare_func)
COMPARE_StateAttribute_Parameter(_shadow_texture_mode)
return 0;
}
@@ -474,6 +483,20 @@ void Texture::applyTexParameters(GLenum target, State& state) const
glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, _borderColor.ptr());
}
if (extensions->isShadowSupported() && target == GL_TEXTURE_2D)
{
if (_use_shadow_comparison)
{
glTexParameteri(target, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
glTexParameteri(target, GL_TEXTURE_COMPARE_FUNC_ARB, _shadow_compare_func);
glTexParameteri(target, GL_DEPTH_TEXTURE_MODE_ARB, _shadow_texture_mode);
}
else
{
glTexParameteri(target, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
}
}
getTextureParameterDirty(state.getContextID()) = false;
}
@@ -1038,6 +1061,7 @@ void Texture::Extensions::setupGLExtenions()
_isTextureBorderClampSupported = isGLExtensionSupported("GL_ARB_texture_border_clamp");
_isGenerateMipMapSupported = (strncmp((const char*)glGetString(GL_VERSION),"1.4",3)>=0) ||
isGLExtensionSupported("GL_SGIS_generate_mipmap");
_isShadowSupported = isGLExtensionSupported("GL_ARB_shadow");
glGetIntegerv(GL_MAX_TEXTURE_SIZE,&_maxTextureSize);