Added support for multitexturing to osg::State and added osgmultitexture

demo which adds as spherical environment map using texture 1 to any model.
This commit is contained in:
Robert Osfield
2002-07-11 16:12:24 +00:00
parent c4c97a0f64
commit 8219a0a63a
7 changed files with 347 additions and 19 deletions

View File

@@ -20,6 +20,18 @@ SG_EXPORT extern const bool isGLExtensionSupported(const char *extension);
*/
SG_EXPORT extern void* getGLExtensionFuncPtr(const char *funcName);
/** return the address of the specified OpenGL function, if not found then
* check a second function name, if this fails then return NULL as function is
* not supported by OpenGL library. This is usual for checking something
* like glActiveTexture (which is in OGL1.3) or glActiveTextureARB.
*/
inline void* getGLExtensionFuncPtr(const char *funcName,const char *fallbackFuncName)
{
void* ptr = getGLExtensionFuncPtr(funcName);
if (ptr) return ptr;
return getGLExtensionFuncPtr(fallbackFuncName);
}
}
#endif

View File

@@ -13,6 +13,8 @@
#include <osg/DisplaySettings>
#include <osg/Polytope>
#include <osg/GLExtensions>
#include <vector>
#include <map>
@@ -301,7 +303,7 @@ class SG_EXPORT State : public Referenced
* note, only updates values that change.*/
inline void disableIndexPointer()
{
//if (_indexArray._enabled)
if (_indexArray._enabled)
{
_indexArray._enabled = false;
glDisableClientState(GL_INDEX_ARRAY);
@@ -319,7 +321,7 @@ class SG_EXPORT State : public Referenced
if ( unit >= _texCoordArrayList.size()) _texCoordArrayList.resize(unit+1);
EnabledArrayPair& eap = _texCoordArrayList[unit];
//if (!eap._enabled)
if (!eap._enabled)
{
eap._enabled = true;
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
@@ -354,14 +356,22 @@ class SG_EXPORT State : public Referenced
* note, only updates values that change.*/
inline bool setClientActiveTextureUnit( unsigned int unit )
{
return unit==0;
// will need to check for extensions etc.
// if (unit!=_currentClientActiveTextureUnit)
// {
// glClientActiveTextureARB(GL_TEXTURE0_ARB+unit);
// _currentClientActiveTextureUnit = unit;
// }
// return true;
if (unit!=_currentClientActiveTextureUnit)
{
static ActiveTextureProc s_glClientActiveTexture =
(ActiveTextureProc) osg::getGLExtensionFuncPtr("glClientActiveTexture","glClientActiveTextureARB");
if (s_glClientActiveTexture)
{
s_glClientActiveTexture(GL_TEXTURE0_ARB+unit);
_currentClientActiveTextureUnit = unit;
}
else
{
return unit==0;
}
}
return true;
}
@@ -369,14 +379,22 @@ class SG_EXPORT State : public Referenced
* note, only updates values that change.*/
inline bool setActiveTextureUnit( unsigned int unit )
{
return unit==0;
//
// if (unit!=_currentActiveTextureUnit)
// {
// glActiveTextureARB(GL_TEXTURE0_ARB+unit);
// _currentActiveTextureUnit = unit;
// }
// return true;
if (unit!=_currentActiveTextureUnit)
{
static ActiveTextureProc s_glActiveTexture =
(ActiveTextureProc) osg::getGLExtensionFuncPtr("glActiveTexture","glActiveTextureARB");
if (s_glActiveTexture)
{
s_glActiveTexture(GL_TEXTURE0_ARB+unit);
_currentActiveTextureUnit = unit;
}
else
{
return unit==0;
}
}
return true;
}
@@ -500,7 +518,8 @@ class SG_EXPORT State : public Referenced
else
return false;
}
typedef void (APIENTRY * ActiveTextureProc) (GLenum texture);
typedef std::map<StateAttribute::GLMode,ModeStack> ModeMap;
typedef std::vector<ModeMap> TextureModeMapList;