Added osg::TextureCubeMap which encapsulates OpenGL's cube texture mapping.

This commit is contained in:
Robert Osfield
2002-03-20 22:39:51 +00:00
parent 8656adb463
commit 9836af1055
8 changed files with 51 additions and 16 deletions

View File

@@ -37,7 +37,7 @@ Neil Salter <neil@nackle.org>
Brede Johansen <bredej@email.com>
- flt loader.
- osg::Point.
- bug fixes.
- osg::TextureCubeMap
- assistance on visual studio workspace files.
Ben Discoe <ben@vterrain.org>

View File

@@ -246,6 +246,10 @@ SOURCE=..\..\..\src\osgPlugins\osg\Texture.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\osg\TextureCubeMap.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\osg\Transform.cpp
# End Source File
# Begin Source File

View File

@@ -9,6 +9,9 @@
#include <osg/Texture>
#ifndef GL_TEXTURE_CUBE_MAP
#define GL_TEXTURE_CUBE_MAP 0x8513
#endif
namespace osg {
@@ -38,8 +41,14 @@ class SG_EXPORT TextureCubeMap : public Texture
NEGATIVE_Z=5
};
/** Set the texture image. */
void setImage( const Face, Image* image);
/** Set the texture image for specified face. */
void setImage(const Face, Image* image);
/** Get the texture image for specified face. */
Image* getImage(const Face);
/** Get the const texture image for specified face. */
const Image* getImage(const Face) const;
/** On first apply (unless already compiled), create the minmapped
* texture and bind it, subsequent apply will simple bind to texture.*/
@@ -49,7 +58,9 @@ class SG_EXPORT TextureCubeMap : public Texture
virtual ~TextureCubeMap();
bool imagesValid() const;
void setImage(Image* image) {} // prevent call to Texture::setImage(Image* image)
void setImage(Image*) {} // prevent call to Texture::setImage(Image* image)
Image* getImage() { return _image.get(); } // prevent call to Texture::setImage(Image* image)
const Image* getImage() const { return _image.get(); } // prevent call to Texture::setImage(Image* image)
mutable ref_ptr<Image> _images[6];
};

View File

@@ -223,6 +223,7 @@ void Texture::apply(State& state) const
glGenTextures( 1L, (GLuint *)&handle );
glBindTexture( _target, handle );
applyTexParameters(_target,state);
applyTexImage(_target,_image.get(),state);
// in theory the following line is redundent, but in practice
@@ -315,7 +316,7 @@ void Texture::applyTexParameters(GLenum target, State&) const
void Texture::applyTexImage(GLenum target, Image* image, State& state) const
{
// if we don't have a valid image we can't create a texture!
if (!_image || !_image->data())
if (!image || !image->data())
return;
// get the contextID (user defined ID of 0 upwards) for the
@@ -331,8 +332,6 @@ void Texture::applyTexImage(GLenum target, Image* image, State& state) const
glPixelStorei(GL_UNPACK_ALIGNMENT,image->packing());
applyTexParameters(target,state);
static bool s_ARB_Compression = isGLExtensionSupported("GL_ARB_texture_compression");
static bool s_S3TC_Compression = isGLExtensionSupported("GL_EXT_texture_compression_s3tc");

View File

@@ -15,10 +15,12 @@
using namespace osg;
// include/osg/TextureCubeMap defines GL_TEXTURE_CUBE_MAP to be
// 0x8513 which is the same as GL_TEXTURE_CUBE_MAP_ARB & _EXT.
// assume its the same as what OpenGL 1.3 defines.
#ifndef GL_ARB_texture_cube_map
#define GL_ARB_texture_cube_map 1
//#define GL_NORMAL_MAP_ARB 0x8511 // defined in TexGen
//#define GL_REFLECTION_MAP_ARB 0x8512 // --- '' ---
#define GL_TEXTURE_CUBE_MAP_ARB 0x8513
#define GL_TEXTURE_BINDING_CUBE_MAP_ARB 0x8514
#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515
@@ -34,8 +36,6 @@ using namespace osg;
#ifndef GL_EXT_texture_cube_map
#define GL_EXT_texture_cube_map 1
//#define GL_NORMAL_MAP_EXT 0x8511
//#define GL_REFLECTION_MAP_EXT 0x8512
#define GL_TEXTURE_CUBE_MAP_EXT 0x8513
#define GL_TEXTURE_BINDING_CUBE_MAP_EXT 0x8514
#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT 0x8515
@@ -81,7 +81,7 @@ static GLenum faceTarget[6] =
TextureCubeMap::TextureCubeMap()
{
_target = GL_TEXTURE_CUBE_MAP_ARB; // default to ARB extension
_target = GL_TEXTURE_CUBE_MAP; // default to ARB extension
}
@@ -145,6 +145,15 @@ void TextureCubeMap::setImage( const Face face, Image* image)
_images[face] = image;
}
Image* TextureCubeMap::getImage(const Face face)
{
return _images[face].get();
}
const Image* TextureCubeMap::getImage(const Face face) const
{
return _images[face].get();
}
bool TextureCubeMap::imagesValid() const
{

View File

@@ -40,6 +40,7 @@ C++FILES = \
TexGen.cpp\
TexMat.cpp\
Texture.cpp\
TextureCubeMap.cpp\
Transform.cpp\
Transparency.cpp\

View File

@@ -1,8 +1,10 @@
#include "osg/StateSet"
#include <osg/StateSet>
#include <osg/Texture>
#include <osg/TextureCubeMap>
#include "osgDB/Registry"
#include "osgDB/Input"
#include "osgDB/Output"
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
using namespace osg;
using namespace osgDB;
@@ -70,7 +72,12 @@ void initGLNames()
ADD_NAME("GL_POLYGON_OFFSET_LINE",GL_POLYGON_OFFSET_LINE)
ADD_NAME("GL_POLYGON_OFFSET_POINT",GL_POLYGON_OFFSET_POINT)
ADD_NAME("GL_TEXTURE_1D",GL_TEXTURE_1D)
ADD_NAME("GL_TEXTURE_2D",GL_TEXTURE_2D)
ADD_NAME("GL_TEXTURE_3D",GL_TEXTURE_3D)
ADD_NAME("GL_TEXTURE_CUBE_MAP",GL_TEXTURE_CUBE_MAP);
ADD_NAME("GL_TEXTURE_GEN_Q",GL_TEXTURE_GEN_Q)
ADD_NAME("GL_TEXTURE_GEN_R",GL_TEXTURE_GEN_R)
ADD_NAME("GL_TEXTURE_GEN_S",GL_TEXTURE_GEN_S)

View File

@@ -94,6 +94,8 @@ bool TexGen_matchModeStr(const char* str,TexGen::Mode& mode)
if (strcmp(str,"EYE_LINEAR")==0) mode = TexGen::EYE_LINEAR;
else if (strcmp(str,"OBJECT_LINEAR")==0) mode = TexGen::OBJECT_LINEAR;
else if (strcmp(str,"SPHERE_MAP")==0) mode = TexGen::SPHERE_MAP;
else if (strcmp(str,"NORMAL_MAP")==0) mode = TexGen::NORMAL_MAP;
else if (strcmp(str,"REFLECTION_MAP")==0) mode = TexGen::REFLECTION_MAP;
else return false;
return true;
}
@@ -106,6 +108,8 @@ const char* TexGen_getModeStr(TexGen::Mode mode)
case(TexGen::EYE_LINEAR): return "EYE_LINEAR";
case(TexGen::OBJECT_LINEAR): return "OBJECT_LINEAR";
case(TexGen::SPHERE_MAP): return "SPHERE_MAP";
case(TexGen::NORMAL_MAP): return "NORMAL_MAP";
case(TexGen::REFLECTION_MAP): return "REFLECTION_MAP";
}
return "";
}