From Mike Weiblen's osgGL2 node kit which support the latest OpenGL 2.0 extensions.

This commit is contained in:
Robert Osfield 2003-07-15 10:45:46 +00:00
parent b2e5e09c28
commit 77c0366cb2
16 changed files with 2374 additions and 4 deletions

View File

@ -14,6 +14,7 @@ SRC_DIRS = \
osgParticle\
osgText\
osgSim\
osgGL2\
osgProducer\
osgPlugins\
../examples
@ -127,13 +128,16 @@ EXAMPLE_DIRS = \
osgoccluder\
osgparticle\
osgpick\
osgprerender\
osgpoints\
osgprerender\
osgprerendercubemap\
osgreflect\
osgscribe\
osgsequence\
osgshaders\
osgshadowtexture\
osgshape\
osgslideshow\
osgstereoimage\
osgteapot\
osgtext\
@ -142,12 +146,10 @@ EXAMPLE_DIRS = \
osgtexture3D\
osgtexturerectangle\
osgunittests\
osgwindows\
osgversion\
osgvertexprogram\
osgviewer\
osgprerendercubemap\
osgslideshow\
osgwindows\
# osgpagedlod\
# osgsimulation\

View File

@ -861,6 +861,39 @@ Package=<4>
###############################################################################
Project: "Example osgshaders"=.\examples\osgshaders\osgshaders.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name Core osg
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgDB
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgGA
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgGL2
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgText
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgProducer
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgUtil
End Project Dependency
}}}
###############################################################################
Project: "Example osgshadowtexture"=.\examples\osgshadowtexture\osgshadowtexture.dsp - Package Owner=<4>
Package=<5>

View File

@ -0,0 +1,189 @@
# Microsoft Developer Studio Project File - Name="Example osgshaders" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=Example osgshaders - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "osgshaders.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "osgshaders.mak" CFG="Example osgshaders - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Example osgshaders - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "Example osgshaders - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "Example osgshaders - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 opengl32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../../../bin/osgshaders.exe" /libpath:"../../../lib"
!ELSEIF "$(CFG)" == "Example osgshaders - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MDd /W3 /Gm /vd0 /GR /GX /Zi /Od /I "../../../include" /D "_CONSOLE" /D "_MBCS" /D "FL_DLL" /D "WIN32" /D "_DEBUG" /FR /YX /FD /c
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 opengl32.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"libcmt" /out:"../../../bin/osgshadersd.exe" /pdbtype:sept /libpath:"../../../lib"
# SUBTRACT LINK32 /incremental:no
!ENDIF
# Begin Target
# Name "Example osgshaders - Win32 Release"
# Name "Example osgshaders - Win32 Debug"
# Begin Source File
SOURCE=..\..\..\examples\osgshaders\GL2Scene.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\examples\osgshaders\osgshaders.cpp
# End Source File
# End Target
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Project

View File

@ -0,0 +1,132 @@
# Microsoft Developer Studio Project File - Name="Core osgGL2" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=Core osgGL2 - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "osgGL2.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "osgGL2.mak" CFG="Core osgGL2 - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Core osgGL2 - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "Core osgGL2 - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "Core osgGL2 - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "../../lib"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "../../lib"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../include" /D "NDEBUG" /D "_MBCS" /D "_USRDLL" /D "osgGL2_LIBRARY" /D "WIN32" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
# ADD LINK32 glu32.lib opengl32.lib /nologo /dll /pdb:none /machine:I386 /out:"../../bin/osgGL2.dll" /libpath:"../../lib"
!ELSEIF "$(CFG)" == "Core osgGL2 - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "../../lib"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /vmg /vd0 /GR /GX /Zi /Od /I "../../include" /D "osgGL2_LIBRARY" /D "_WINDOWS" /D "WIN32" /D "_DEBUG" /YX /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 glu32.lib opengl32.lib /nologo /dll /debug /machine:I386 /out:"../../bin/osgGL2d.dll" /pdbtype:sept /libpath:"../../lib"
# SUBTRACT LINK32 /pdb:none
!ENDIF
# Begin Target
# Name "Core osgGL2 - Win32 Release"
# Name "Core osgGL2 - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=..\..\src\osgGL2\Extensions.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osgGL2\ProgramObject.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osgGL2\Version.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter ";h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=..\..\include\osgGL2\Export
# End Source File
# Begin Source File
SOURCE=..\..\include\osgGL2\Extensions
# End Source File
# Begin Source File
SOURCE=..\..\include\osgGL2\ProgramObject
# End Source File
# Begin Source File
SOURCE=..\..\include\osgGL2\Version
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@ -0,0 +1,174 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
* Copyright (C) 2003 3Dlabs Inc. Ltd.
*
* This application is open source and may be redistributed and/or modified
* freely and without restriction, both in commericial and non commericial applications,
* as long as this copyright notice is maintained.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/* file: examples/osgshaders/GL2Scene.cpp
* author: Mike Weiblen 2003-07-14
*
* Compose a scene of several instances of a model, with a different
* OpenGL Shading Language shader applied to each.
*
* See http://www.3dlabs.com/opengl2/ for more information regarding
* the OpenGL Shading Language.
*/
#include <osg/ShapeDrawable>
#include <osg/PositionAttitudeTransform>
#include <osg/Geode>
#include <osg/Notify>
#include <osgDB/ReadFile>
#include <osgDB/FileUtils>
#include <osgUtil/Optimizer>
#include <osgGL2/ProgramObject>
///////////////////////////////////////////////////////////////////////////
// OpenGL Shading Language source code for the "microshader" example.
static const char *microshaderVertSource = {
"varying vec3 color;"
"void main(void)"
"{"
"gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
"color = gl_Vertex.zyx * 1.0;"
"}"
};
static const char *microshaderFragSource = {
"varying vec3 color;"
"void main(void)"
"{"
"gl_FragColor = vec4(color, 1.0);"
"}"
};
///////////////////////////////////////////////////////////////////////////
static osg::Group* rootNode;
static osg::Node* masterModel;
// Add a reference to the masterModel at the specified translation, and
// return its StateSet so we can easily attach StateAttributes.
static osg::StateSet*
CloneMaster(float x, float y, float z )
{
osg::PositionAttitudeTransform* xform = new osg::PositionAttitudeTransform();
xform->setPosition(osg::Vec3(x, y, z));
xform->addChild(masterModel);
rootNode->addChild(xform);
return xform->getOrCreateStateSet();
}
// Create some geometry upon which to render GL2 shaders.
static osg::Geode*
CreateModel()
{
osg::Geode* geode = new osg::Geode();
geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),1.0f)));
geode->addDrawable(new osg::ShapeDrawable(new osg::Cone(osg::Vec3(2.2f,0.0f,-0.4f),0.9f,1.8f)));
geode->addDrawable(new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(4.4f,0.0f,0.0f),1.0f,1.4f)));
return geode;
}
// read vert & frag shader source code from a pair of files.
static void
LoadShaderSource( osgGL2::ProgramObject* progObj, std::string baseFileName )
{
std::string vertFileName = osgDB::findDataFile(baseFileName + ".vert");
if( vertFileName.length() != 0 )
{
osgGL2::ShaderObject* vertObj = new osgGL2::ShaderObject( osgGL2::ShaderObject::VERTEX );
vertObj->loadShaderSourceFromFile( vertFileName.c_str() );
progObj->addShader( vertObj );
}
else
{
osg::notify(osg::WARN) << "Warning: file \"" << baseFileName+".vert" << "\" not found." << std::endl;
}
std::string fragFileName = osgDB::findDataFile(baseFileName + ".frag");
if( fragFileName.length() != 0 )
{
osgGL2::ShaderObject* fragObj = new osgGL2::ShaderObject( osgGL2::ShaderObject::FRAGMENT );
fragObj->loadShaderSourceFromFile( fragFileName.c_str() );
progObj->addShader( fragObj );
}
else
{
osg::notify(osg::WARN) << "Warning: file \"" << baseFileName+".frag" << "\" not found." << std::endl;
}
}
///////////////////////////////////////////////////////////////////////////
// Compose a scenegraph with examples of GL2 shaders
#define ZGRID 2.2
osg::Node*
GL2Scene()
{
osg::StateSet* ss;
osgGL2::ProgramObject* progObj;
// the rootNode of our created graph.
rootNode = new osg::Group;
ss = rootNode->getOrCreateStateSet();
// attach an "empty" ProgramObject to the rootNode as a default
// StateAttribute. An empty ProgramObject (ie without any attached
// ShaderObjects) is a special case, which means to use the
// OpenGL 1.x "fixed functionality" rendering pipeline.
progObj = new osgGL2::ProgramObject;
ss->setAttributeAndModes(progObj, osg::StateAttribute::ON);
// put the unadorned masterModel at the origin for comparison.
masterModel = CreateModel();
rootNode->addChild(masterModel);
// add logo overlays
//rootNode->addChild( osgDB::readNodeFile( "3dl_ogl.logo" ) );
//
// create references to the masterModel and attach shaders
//
// apply the simple microshader example
// (the shader sources are hardcoded above in this .cpp file)
ss = CloneMaster(0,0,ZGRID*1);
progObj = new osgGL2::ProgramObject;
progObj->addShader( new osgGL2::ShaderObject( osgGL2::ShaderObject::VERTEX, microshaderVertSource ) );
progObj->addShader( new osgGL2::ShaderObject( osgGL2::ShaderObject::FRAGMENT, microshaderFragSource ) );
ss->setAttributeAndModes(progObj, osg::StateAttribute::ON);
// load the "specular brick" shader from a pair of source files.
ss = CloneMaster(0,0,ZGRID*2);
progObj = new osgGL2::ProgramObject;
LoadShaderSource( progObj, "shaders/brick" );
ss->setAttributeAndModes(progObj, osg::StateAttribute::ON);
// load the "gold screen" shader from a pair of source files.
ss = CloneMaster(0,0,ZGRID*3);
progObj = new osgGL2::ProgramObject;
LoadShaderSource( progObj, "shaders/screen" );
ss->setAttributeAndModes(progObj, osg::StateAttribute::ON);
return rootNode;
}
void
GL2Update()
{
/* TODO : update uniform values for shader animation */
}
/*EOF*/

View File

@ -0,0 +1,20 @@
TOPDIR = ../..
include $(TOPDIR)/Make/makedefs
CXXFILES =\
GL2Scene.cpp \
osgshaders.cpp
LIBS += -losgProducer -lProducer -losgText -losgGL2 -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
INSTFILES = \
$(CXXFILES)\
GNUmakefile.inst=GNUmakefile
EXEC = osgshaders
INC += $(PRODUCER_INCLUDE_DIR) -I/usr/X11R6/include
LDFLAGS += $(PRODUCER_LIB_DIR)
include $(TOPDIR)/Make/makerules

View File

@ -0,0 +1,15 @@
TOPDIR = ../..
include $(TOPDIR)/Make/makedefs
CXXFILES =\
GL2Scene.cpp \
osgshaders.cpp
LIBS += -losgProducer -lProducer -losgDB -losgText -losgGL2 -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
EXEC = osgshaders
INC += $(PRODUCER_INCLUDE_DIR) -I/usr/X11R6/include
LDFLAGS += $(PRODUCER_LIB_DIR)
include $(TOPDIR)/Make/makerules

View File

@ -0,0 +1,123 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
* Copyright (C) 2003 3Dlabs Inc. Ltd.
*
* This application is open source and may be redistributed and/or modified
* freely and without restriction, both in commericial and non commericial applications,
* as long as this copyright notice is maintained.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/* file: examples/osgshaders/osgshaders.cpp
* author: Mike Weiblen 2003-07-14
*
* A simple app skeleton for viewing OpenGL Shading Language shaders;
* derived from osgviewer.cpp from OSG 0.9.4-2
*
* See http://www.3dlabs.com/opengl2/ for more information regarding
* the OpenGL Shading Language.
*/
#include <osgDB/ReadFile>
#include <osgUtil/Optimizer>
#include <osgProducer/Viewer>
#define GL2SCENE
osg::Node* GL2Scene();
void GL2Update();
int main( int argc, char **argv )
{
// use an ArgumentParser object to manage the program arguments.
osg::ArgumentParser arguments(&argc,argv);
// set up the usage document, in case we need to print out how to use this program.
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models.");
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
// construct the viewer.
osgProducer::Viewer viewer(arguments);
// set up the value with sensible default event handlers.
viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
// get details on keyboard and mouse bindings used by the viewer.
viewer.getUsage(*arguments.getApplicationUsage());
// if user request help write it out to cout.
if (arguments.read("-h") || arguments.read("--help"))
{
arguments.getApplicationUsage()->write(std::cout);
return 1;
}
// any option left unread are converted into errors to write out later.
arguments.reportRemainingOptionsAsUnrecognized();
// report any errors if they have occured when parsing the program aguments.
if (arguments.errors())
{
arguments.writeErrorMessages(std::cout);
return 1;
}
#ifdef GL2SCENE //(
osg::ref_ptr<osg::Node> loadedModel = GL2Scene();
#else //)(
if (arguments.argc()<=1)
{
arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
return 1;
}
// read the scene from the list of file specified commandline args.
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
// if no model has been successfully loaded report failure.
if (!loadedModel)
{
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
return 1;
}
// optimize the scene graph, remove rendundent nodes and state etc.
osgUtil::Optimizer optimizer;
optimizer.optimize(loadedModel.get());
#endif //)
// set the scene to render
viewer.setSceneData(loadedModel.get());
// create the windows and run the threads.
viewer.realize();
while( !viewer.done() )
{
// wait for all cull and draw threads to complete.
viewer.sync();
// update the scene by traversing it with the the update visitor which will
// call all node update callbacks and animations.
viewer.update();
#ifdef GL2SCENE //(
GL2Update();
#endif //)
// fire off the cull and draw traversals of the scene.
viewer.frame();
}
// wait for all cull and draw threads to complete before exit.
viewer.sync();
return 0;
}

47
include/osgGL2/Export Normal file
View File

@ -0,0 +1,47 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGGL2_EXPORT_
#define OSGGL2_EXPORT_ 1
#if defined(WIN32) && !(defined(__CYGWIN__) || defined(__MINGW32__))
#pragma warning( disable : 4244 )
#pragma warning( disable : 4251 )
#pragma warning( disable : 4275 )
#pragma warning( disable : 4786 )
#pragma warning( disable : 4290 )
#pragma warning( disable : 4305 )
#endif
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
# ifdef OSGGL2_LIBRARY
# define OSGGL2_EXPORT __declspec(dllexport)
# else
# define OSGGL2_EXPORT __declspec(dllimport)
# endif
#else
# define OSGGL2_EXPORT
#endif
/* Define NULL pointer value */
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif
#endif /* OSGGL2_EXPORT_ */

231
include/osgGL2/Extensions Normal file
View File

@ -0,0 +1,231 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
* Copyright (C) 2003 3Dlabs Inc. Ltd.
*
* This application is open source and may be redistributed and/or modified
* freely and without restriction, both in commericial and non commericial
* applications, as long as this copyright notice is maintained.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/* file: include/osgGL2/Extensions
* author: Mike Weiblen 2003-07-14
*
* See http://www.3dlabs.com/opengl2/ for more information regarding
* the OpenGL Shading Language.
*/
#ifndef OSGGL2_EXTENSIONS
#define OSGGL2_EXTENSIONS 1
#include <osg/Referenced>
#include <osg/GL>
#include <osgGL2/Export>
// If not defined by gl.h use the definitions found in the
// arb_shader_objects, arb_vertex_shader, and arb_fragment_shader
// specificiations.
#if !defined(GL_ARB_vertex_shader) && !defined(GL_ARB_fragment_shader) && !defined(GL_ARB_shader_objects) //(
typedef int GLhandleARB;
typedef char GLcharARB;
#define GL_PROGRAM_OBJECT_ARB 0x8B40
#define GL_OBJECT_TYPE_ARB 0x8B4E
#define GL_OBJECT_SUBTYPE_ARB 0x8B4F
#define GL_SHADER_OBJECT_ARB 0x8B48
#define GL_FLOAT_VEC2_ARB 0x8B50
#define GL_FLOAT_VEC3_ARB 0x8B51
#define GL_FLOAT_VEC4_ARB 0x8B52
#define GL_INT_VEC2_ARB 0x8B53
#define GL_INT_VEC3_ARB 0x8B54
#define GL_INT_VEC4_ARB 0x8B55
#define GL_BOOL_ARB 0x8B56
#define GL_BOOL_VEC2_ARB 0x8B57
#define GL_BOOL_VEC3_ARB 0x8B58
#define GL_BOOL_VEC4_ARB 0x8B59
#define GL_FLOAT_MAT2_ARB 0x8B5A
#define GL_FLOAT_MAT3_ARB 0x8B5B
#define GL_FLOAT_MAT4_ARB 0x8B5C
#define GL_VERTEX_SHADER_ARB 0x8B31
#define GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB 0x8B4A
#define GL_MAX_VERTEX_ATTRIBS_ARB 0x8869
#define GL_MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872
#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB 0x8B4C
#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB 0x8B4D
#define GL_MAX_TEXTURE_COORDS_ARB 0x8871
#define GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB 0x8622
#define GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB 0x8623
#define GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB 0x8624
#define GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB 0x8625
#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB 0x886A
#define GL_CURRENT_VERTEX_ATTRIB_ARB 0x8626
#define GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB 0x8645
#define GL_FRAGMENT_SHADER_ARB 0x8B30
#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB 0x8B49
#define GL_MAX_VARYING_FLOATS_ARB 0x8B4B
#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642
#define GL_VERTEX_PROGRAM_TWO_SIDE_ARB 0x8643
#define GL_OBJECT_DELETE_STATUS_ARB 0x8B80
#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81
#define GL_OBJECT_LINK_STATUS_ARB 0x8B82
#define GL_OBJECT_VALIDATE_STATUS_ARB 0x8B83
#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84
#define GL_OBJECT_ATTACHED_OBJECTS_ARB 0x8B85
#define GL_OBJECT_ACTIVE_UNIFORMS_ARB 0x8B86
#define GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB 0x8B87
#define GL_OBJECT_SHADER_SOURCE_LENGTH_ARB 0x8B88
#define GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB 0x8B8A
#define GL_OBJECT_ACTIVE_ATTRIBUTES_ARB 0x8B89
#endif //)
namespace osgGL2 {
/** Extensions class which encapsulates the querying of extensions and
* associated function pointers, and provide convenience wrappers to
* check for the extensions or use the associated functions.*/
class OSGGL2_EXPORT Extensions : public osg::Referenced
{
public:
Extensions();
Extensions(const Extensions& rhs);
void lowestCommonDenominator(const Extensions& rhs);
void setupGLExtensions();
void setShaderObjectsSupported(bool flag) { _isShaderObjectsSupported = flag; }
bool isShaderObjectsSupported() const { return _isShaderObjectsSupported; }
void setVertexShaderSupported(bool flag) { _isVertexShaderSupported = flag; }
bool isVertexShaderSupported() const { return _isVertexShaderSupported; }
void setFragmentShaderSupported(bool flag) { _isFragmentShaderSupported = flag; }
bool isFragmentShaderSupported() const { return _isFragmentShaderSupported; }
/** Function to call to get the extension of a specified context.
* If the Exentsion object for that context has not yet been created then
* and the 'createIfNotInitalized' flag been set to false then returns NULL.
* If 'createIfNotInitalized' is true then the Extensions object is
* automatically created. However, in this case the extension object
* only be created with the graphics context associated with ContextID..*/
static Extensions* Get(unsigned int contextID,bool createIfNotInitalized);
/** allows users to override the extensions across graphics contexts.
* typically used when you have different extensions supported across graphics pipes
* but need to ensure that they all use the same low common denominator extensions.*/
static void Set(unsigned int contextID,Extensions* extensions);
GLhandleARB glCreateShaderObject(GLenum shaderType) const;
GLhandleARB glCreateProgramObject() const;
void glDeleteObject(GLhandleARB obj) const;
void glAttachObject(GLhandleARB containerObj, GLhandleARB obj) const;
void glDetachObject(GLhandleARB containerObj, GLhandleARB attachedObj) const;
void glShaderSource(GLhandleARB shaderObj, GLsizei count, const GLcharARB **strings, const GLint *length) const;
void glCompileShader(GLhandleARB shaderObj) const;
void glBindAttribLocation(GLhandleARB programObj, GLuint index, const GLcharARB *name) const;
void glLinkProgram(GLhandleARB programObj) const;
void glUseProgramObject(GLhandleARB programObj) const;
void glGetInfoLog(GLhandleARB obj,GLsizei maxLength, GLsizei *length, GLcharARB *infoLog) const;
void glGetAttachedObjects(GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj) const;
void glGetShaderSource(GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source) const;
void glUniform1f(GLint location, GLfloat v0) const;
void glUniform2f(GLint location, GLfloat v0, GLfloat v1) const;
void glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) const;
void glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) const;
void glUniform1i(GLint location, GLint v0) const;
void glUniform2i(GLint location, GLint v0, GLint v1) const;
void glUniform3i(GLint location, GLint v0, GLint v1, GLint v2) const;
void glUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) const;
void glUniform1fv(GLint location, GLsizei count, GLfloat *value) const;
void glUniform2fv(GLint location, GLsizei count, GLfloat *value) const;
void glUniform3fv(GLint location, GLsizei count, GLfloat *value) const;
void glUniform4fv(GLint location, GLsizei count, GLfloat *value) const;
void glUniform1iv(GLint location, GLsizei count, GLint *value) const;
void glUniform2iv(GLint location, GLsizei count, GLint *value) const;
void glUniform3iv(GLint location, GLsizei count, GLint *value) const;
void glUniform4iv(GLint location, GLsizei count, GLint *value) const;
void glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, GLfloat *value) const;
void glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, GLfloat *value) const;
void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, GLfloat *value) const;
GLint glGetUniformLocation(GLhandleARB programObject, const GLcharARB *name) const;
GLint glGetAttribLocation(GLhandleARB programObj, const GLcharARB *name) const;
void glGetActiveUniform(GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLint *type, GLcharARB *name) const;
void glGetActiveAttribs(GLhandleARB programObj, GLint *count, const GLint **size, const GLenum **type, const GLcharARB* const **attributes) const;
void glGetUniformfv(GLhandleARB programObj, GLint location, GLfloat *params) const;
void glGetUniformiv(GLhandleARB programObj, GLint location, GLint *params) const;
void glGetObjectParameterfv(GLhandleARB obj, GLenum pname, GLfloat *params) const;
void glGetObjectParameteriv(GLhandleARB obj, GLenum pname, GLint *params) const;
GLhandleARB glGetHandle(GLenum pname) const;
protected:
~Extensions() {}
bool _isShaderObjectsSupported;
bool _isVertexShaderSupported;
bool _isFragmentShaderSupported;
void* _glCreateShaderObject;
void* _glCreateProgramObject;
void* _glDeleteObject;
void* _glAttachObject;
void* _glDetachObject;
void* _glShaderSource;
void* _glCompileShader;
void* _glBindAttribLocation;
void* _glLinkProgram;
void* _glUseProgramObject;
void* _glGetInfoLog;
void* _glGetAttachedObjects;
void* _glGetShaderSource;
void* _glUniform1f;
void* _glUniform2f;
void* _glUniform3f;
void* _glUniform4f;
void* _glUniform1i;
void* _glUniform2i;
void* _glUniform3i;
void* _glUniform4i;
void* _glUniform1fv;
void* _glUniform2fv;
void* _glUniform3fv;
void* _glUniform4fv;
void* _glUniform1iv;
void* _glUniform2iv;
void* _glUniform3iv;
void* _glUniform4iv;
void* _glUniformMatrix2fv;
void* _glUniformMatrix3fv;
void* _glUniformMatrix4fv;
void* _glGetUniformLocation;
void* _glGetAttribLocation;
void* _glGetActiveUniform;
void* _glGetActiveAttribs;
void* _glGetUniformfv;
void* _glGetUniformiv;
void* _glGetObjectParameterfv;
void* _glGetObjectParameteriv;
void* _glGetHandle;
};
}
#endif

View File

@ -0,0 +1,214 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
* Copyright (C) 2003 3Dlabs Inc. Ltd.
*
* This application is open source and may be redistributed and/or modified
* freely and without restriction, both in commericial and non commericial
* applications, as long as this copyright notice is maintained.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/* file: include/osgGL2/ProgramObject
* author: Mike Weiblen 2003-07-14
*
* See http://www.3dlabs.com/opengl2/ for more information regarding
* the OpenGL Shading Language.
*/
#ifndef OSGGL2_PROGRAMOBJECT
#define OSGGL2_PROGRAMOBJECT 1
#include <osg/State>
#include <osg/StateAttribute>
#include <osg/buffered_value>
#include <osg/ref_ptr>
#include <osgGL2/Export>
#include <osgGL2/Extensions>
#include <string>
// TODO This type enum must be officially added to osg::StateAttribute::Types
#define PROGRAMOBJECT (osg::StateAttribute::VERTEXPROGRAM + 1)
namespace osgGL2 {
/** use deleteObject instead of glDeleteObject to allow
* GL2 Objects to cached until they can be deleted
* by the OpenGL context in which they were created, specified
* by contextID.*/
void DeleteObject(unsigned int contextID, GLhandleARB handle);
/** flush all the cached glProgramObjects which need to be deleted
* in the OpenGL context related to contextID.*/
void FlushDeletedGL2Objects(unsigned int contextID);
///////////////////////////////////////////////////////////////////////////
class ShaderObject;
/** Encapsulates the OpenGL Shading Language ProgramObject */
class OSGGL2_EXPORT ProgramObject : public osg::StateAttribute
{
public:
ProgramObject();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
ProgramObject(const ProgramObject& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_StateAttribute(osgGL2, ProgramObject, PROGRAMOBJECT);
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
virtual int compare(const osg::StateAttribute& sa) const
{
// check the types are equal and then create the rhs variable
// used by the COMPARE_StateAttribute_Paramter macro's below.
COMPARE_StateAttribute_Types(ProgramObject,sa)
// compare each parameter in turn against the rhs.
COMPARE_StateAttribute_Parameter(_shaderObjectList);
// COMPARE_StateAttribute_Parameter(_pcpoList);
return 0; // passed all the above comparison macro's, must be equal.
}
virtual void getAssociatedModes(std::vector<GLMode>& ) const {}
virtual void apply(osg::State& state) const;
virtual void compile(osg::State& state) const { apply(state); }
// data access methods.
/** Force a relink on next apply() of associated glProgramObject. */
void dirtyProgramObject();
void addShader( ShaderObject* shader );
protected:
virtual ~ProgramObject();
typedef std::vector< osg::ref_ptr<ShaderObject> > ShaderObjectList;
ShaderObjectList _shaderObjectList;
class OSGGL2_EXPORT PerContextProgObj : public osg::Referenced
{
public:
PerContextProgObj(const ProgramObject* parent, Extensions* extensions);
PerContextProgObj(const PerContextProgObj& rhs);
GLhandleARB& getHandle() {return _handle;}
bool isDirty() const {return _dirty;}
void markAsDirty() {_dirty = true; }
void markAsClean() {_dirty = false;}
bool build() const;
void use() const;
void markAsAttached() {_unattached = false;}
bool isUnattached() const {return _unattached;}
protected:
PerContextProgObj() {};
~PerContextProgObj();
const ProgramObject* _parent;
osg::ref_ptr<Extensions> _extensions;
GLhandleARB _handle;
bool _dirty;
bool _unattached;
};
typedef osg::buffered_value< osg::ref_ptr<PerContextProgObj> > PCPOList;
mutable PCPOList _pcpoList;
PerContextProgObj* getPCPO(unsigned int contextID) const;
};
///////////////////////////////////////////////////////////////////////////
/** Encapsulates the OpenGL Shading Language ShaderObject */
class OSGGL2_EXPORT ShaderObject : public osg::Object
{
public:
enum Type {
VERTEX = GL_VERTEX_SHADER_ARB,
FRAGMENT = GL_FRAGMENT_SHADER_ARB,
UNKNOWN = -1
};
ShaderObject();
ShaderObject(Type type);
ShaderObject(Type type, const char* sourceText);
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
ShaderObject(const ShaderObject& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgGL2, ShaderObject);
// data access methods.
void setShaderSource( const char* sourceText );
inline const std::string& getShaderSource() const {return _shaderSource; }
bool loadShaderSourceFromFile( const char* fileName );
Type getType() const { return _type; }
/** Force a recompile on next apply() of associated glShaderObject. */
void dirtyShaderObject();
bool build(unsigned int contextID) const;
void attach(unsigned int contextID, GLhandleARB progObj) const;
protected:
virtual ~ShaderObject();
std::string _shaderSource;
Type _type;
class OSGGL2_EXPORT PerContextShaderObj : public osg::Referenced
{
public:
PerContextShaderObj(const ShaderObject* parent, Extensions* extensions);
PerContextShaderObj(const PerContextShaderObj& rhs);
GLhandleARB& getHandle() {return _handle;}
bool isDirty() const {return _dirty;}
void markAsDirty() {_dirty = true; }
void markAsClean() {_dirty = false;}
bool build();
void attach(GLhandleARB progObj);
protected:
PerContextShaderObj() {};
~PerContextShaderObj();
const ShaderObject* _parent;
osg::ref_ptr<Extensions> _extensions;
GLhandleARB _handle;
bool _dirty;
};
typedef osg::buffered_value< osg::ref_ptr<PerContextShaderObj> > PCSOList;
mutable PCSOList _pcsoList;
PerContextShaderObj* getPCSO(unsigned int contextID) const;
};
}
#endif

49
include/osgGL2/Version Normal file
View File

@ -0,0 +1,49 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGGL2_VERSION
#define OSGGL2_VERSION 1
#include <osgGL2/Export>
extern "C" {
/*
* osgGL2GetVersion() returns the library version number.
* Numbering convention : OpenSceneGraph-GL2-0.1 will return 0.1 from osgGL2getVersion.
*
* This C function can be also used to check for the existence of the OpenSceneGraph
* library using autoconf and its m4 macro AC_CHECK_LIB.
*
* Here is the code to add to your configure.in:
\verbatim
#
# Check for the OpenSceneGraph-GL2 library
#
AC_CHECK_LIB(osg, osgGL2GetVersion, ,
[AC_MSG_ERROR(OpenSceneGraph library not found. See http://www.openscenegraph.org)],)
\endverbatim
*/
extern OSGGL2_EXPORT const char* osgGL2GetVersion();
/*
* osgGL2GetLibraryName() returns the library name in human friendly form.
*/
extern OSGGL2_EXPORT const char* osgGL2GetLibraryName();
}
#endif

743
src/osgGL2/Extensions.cpp Normal file
View File

@ -0,0 +1,743 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
* Copyright (C) 2003 3Dlabs Inc. Ltd.
*
* This application is open source and may be redistributed and/or modified
* freely and without restriction, both in commericial and non commericial
* applications, as long as this copyright notice is maintained.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/* file: src/osgGL2/Extensions.cpp
* author: Mike Weiblen 2003-07-14
*
* See http://www.3dlabs.com/opengl2/ for more information regarding
* the OpenGL Shading Language.
*/
#include <osg/Notify>
#include <osg/GLExtensions>
#include <osg/buffered_value>
#include <osg/ref_ptr>
#include <osgGL2/Extensions>
using namespace osgGL2;
Extensions::Extensions()
{
setupGLExtensions();
}
Extensions::Extensions(const Extensions& rhs) : Referenced()
{
_isShaderObjectsSupported = rhs._isShaderObjectsSupported;
_isVertexShaderSupported = rhs._isVertexShaderSupported;
_isFragmentShaderSupported = rhs._isFragmentShaderSupported;
_glCreateShaderObject = rhs._glCreateShaderObject;
_glCreateProgramObject = rhs._glCreateProgramObject;
_glDeleteObject = rhs._glDeleteObject;
_glAttachObject = rhs._glAttachObject;
_glDetachObject = rhs._glDetachObject;
_glShaderSource = rhs._glShaderSource;
_glCompileShader = rhs._glCompileShader;
_glBindAttribLocation = rhs._glBindAttribLocation;
_glLinkProgram = rhs._glLinkProgram;
_glUseProgramObject = rhs._glUseProgramObject;
_glGetInfoLog = rhs._glGetInfoLog;
_glGetAttachedObjects = rhs._glGetAttachedObjects;
_glGetShaderSource = rhs._glGetShaderSource;
_glUniform1f = rhs._glUniform1f;
_glUniform2f = rhs._glUniform2f;
_glUniform3f = rhs._glUniform3f;
_glUniform4f = rhs._glUniform4f;
_glUniform1i = rhs._glUniform1i;
_glUniform2i = rhs._glUniform2i;
_glUniform3i = rhs._glUniform3i;
_glUniform4i = rhs._glUniform4i;
_glUniform1fv = rhs._glUniform1fv;
_glUniform2fv = rhs._glUniform2fv;
_glUniform3fv = rhs._glUniform3fv;
_glUniform4fv = rhs._glUniform4fv;
_glUniform1iv = rhs._glUniform1iv;
_glUniform2iv = rhs._glUniform2iv;
_glUniform3iv = rhs._glUniform3iv;
_glUniform4iv = rhs._glUniform4iv;
_glUniformMatrix2fv = rhs._glUniformMatrix2fv;
_glUniformMatrix3fv = rhs._glUniformMatrix3fv;
_glUniformMatrix4fv = rhs._glUniformMatrix4fv;
_glGetUniformLocation = rhs._glGetUniformLocation;
_glGetAttribLocation = rhs._glGetAttribLocation;
_glGetActiveUniform = rhs._glGetActiveUniform;
_glGetActiveAttribs = rhs._glGetActiveAttribs;
_glGetUniformfv = rhs._glGetUniformfv;
_glGetUniformiv = rhs._glGetUniformiv;
_glGetObjectParameterfv = rhs._glGetObjectParameterfv;
_glGetObjectParameteriv = rhs._glGetObjectParameteriv;
_glGetHandle = rhs._glGetHandle;
}
void Extensions::lowestCommonDenominator(const Extensions& rhs)
{
if (!rhs._isShaderObjectsSupported) _isShaderObjectsSupported = false;
if (!rhs._isVertexShaderSupported) _isVertexShaderSupported = false;
if (!rhs._isFragmentShaderSupported) _isFragmentShaderSupported = false;
if (!rhs._glCreateShaderObject) _glCreateShaderObject = 0;
if (!rhs._glCreateProgramObject) _glCreateProgramObject = 0;
if (!rhs._glDeleteObject) _glDeleteObject = 0;
if (!rhs._glAttachObject) _glAttachObject = 0;
if (!rhs._glDetachObject) _glDetachObject = 0;
if (!rhs._glShaderSource) _glShaderSource = 0;
if (!rhs._glCompileShader) _glCompileShader = 0;
if (!rhs._glBindAttribLocation) _glBindAttribLocation = 0;
if (!rhs._glLinkProgram) _glLinkProgram = 0;
if (!rhs._glUseProgramObject) _glUseProgramObject = 0;
if (!rhs._glGetInfoLog) _glGetInfoLog = 0;
if (!rhs._glGetAttachedObjects) _glGetAttachedObjects = 0;
if (!rhs._glGetShaderSource) _glGetShaderSource = 0;
if (!rhs._glUniform1f) _glUniform1f = 0;
if (!rhs._glUniform2f) _glUniform2f = 0;
if (!rhs._glUniform3f) _glUniform3f = 0;
if (!rhs._glUniform4f) _glUniform4f = 0;
if (!rhs._glUniform1i) _glUniform1i = 0;
if (!rhs._glUniform2i) _glUniform2i = 0;
if (!rhs._glUniform3i) _glUniform3i = 0;
if (!rhs._glUniform4i) _glUniform4i = 0;
if (!rhs._glUniform1fv) _glUniform1fv = 0;
if (!rhs._glUniform2fv) _glUniform2fv = 0;
if (!rhs._glUniform3fv) _glUniform3fv = 0;
if (!rhs._glUniform4fv) _glUniform4fv = 0;
if (!rhs._glUniform1iv) _glUniform1iv = 0;
if (!rhs._glUniform2iv) _glUniform2iv = 0;
if (!rhs._glUniform3iv) _glUniform3iv = 0;
if (!rhs._glUniform4iv) _glUniform4iv = 0;
if (!rhs._glUniformMatrix2fv) _glUniformMatrix2fv = 0;
if (!rhs._glUniformMatrix3fv) _glUniformMatrix3fv = 0;
if (!rhs._glUniformMatrix4fv) _glUniformMatrix4fv = 0;
if (!rhs._glGetUniformLocation) _glGetUniformLocation = 0;
if (!rhs._glGetAttribLocation) _glGetAttribLocation = 0;
if (!rhs._glGetActiveUniform) _glGetActiveUniform = 0;
if (!rhs._glGetActiveAttribs) _glGetActiveAttribs = 0;
if (!rhs._glGetUniformfv) _glGetUniformfv = 0;
if (!rhs._glGetUniformiv) _glGetUniformiv = 0;
if (!rhs._glGetObjectParameterfv) _glGetObjectParameterfv = 0;
if (!rhs._glGetObjectParameteriv) _glGetObjectParameteriv = 0;
if (!rhs._glGetHandle) _glGetHandle = 0;
}
void Extensions::setupGLExtensions()
{
_isShaderObjectsSupported = osg::isGLExtensionSupported("GL_ARB_shader_objects");
_isVertexShaderSupported = osg::isGLExtensionSupported("GL_ARB_vertex_shader");
_isFragmentShaderSupported = osg::isGLExtensionSupported("GL_ARB_fragment_shader");
_glCreateShaderObject = osg::getGLExtensionFuncPtr("glCreateShaderObjectARB");
_glCreateProgramObject = osg::getGLExtensionFuncPtr("glCreateProgramObjectARB");
_glDeleteObject = osg::getGLExtensionFuncPtr("glDeleteObjectARB");
_glAttachObject = osg::getGLExtensionFuncPtr("glAttachObjectARB");
_glDetachObject = osg::getGLExtensionFuncPtr("glDetachObjectARB");
_glShaderSource = osg::getGLExtensionFuncPtr("glShaderSourceARB");
_glCompileShader = osg::getGLExtensionFuncPtr("glCompileShaderARB");
_glBindAttribLocation = osg::getGLExtensionFuncPtr("glBindAttribLocationARB");
_glLinkProgram = osg::getGLExtensionFuncPtr("glLinkProgramARB");
_glUseProgramObject = osg::getGLExtensionFuncPtr("glUseProgramObjectARB");
_glGetInfoLog = osg::getGLExtensionFuncPtr("glGetInfoLogARB");
_glGetAttachedObjects = osg::getGLExtensionFuncPtr("glGetAttachedObjectsARB");
_glGetShaderSource = osg::getGLExtensionFuncPtr("glGetShaderSourceARB");
_glUniform1f = osg::getGLExtensionFuncPtr("glUniform1fARB");
_glUniform2f = osg::getGLExtensionFuncPtr("glUniform2fARB");
_glUniform3f = osg::getGLExtensionFuncPtr("glUniform3fARB");
_glUniform4f = osg::getGLExtensionFuncPtr("glUniform4fARB");
_glUniform1i = osg::getGLExtensionFuncPtr("glUniform1iARB");
_glUniform2i = osg::getGLExtensionFuncPtr("glUniform2iARB");
_glUniform3i = osg::getGLExtensionFuncPtr("glUniform3iARB");
_glUniform4i = osg::getGLExtensionFuncPtr("glUniform4iARB");
_glUniform1fv = osg::getGLExtensionFuncPtr("glUniform1fvARB");
_glUniform2fv = osg::getGLExtensionFuncPtr("glUniform2fvARB");
_glUniform3fv = osg::getGLExtensionFuncPtr("glUniform3fvARB");
_glUniform4fv = osg::getGLExtensionFuncPtr("glUniform4fvARB");
_glUniform1iv = osg::getGLExtensionFuncPtr("glUniform1ivARB");
_glUniform2iv = osg::getGLExtensionFuncPtr("glUniform2ivARB");
_glUniform3iv = osg::getGLExtensionFuncPtr("glUniform3ivARB");
_glUniform4iv = osg::getGLExtensionFuncPtr("glUniform4ivARB");
_glUniformMatrix2fv = osg::getGLExtensionFuncPtr("glUniformMatrix2fvARB");
_glUniformMatrix3fv = osg::getGLExtensionFuncPtr("glUniformMatrix3fvARB");
_glUniformMatrix4fv = osg::getGLExtensionFuncPtr("glUniformMatrix4fvARB");
_glGetUniformLocation = osg::getGLExtensionFuncPtr("glGetUniformLocationARB");
_glGetAttribLocation = osg::getGLExtensionFuncPtr("glGetAttribLocationARB");
_glGetActiveUniform = osg::getGLExtensionFuncPtr("glGetActiveUniformARB");
_glGetActiveAttribs = osg::getGLExtensionFuncPtr("glGetActiveAttribsARB");
_glGetUniformfv = osg::getGLExtensionFuncPtr("glGetUniformfvARB");
_glGetUniformiv = osg::getGLExtensionFuncPtr("glGetUniformivARB");
_glGetObjectParameterfv = osg::getGLExtensionFuncPtr("glGetObjectParameterfvARB");
_glGetObjectParameteriv = osg::getGLExtensionFuncPtr("glGetObjectParameterivARB");
_glGetHandle = osg::getGLExtensionFuncPtr("glGetHandleARB");
}
/***************************************************************************/
// Static array of per-context osgGL2::Extensions instances
typedef osg::buffered_value< osg::ref_ptr<Extensions> > BufferedExtensions;
static BufferedExtensions s_extensions;
Extensions* Extensions::Get(unsigned int contextID, bool createIfNotInitalized)
{
if (!s_extensions[contextID] && createIfNotInitalized)
s_extensions[contextID] = new Extensions;
return s_extensions[contextID].get();
}
void Extensions::Set(unsigned int contextID, Extensions* extensions)
{
s_extensions[contextID] = extensions;
}
/***************************************************************************/
GLhandleARB Extensions::glCreateShaderObject(GLenum shaderType) const
{
if (_glCreateShaderObject)
{
typedef GLhandleARB (APIENTRY * CreateShaderObjectProc) (GLenum shaderType);
return ((CreateShaderObjectProc)_glCreateShaderObject)(shaderType);
}
else
{
osg::notify(osg::WARN)<<"Error: glCreateShaderObject not supported by OpenGL driver"<<std::endl;
return -1; //TODO
}
}
GLhandleARB Extensions::glCreateProgramObject() const
{
if (_glCreateProgramObject)
{
typedef GLhandleARB (APIENTRY * CreateProgramObjectProc) ();
return ((CreateProgramObjectProc)_glCreateProgramObject)();
}
else
{
osg::notify(osg::WARN)<<"Error: glCreateProgramObject not supported by OpenGL driver"<<std::endl;
return -1; //TODO
}
}
void Extensions::glDeleteObject(GLhandleARB obj) const
{
if (_glDeleteObject)
{
typedef void (APIENTRY * DeleteObjectProc) (GLhandleARB obj);
((DeleteObjectProc)_glDeleteObject)(obj);
}
else
{
osg::notify(osg::WARN)<<"Error: glDeleteObject not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glAttachObject(GLhandleARB containerObj, GLhandleARB obj) const
{
if (_glAttachObject)
{
typedef void (APIENTRY * AttachObjectProc) (GLhandleARB containerObj, GLhandleARB obj);
((AttachObjectProc)_glAttachObject)(containerObj, obj);
}
else
{
osg::notify(osg::WARN)<<"Error: glAttachObject not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glDetachObject(GLhandleARB containerObj, GLhandleARB attachedObj) const
{
if (_glDetachObject)
{
typedef void (APIENTRY * DetachObjectProc) (GLhandleARB containerObj, GLhandleARB attachedObj);
((DetachObjectProc)_glDetachObject)(containerObj, attachedObj);
}
else
{
osg::notify(osg::WARN)<<"Error: glDetachObject not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glShaderSource(GLhandleARB shaderObj, GLsizei count, const GLcharARB **strings, const GLint *length) const
{
if (_glShaderSource)
{
typedef void (APIENTRY * ShaderSourceProc) (GLhandleARB shaderObj, GLsizei count, const GLcharARB **strings, const GLint *length);
((ShaderSourceProc)_glShaderSource)(shaderObj, count, strings, length);
}
else
{
osg::notify(osg::WARN)<<"Error: glShaderSource not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glCompileShader(GLhandleARB shaderObj) const
{
if (_glCompileShader)
{
typedef void (APIENTRY * CompileShaderProc) (GLhandleARB shaderObj);
((CompileShaderProc)_glCompileShader)(shaderObj);
}
else
{
osg::notify(osg::WARN)<<"Error: glCompileShader not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glBindAttribLocation(GLhandleARB programObj, GLuint index, const GLcharARB *name) const
{
if (_glBindAttribLocation)
{
typedef void (APIENTRY * BindAttribLocationProc) (GLhandleARB programObj, GLuint index, const GLcharARB *name);
((BindAttribLocationProc)_glBindAttribLocation)(programObj, index, name);
}
else
{
osg::notify(osg::WARN)<<"Error: glBindAttribLocation not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glLinkProgram(GLhandleARB programObj) const
{
if (_glLinkProgram)
{
typedef void (APIENTRY * LinkProgramProc) (GLhandleARB programObj);
((LinkProgramProc)_glLinkProgram)(programObj);
}
else
{
osg::notify(osg::WARN)<<"Error: glLinkProgram not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUseProgramObject(GLhandleARB programObj) const
{
if (_glUseProgramObject)
{
typedef void (APIENTRY * UseProgramObjectProc) (GLhandleARB programObj);
((UseProgramObjectProc)_glUseProgramObject)(programObj);
}
else
{
osg::notify(osg::WARN)<<"Error: glUseProgramObject not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glGetInfoLog(GLhandleARB obj,GLsizei maxLength, GLsizei *length, GLcharARB *infoLog) const
{
if (_glGetInfoLog)
{
typedef void (APIENTRY * GetInfoLogProc) (GLhandleARB obj,GLsizei maxLength, GLsizei *length, GLcharARB *infoLog);
((GetInfoLogProc)_glGetInfoLog)(obj,maxLength, length, infoLog);
}
else
{
osg::notify(osg::WARN)<<"Error: glGetInfoLog not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glGetAttachedObjects(GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj) const
{
if (_glGetAttachedObjects)
{
typedef void (APIENTRY * GetAttachedObjectsProc) (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj);
((GetAttachedObjectsProc)_glGetAttachedObjects)(containerObj, maxCount, count, obj);
}
else
{
osg::notify(osg::WARN)<<"Error: glGetAttachedObjects not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glGetShaderSource(GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source) const
{
if (_glGetShaderSource)
{
typedef void (APIENTRY * GetShaderSourceProc) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source);
((GetShaderSourceProc)_glGetShaderSource)(obj, maxLength, length, source);
}
else
{
osg::notify(osg::WARN)<<"Error: glGetShaderSource not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniform1f(GLint location, GLfloat v0) const
{
if (_glUniform1f)
{
typedef void (APIENTRY * Uniform1fProc) (GLint location, GLfloat v0);
((Uniform1fProc)_glUniform1f)(location, v0);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniform1f not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniform2f(GLint location, GLfloat v0, GLfloat v1) const
{
if (_glUniform2f)
{
typedef void (APIENTRY * Uniform2fProc) (GLint location, GLfloat v0, GLfloat v1);
((Uniform2fProc)_glUniform2f)(location, v0, v1);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniform2f not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) const
{
if (_glUniform3f)
{
typedef void (APIENTRY * Uniform3fProc) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
((Uniform3fProc)_glUniform3f)(location, v0, v1, v2);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniform3f not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) const
{
if (_glUniform4f)
{
typedef void (APIENTRY * Uniform4fProc) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
((Uniform4fProc)_glUniform4f)(location, v0, v1, v2, v3);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniform4f not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniform1i(GLint location, GLint v0) const
{
if (_glUniform1i)
{
typedef void (APIENTRY * Uniform1iProc) (GLint location, GLint v0);
((Uniform1iProc)_glUniform1i)(location, v0);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniform1i not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniform2i(GLint location, GLint v0, GLint v1) const
{
if (_glUniform2i)
{
typedef void (APIENTRY * Uniform2iProc) (GLint location, GLint v0, GLint v1);
((Uniform2iProc)_glUniform2i)(location, v0, v1);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniform2i not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniform3i(GLint location, GLint v0, GLint v1, GLint v2) const
{
if (_glUniform3i)
{
typedef void (APIENTRY * Uniform3iProc) (GLint location, GLint v0, GLint v1, GLint v2);
((Uniform3iProc)_glUniform3i)(location, v0, v1, v2);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniform3i not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) const
{
if (_glUniform4i)
{
typedef void (APIENTRY * Uniform4iProc) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
((Uniform4iProc)_glUniform4i)(location, v0, v1, v2, v3);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniform4i not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniform1fv(GLint location, GLsizei count, GLfloat *value) const
{
if (_glUniform1fv)
{
typedef void (APIENTRY * Uniform1fvProc) (GLint location, GLsizei count, GLfloat *value);
((Uniform1fvProc)_glUniform1fv)(location, count, value);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniform1fv not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniform2fv(GLint location, GLsizei count, GLfloat *value) const
{
if (_glUniform2fv)
{
typedef void (APIENTRY * Uniform2fvProc) (GLint location, GLsizei count, GLfloat *value);
((Uniform2fvProc)_glUniform2fv)(location, count, value);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniform2fv not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniform3fv(GLint location, GLsizei count, GLfloat *value) const
{
if (_glUniform3fv)
{
typedef void (APIENTRY * Uniform3fvProc) (GLint location, GLsizei count, GLfloat *value);
((Uniform3fvProc)_glUniform3fv)(location, count, value);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniform3fv not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniform4fv(GLint location, GLsizei count, GLfloat *value) const
{
if (_glUniform4fv)
{
typedef void (APIENTRY * Uniform4fvProc) (GLint location, GLsizei count, GLfloat *value);
((Uniform4fvProc)_glUniform4fv)(location, count, value);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniform4fv not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniform1iv(GLint location, GLsizei count, GLint *value) const
{
if (_glUniform1iv)
{
typedef void (APIENTRY * Uniform1ivProc) (GLint location, GLsizei count, GLint *value);
((Uniform1ivProc)_glUniform1iv)(location, count, value);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniform1iv not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniform2iv(GLint location, GLsizei count, GLint *value) const
{
if (_glUniform2iv)
{
typedef void (APIENTRY * Uniform2ivProc) (GLint location, GLsizei count, GLint *value);
((Uniform2ivProc)_glUniform2iv)(location, count, value);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniform2iv not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniform3iv(GLint location, GLsizei count, GLint *value) const
{
if (_glUniform3iv)
{
typedef void (APIENTRY * Uniform3ivProc) (GLint location, GLsizei count, GLint *value);
((Uniform3ivProc)_glUniform3iv)(location, count, value);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniform3iv not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniform4iv(GLint location, GLsizei count, GLint *value) const
{
if (_glUniform4iv)
{
typedef void (APIENTRY * Uniform4ivProc) (GLint location, GLsizei count, GLint *value);
((Uniform4ivProc)_glUniform4iv)(location, count, value);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniform4iv not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, GLfloat *value) const
{
if (_glUniformMatrix2fv)
{
typedef void (APIENTRY * UniformMatrix2fvProc) (GLint location, GLsizei count, GLboolean transpose, GLfloat *value);
((UniformMatrix2fvProc)_glUniformMatrix2fv)(location, count, transpose, value);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniformMatrix2fv not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, GLfloat *value) const
{
if (_glUniformMatrix3fv)
{
typedef void (APIENTRY * UniformMatrix3fvProc) (GLint location, GLsizei count, GLboolean transpose, GLfloat *value);
((UniformMatrix3fvProc)_glUniformMatrix3fv)(location, count, transpose, value);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniformMatrix3fv not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, GLfloat *value) const
{
if (_glUniformMatrix4fv)
{
typedef void (APIENTRY * UniformMatrix4fvProc) (GLint location, GLsizei count, GLboolean transpose, GLfloat *value);
((UniformMatrix4fvProc)_glUniformMatrix4fv)(location, count, transpose, value);
}
else
{
osg::notify(osg::WARN)<<"Error: glUniformMatrix4fv not supported by OpenGL driver"<<std::endl;
}
}
GLint Extensions::glGetUniformLocation(GLhandleARB programObject, const GLcharARB *name) const
{
if (_glGetUniformLocation)
{
typedef GLint (APIENTRY * GetUniformLocationProc) (GLhandleARB programObject, const GLcharARB *name);
return ((GetUniformLocationProc)_glGetUniformLocation)(programObject, name);
}
else
{
osg::notify(osg::WARN)<<"Error: glGetUniformLocation not supported by OpenGL driver"<<std::endl;
return -1; //TODO
}
}
GLint Extensions::glGetAttribLocation(GLhandleARB programObj, const GLcharARB *name) const
{
if (_glGetAttribLocation)
{
typedef GLint (APIENTRY * GetAttribLocationProc) (GLhandleARB programObj, const GLcharARB *name);
return ((GetAttribLocationProc)_glGetAttribLocation)(programObj, name);
}
else
{
osg::notify(osg::WARN)<<"Error: glGetAttribLocation not supported by OpenGL driver"<<std::endl;
return -1; //TODO
}
}
void Extensions::glGetActiveUniform(GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLint *type, GLcharARB *name) const
{
if (_glGetActiveUniform)
{
typedef void (APIENTRY * GetActiveUniformProc) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLint *type, GLcharARB *name);
((GetActiveUniformProc)_glGetActiveUniform)(programObj, index, maxLength, length, size, type, name);
}
else
{
osg::notify(osg::WARN)<<"Error: glGetActiveUniform not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glGetActiveAttribs(GLhandleARB programObj, GLint *count, const GLint **size, const GLenum **type, const GLcharARB* const **attributes) const
{
if (_glGetActiveAttribs)
{
typedef void (APIENTRY * GetActiveAttribsProc) (GLhandleARB programObj, GLint *count, const GLint **size, const GLenum **type, const GLcharARB* const **attributes);
((GetActiveAttribsProc)_glGetActiveAttribs)(programObj, count, size, type, attributes);
}
else
{
osg::notify(osg::WARN)<<"Error: glGetActiveAttribs not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glGetUniformfv(GLhandleARB programObj, GLint location, GLfloat *params) const
{
if (_glGetUniformfv)
{
typedef void (APIENTRY * GetUniformfvProc) (GLhandleARB programObj, GLint location, GLfloat *params);
((GetUniformfvProc)_glGetUniformfv)(programObj, location, params);
}
else
{
osg::notify(osg::WARN)<<"Error: glGetUniformfv not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glGetUniformiv(GLhandleARB programObj, GLint location, GLint *params) const
{
if (_glGetUniformiv)
{
typedef void (APIENTRY * GetUniformivProc) (GLhandleARB programObj, GLint location, GLint *params);
((GetUniformivProc)_glGetUniformiv)(programObj, location, params);
}
else
{
osg::notify(osg::WARN)<<"Error: glGetUniformiv not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glGetObjectParameterfv(GLhandleARB obj, GLenum pname, GLfloat *params) const
{
if (_glGetObjectParameterfv)
{
typedef void (APIENTRY * GetObjectParameterfvProc) (GLhandleARB obj, GLenum pname, GLfloat *params);
((GetObjectParameterfvProc)_glGetObjectParameterfv)(obj, pname, params);
}
else
{
osg::notify(osg::WARN)<<"Error: glGetObjectParameterfv not supported by OpenGL driver"<<std::endl;
}
}
void Extensions::glGetObjectParameteriv(GLhandleARB obj, GLenum pname, GLint *params) const
{
if (_glGetObjectParameteriv)
{
typedef void (APIENTRY * GetObjectParameterivProc) (GLhandleARB obj, GLenum pname, GLint *params);
((GetObjectParameterivProc)_glGetObjectParameteriv)(obj, pname, params);
}
else
{
osg::notify(osg::WARN)<<"Error: glGetObjectParameteriv not supported by OpenGL driver"<<std::endl;
}
}
GLhandleARB Extensions::glGetHandle(GLenum pname) const
{
if (_glGetHandle)
{
typedef GLhandleARB (APIENTRY * GetHandleProc) (GLenum pname);
return ((GetHandleProc)_glGetHandle)(pname);
}
else
{
osg::notify(osg::WARN)<<"Error: glGetHandle not supported by OpenGL driver"<<std::endl;
return -1; //TODO
}
}

20
src/osgGL2/GNUmakefile Normal file
View File

@ -0,0 +1,20 @@
TOPDIR = ../..
include $(TOPDIR)/Make/makedefs
CXXFILES = \
Extensions.cpp \
Version.cpp \
ProgramObject.cpp
DEF += -DOSGGL2_LIBRARY
LIBS += -losg -losgUtil $(GL_LIBS) $(OTHER_LIBS)
TARGET_BASENAME = osgGL2
LIB = $(LIB_PREFIX)$(TARGET_BASENAME).$(LIB_EXT)
include $(TOPDIR)/Make/makerules

View File

@ -0,0 +1,365 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
* Copyright (C) 2003 3Dlabs Inc. Ltd.
*
* This application is open source and may be redistributed and/or modified
* freely and without restriction, both in commericial and non commericial
* applications, as long as this copyright notice is maintained.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
/* file: src/osgGL2/ProgramObject.cpp
* author: Mike Weiblen 2003-07-14
*
* See http://www.3dlabs.com/opengl2/ for more information regarding
* the OpenGL Shading Language.
*/
#include <fstream>
#include <osg/Notify>
#include <osg/State>
#include <osg/ref_ptr>
#include <osgGL2/ProgramObject>
#include <osgGL2/Extensions>
using namespace osgGL2;
///////////////////////////////////////////////////////////////////////////
// static cache of deleted GL2 objects which may only
// by actually deleted in the correct GL context.
typedef std::vector<GLhandleARB> GL2ObjectVector;
typedef std::map<unsigned int, GL2ObjectVector> DeletedGL2ObjectCache;
static DeletedGL2ObjectCache s_deletedGL2ObjectCache;
void osgGL2::DeleteObject(unsigned int contextID, GLhandleARB handle)
{
if (handle!=0)
{
// add handle to the cache for the appropriate context.
s_deletedGL2ObjectCache[contextID].push_back(handle);
}
}
void osgGL2::FlushDeletedGL2Objects(unsigned int contextID)
{
const Extensions* extensions = Extensions::Get(contextID,true);
if (!extensions->isShaderObjectsSupported())
return;
DeletedGL2ObjectCache::iterator citr = s_deletedGL2ObjectCache.find(contextID);
if( citr != s_deletedGL2ObjectCache.end() )
{
GL2ObjectVector vpObjectSet;
// this swap will transfer the content of and empty citr->second
// in one quick pointer change.
vpObjectSet.swap(citr->second);
for( GL2ObjectVector::iterator titr=vpObjectSet.begin();
titr!=vpObjectSet.end();
++titr )
{
extensions->glDeleteObject( *titr );
}
}
}
///////////////////////////////////////////////////////////////////////////
// osgGL2::ProgramObject
///////////////////////////////////////////////////////////////////////////
ProgramObject::ProgramObject()
{
}
ProgramObject::ProgramObject(const ProgramObject& rhs, const osg::CopyOp& copyop):
osg::StateAttribute(rhs, copyop)
{
}
// virtual
ProgramObject::~ProgramObject()
{
for( unsigned int cxt=0; cxt<_pcpoList.size(); ++cxt )
{
if( ! _pcpoList[cxt] ) continue;
PerContextProgObj* pcpo = _pcpoList[cxt].get();
DeleteObject( cxt, pcpo->getHandle() );
// TODO add shader objects to delete list.
_pcpoList[cxt] = 0;
}
}
// mark each PCPO (per-context ProgramObject) as needing a relink
void ProgramObject::dirtyProgramObject()
{
for( unsigned int cxt=0; cxt<_pcpoList.size(); ++cxt )
{
if( ! _pcpoList[cxt] ) continue;
PerContextProgObj* pcpo = _pcpoList[cxt].get();
pcpo->markAsDirty();
}
}
void ProgramObject::addShader( ShaderObject* shader )
{
_shaderObjectList.push_back(shader);
dirtyProgramObject();
}
void ProgramObject::apply(osg::State& state) const
{
const unsigned int contextID = state.getContextID();
const Extensions* extensions = Extensions::Get(contextID,true);
if (!extensions->isShaderObjectsSupported())
return;
// if there are no ShaderObjects attached (ie it is "empty"),
// indicates to use GL 1.x "fixed functionality" rendering.
if( _shaderObjectList.size() == 0 )
{
// glProgramObject handle 0 == GL 1.x fixed functionality
extensions->glUseProgramObject( 0 );
return;
}
PerContextProgObj* pcpo = getPCPO( contextID );
// if the first apply(), attach glShaderObjects to the glProgramObject
if( pcpo->isUnattached() )
{
for( unsigned int i=0; i < _shaderObjectList.size() ; ++i )
{
if( ! _shaderObjectList[i] ) continue;
_shaderObjectList[i]->attach( contextID, pcpo->getHandle() );
}
pcpo->markAsAttached();
}
// if we're dirty, build all attached objects, then build ourself
if( pcpo->isDirty() )
{
for( unsigned int i=0; i < _shaderObjectList.size() ; ++i )
{
if( ! _shaderObjectList[i] ) continue;
_shaderObjectList[i]->build( contextID );
}
if( pcpo->build() )
pcpo->markAsClean();
}
// make this glProgramObject part of current GL state
pcpo->use();
}
ProgramObject::PerContextProgObj* ProgramObject::getPCPO(unsigned int contextID) const
{
if( ! _pcpoList[contextID].valid() )
{
_pcpoList[contextID] = new PerContextProgObj( this, Extensions::Get(contextID,true) );
}
return _pcpoList[contextID].get();
}
///////////////////////////////////////////////////////////////////////////
// PCPO : OSG abstraction of the per-context Program Object
ProgramObject::PerContextProgObj::PerContextProgObj(const ProgramObject* parent, Extensions* extensions) :
Referenced()
{
_parent = parent;
_extensions = extensions;
_handle= _extensions->glCreateProgramObject();
markAsDirty();
_unattached = true;
}
ProgramObject::PerContextProgObj::PerContextProgObj(const PerContextProgObj& rhs) :
Referenced()
{
_parent = rhs._parent;
_extensions = rhs._extensions;
_handle= rhs._handle;
_dirty = rhs._dirty;
_unattached = rhs._unattached;
}
ProgramObject::PerContextProgObj::~PerContextProgObj()
{
}
bool ProgramObject::PerContextProgObj::build() const
{
_extensions->glLinkProgram(_handle);
return true;
}
void ProgramObject::PerContextProgObj::use() const
{
_extensions->glUseProgramObject( _handle );
}
///////////////////////////////////////////////////////////////////////////
// osgGL2::ShaderObject
///////////////////////////////////////////////////////////////////////////
ShaderObject::ShaderObject() :
_type(UNKNOWN)
{
}
ShaderObject::ShaderObject(Type type) :
_type(type)
{
}
ShaderObject::ShaderObject(Type type, const char* sourceText) :
_type(type)
{
setShaderSource(sourceText);
}
ShaderObject::ShaderObject(const ShaderObject& rhs, const osg::CopyOp& copyop):
osg::Object(rhs, copyop)
{
/*TODO*/
}
ShaderObject::~ShaderObject()
{
/*TODO*/
}
// mark each PCSO (per-context Shader Object) as needing a recompile
void ShaderObject::dirtyShaderObject()
{
for( unsigned int cxt=0; cxt<_pcsoList.size(); ++cxt )
{
if( ! _pcsoList[cxt] ) continue;
PerContextShaderObj* pcso = _pcsoList[cxt].get();
pcso->markAsDirty();
}
}
void ShaderObject::setShaderSource( const char* sourceText )
{
_shaderSource = sourceText;
dirtyShaderObject();
}
bool ShaderObject::loadShaderSourceFromFile( const char* fileName )
{
std::ifstream sourceFile;
sourceFile.open(fileName, std::ios::binary);
if(!sourceFile)
{
osg::notify(osg::WARN)<<"Error: can't open file \""<<fileName<<"\""<<std::endl;
return false;
}
osg::notify(osg::INFO)<<"Loading shader source file \""<<fileName<<"\""<<std::endl;
sourceFile.seekg(0, std::ios::end);
int length = sourceFile.tellg();
char *text = new char[length + 1];
sourceFile.seekg(0, std::ios::beg);
sourceFile.read(text, length);
sourceFile.close();
text[length] = '\0';
setShaderSource( text );
delete text;
return true;
}
bool ShaderObject::build(unsigned int contextID ) const
{
PerContextShaderObj* pcso = getPCSO( contextID );
if( pcso->isDirty() )
{
if( pcso->build() )
pcso->markAsClean();
}
return true; /*TODO*/
}
ShaderObject::PerContextShaderObj* ShaderObject::getPCSO(unsigned int contextID) const
{
if( ! _pcsoList[contextID].valid() )
{
_pcsoList[contextID] = new PerContextShaderObj( this, Extensions::Get(contextID,true) );
}
return _pcsoList[contextID].get();
}
void ShaderObject::attach(unsigned int contextID, GLhandleARB progObj) const
{
getPCSO( contextID )->attach( progObj );
}
///////////////////////////////////////////////////////////////////////////
// PCSO : OSG abstraction of the per-context Shader Object
ShaderObject::PerContextShaderObj::PerContextShaderObj(const ShaderObject* parent, Extensions* extensions) :
Referenced()
{
_parent = parent;
_extensions = extensions;
_handle = _extensions->glCreateShaderObject( parent->getType() );
markAsDirty();
}
ShaderObject::PerContextShaderObj::PerContextShaderObj(const PerContextShaderObj& rhs) :
Referenced()
{
_parent = rhs._parent;
_extensions = rhs._extensions;
_handle = rhs._handle;
_dirty = rhs._dirty;
}
ShaderObject::PerContextShaderObj::~PerContextShaderObj()
{
}
bool ShaderObject::PerContextShaderObj::build()
{
const char* sourceText = _parent->getShaderSource().c_str();
_extensions->glShaderSource( _handle, 1, &sourceText, NULL );
_extensions->glCompileShader( _handle );
// _extensions->glAttachObject( _handle, vertShaderObject );
return true;
}
void ShaderObject::PerContextShaderObj::attach(GLhandleARB progObj)
{
_extensions->glAttachObject(progObj, _handle);
}
/*EOF*/

13
src/osgGL2/Version.cpp Normal file
View File

@ -0,0 +1,13 @@
#include <osgGL2/Version>
const char* osgGL2GetVersion()
{
return "0.1.0";
}
const char* osgGL2GetLibraryName()
{
return "Open Scene Graph OpenGL Shading Language Library";
}