Added new ARB vertex program state attribute and demo program,
sent in my Brede Johansen.
This commit is contained in:
parent
060975a05c
commit
3ef3666d0f
@ -106,5 +106,6 @@ DEMOS_DIRS = \
|
||||
osgtexture3D\
|
||||
osgunittests\
|
||||
osgversion\
|
||||
osgvertexprogram\
|
||||
osgviews\
|
||||
sgv
|
||||
|
9
NEWS
9
NEWS
@ -18,9 +18,16 @@ OSG News (most significant items from ChangeLog)
|
||||
Addition osgSim which is NodeKit designed for visual simulation
|
||||
market, currently features high fidelity light points support.
|
||||
|
||||
From Brede Johansen, new osgpbuffer demo for Win32.
|
||||
From Brede Johansen, new ARB VertexProgram StateAttribute class and
|
||||
osgpbuffer demo for Win32.
|
||||
|
||||
New osglogo demo.
|
||||
|
||||
Removed the osg/ManagerManger and associated #define osgNew's, this has
|
||||
been done to simplify users code and to solve the lack of thread safety
|
||||
that was causing problems with the MemoryManager.
|
||||
|
||||
Support for reading and writing of callbacks in the .osg format.
|
||||
|
||||
|
||||
13th November 2002 - OpenSceneGraph-0.9.2.tar.gz
|
||||
|
95
VisualStudio/Demos/osgvertexprogram/osgvertexprogram.dsp
Executable file
95
VisualStudio/Demos/osgvertexprogram/osgvertexprogram.dsp
Executable file
@ -0,0 +1,95 @@
|
||||
# Microsoft Developer Studio Project File - Name="Demo osgvertexprogram" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=Demo osgvertexprogram - 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 "osgvertexprogram.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 "osgvertexprogram.mak" CFG="Demo osgvertexprogram - Win32 Release"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "Demo osgvertexprogram - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "Demo osgvertexprogram - 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)" == "Demo osgvertexprogram - 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 /nologo /subsystem:console /pdb:none /machine:I386 /out:"../../../bin/osgvertexprogram.exe" /libpath:"../../../lib"
|
||||
|
||||
!ELSEIF "$(CFG)" == "Demo osgvertexprogram - 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 /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"libcmt" /out:"../../../bin/osgvertexprogramd.exe" /pdbtype:sept /libpath:"../../../lib"
|
||||
# SUBTRACT LINK32 /incremental:no
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "Demo osgvertexprogram - Win32 Release"
|
||||
# Name "Demo osgvertexprogram - Win32 Debug"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\Demos\osgvertexprogram\osgvertexprogram.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
|
@ -402,6 +402,33 @@ Package=<4>
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "Demo osgvertexprogram"=.\Demos\osgvertexprogram\osgvertexprogram.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 osgGLUT
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name Core osgUtil
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "Demo osgshape"=.\Demos\osgshape\osgshape.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
|
@ -429,6 +429,10 @@ SOURCE=..\..\src\osg\Vec3.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\VertexProgram.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\Version.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@ -849,6 +853,10 @@ SOURCE=..\..\Include\Osg\Vec4
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\VertexProgram
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\Version
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -90,9 +90,9 @@ class SG_EXPORT Geometry : public Drawable
|
||||
void setFogCoordBinding(AttributeBinding ab) { _fogCoordBinding = ab; _fastPathComputed=false;}
|
||||
AttributeBinding getFogCoordBinding() const { return _fogCoordBinding; }
|
||||
|
||||
void setFogCoordArray(FloatArray* array) { _fogCoordArray = array; if (!_fogCoordArray.valid()) _fogCoordBinding=BIND_OFF; dirtyDisplayList(); }
|
||||
FloatArray* getFogCoordArray() { return _fogCoordArray.get(); }
|
||||
const FloatArray* getFogCoordArray() const { return _fogCoordArray.get(); }
|
||||
void setFogCoordArray(Array* array) { _fogCoordArray = array; if (!_fogCoordArray.valid()) _fogCoordBinding=BIND_OFF; dirtyDisplayList(); }
|
||||
Array* getFogCoordArray() { return _fogCoordArray.get(); }
|
||||
const Array* getFogCoordArray() const { return _fogCoordArray.get(); }
|
||||
|
||||
|
||||
void setFogCoordIndices(IndexArray* array) { _fogCoordIndices = array; dirtyDisplayList(); }
|
||||
@ -205,7 +205,7 @@ class SG_EXPORT Geometry : public Drawable
|
||||
ref_ptr<IndexArray> _secondaryColorIndices;
|
||||
|
||||
mutable AttributeBinding _fogCoordBinding;
|
||||
ref_ptr<FloatArray> _fogCoordArray;
|
||||
ref_ptr<Array> _fogCoordArray;
|
||||
ref_ptr<IndexArray> _fogCoordIndices;
|
||||
|
||||
TexCoordArrayList _texCoordList;
|
||||
|
@ -151,7 +151,10 @@ class SG_EXPORT StateAttribute : public Object
|
||||
CLIPPLANE_4,
|
||||
CLIPPLANE_5,
|
||||
|
||||
COLORMATRIX
|
||||
COLORMATRIX,
|
||||
|
||||
VERTEXPROGRAM,
|
||||
FRAGMENTPROGRAM
|
||||
};
|
||||
|
||||
|
||||
|
183
include/osg/VertexProgram
Normal file
183
include/osg/VertexProgram
Normal file
@ -0,0 +1,183 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSG_VERTEXPROGRAM
|
||||
#define OSG_VERTEXPROGRAM 1
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/Vec4>
|
||||
#include <osg/Matrix>
|
||||
|
||||
#include <cassert>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
// if not defined by gl.h use the definition found in:
|
||||
// http://oss.sgi.com/projects/ogl-sample/registry/ARB/vertex_program.txt
|
||||
#ifndef GL_ARB_vertex_program
|
||||
#define GL_VERTEX_PROGRAM_ARB 0x8620
|
||||
#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642
|
||||
#define GL_VERTEX_PROGRAM_TWO_SIDE_ARB 0x8643
|
||||
#define GL_COLOR_SUM_ARB 0x8458
|
||||
#define GL_PROGRAM_FORMAT_ASCII_ARB 0x8875
|
||||
#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_PROGRAM_LENGTH_ARB 0x8627
|
||||
#define GL_PROGRAM_FORMAT_ARB 0x8876
|
||||
#define GL_PROGRAM_BINDING_ARB 0x8677
|
||||
#define GL_PROGRAM_INSTRUCTIONS_ARB 0x88A0
|
||||
#define GL_MAX_PROGRAM_INSTRUCTIONS_ARB 0x88A1
|
||||
#define GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A2
|
||||
#define GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A3
|
||||
#define GL_PROGRAM_TEMPORARIES_ARB 0x88A4
|
||||
#define GL_MAX_PROGRAM_TEMPORARIES_ARB 0x88A5
|
||||
#define GL_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A6
|
||||
#define GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A7
|
||||
#define GL_PROGRAM_PARAMETERS_ARB 0x88A8
|
||||
#define GL_MAX_PROGRAM_PARAMETERS_ARB 0x88A9
|
||||
#define GL_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AA
|
||||
#define GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AB
|
||||
#define GL_PROGRAM_ATTRIBS_ARB 0x88AC
|
||||
#define GL_MAX_PROGRAM_ATTRIBS_ARB 0x88AD
|
||||
#define GL_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AE
|
||||
#define GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AF
|
||||
#define GL_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B0
|
||||
#define GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B1
|
||||
#define GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B2
|
||||
#define GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B3
|
||||
#define GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB 0x88B4
|
||||
#define GL_MAX_PROGRAM_ENV_PARAMETERS_ARB 0x88B5
|
||||
#define GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB 0x88B6
|
||||
#define GL_PROGRAM_STRING_ARB 0x8628
|
||||
#define GL_PROGRAM_ERROR_POSITION_ARB 0x864B
|
||||
#define GL_CURRENT_MATRIX_ARB 0x8641
|
||||
#define GL_TRANSPOSE_CURRENT_MATRIX_ARB 0x88B7
|
||||
#define GL_CURRENT_MATRIX_STACK_DEPTH_ARB 0x8640
|
||||
#define GL_MAX_VERTEX_ATTRIBS_ARB 0x8869
|
||||
#define GL_MAX_PROGRAM_MATRICES_ARB 0x862F
|
||||
#define GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB 0x862E
|
||||
#define GL_PROGRAM_ERROR_STRING_ARB 0x8874
|
||||
#define GL_MATRIX0_ARB 0x88C0
|
||||
#define GL_MATRIX1_ARB 0x88C1
|
||||
#define GL_MATRIX2_ARB 0x88C2
|
||||
#define GL_MATRIX3_ARB 0x88C3
|
||||
#define GL_MATRIX4_ARB 0x88C4
|
||||
#define GL_MATRIX5_ARB 0x88C5
|
||||
#define GL_MATRIX6_ARB 0x88C6
|
||||
#define GL_MATRIX7_ARB 0x88C7
|
||||
#define GL_MATRIX8_ARB 0x88C8
|
||||
#define GL_MATRIX9_ARB 0x88C9
|
||||
#define GL_MATRIX10_ARB 0x88CA
|
||||
#define GL_MATRIX11_ARB 0x88CB
|
||||
#define GL_MATRIX12_ARB 0x88CC
|
||||
#define GL_MATRIX13_ARB 0x88CD
|
||||
#define GL_MATRIX14_ARB 0x88CE
|
||||
#define GL_MATRIX15_ARB 0x88CF
|
||||
#define GL_MATRIX16_ARB 0x88D0
|
||||
#define GL_MATRIX17_ARB 0x88D1
|
||||
#define GL_MATRIX18_ARB 0x88D2
|
||||
#define GL_MATRIX19_ARB 0x88D3
|
||||
#define GL_MATRIX20_ARB 0x88D4
|
||||
#define GL_MATRIX21_ARB 0x88D5
|
||||
#define GL_MATRIX22_ARB 0x88D6
|
||||
#define GL_MATRIX23_ARB 0x88D7
|
||||
#define GL_MATRIX24_ARB 0x88D8
|
||||
#define GL_MATRIX25_ARB 0x88D9
|
||||
#define GL_MATRIX26_ARB 0x88DA
|
||||
#define GL_MATRIX27_ARB 0x88DB
|
||||
#define GL_MATRIX28_ARB 0x88DC
|
||||
#define GL_MATRIX29_ARB 0x88DD
|
||||
#define GL_MATRIX30_ARB 0x88DE
|
||||
#define GL_MATRIX31_ARB 0x88DF
|
||||
#endif
|
||||
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
||||
|
||||
/** VertexProgram - encapsulates the OpenGL ARB vertex program state.*/
|
||||
class SG_EXPORT VertexProgram : public StateAttribute
|
||||
{
|
||||
public:
|
||||
|
||||
VertexProgram();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
VertexProgram(const VertexProgram& vp,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_StateAttribute(osg, VertexProgram, VERTEXPROGRAM);
|
||||
|
||||
/** 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(VertexProgram,sa)
|
||||
|
||||
// compare each paramter in turn against the rhs.
|
||||
COMPARE_StateAttribute_Parameter(_vertexProgramId)
|
||||
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
modes.push_back(GL_VERTEX_PROGRAM_ARB);
|
||||
}
|
||||
|
||||
// data access methods.
|
||||
|
||||
/** Set the vertex program using C++ style string.*/
|
||||
inline void setVertexProgram( const std::string& program ) { _vertexProgram = program; }
|
||||
/** Set the vertex program using a C style string.*/
|
||||
inline void setVertexProgram( const char* program ) { _vertexProgram = program; }
|
||||
/** Get the vertex program.*/
|
||||
inline const std::string& getVertexProgram() const { return _vertexProgram; }
|
||||
/** Load vertex program from file. */
|
||||
// inline void loadVertexProgram( const std::string& filename ) {
|
||||
// _vertexProgram = loadProgramFile( filename ); }
|
||||
|
||||
|
||||
/** Program Parameters */
|
||||
inline void setProgramLocalParameter(const GLuint index, const Vec4& p)
|
||||
{
|
||||
_programLocalParameters[index] = p;
|
||||
}
|
||||
|
||||
/** Matrix */
|
||||
inline void setMatrix(const GLenum mode, const Matrix& matrix)
|
||||
{
|
||||
assert(mode>=GL_MATRIX0_ARB && mode<=GL_MATRIX31_ARB);
|
||||
_matrixList[mode] = new Matrix(matrix);
|
||||
}
|
||||
|
||||
virtual void apply(State& state) const;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
virtual ~VertexProgram();
|
||||
|
||||
mutable GLuint _vertexProgramId;
|
||||
std::string _vertexProgram;
|
||||
|
||||
typedef std::map<GLuint,Vec4> LocalParamList;
|
||||
LocalParamList _programLocalParameters;
|
||||
|
||||
typedef std::map<GLenum,ref_ptr<Matrix> > MatrixList;
|
||||
MatrixList _matrixList;
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
15
src/Demos/osgvertexprogram/Makefile
Normal file
15
src/Demos/osgvertexprogram/Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
TOPDIR = ../../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
osgvertexprogram.cpp\
|
||||
|
||||
LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
INSTFILES = \
|
||||
$(CXXFILES)\
|
||||
Makefile.inst=Makefile
|
||||
|
||||
EXEC = osgvertexprogram
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
11
src/Demos/osgvertexprogram/Makefile.inst
Normal file
11
src/Demos/osgvertexprogram/Makefile.inst
Normal file
@ -0,0 +1,11 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
osgvertexprogram.cpp\
|
||||
|
||||
LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
EXEC = osgvertexprogram
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
188
src/Demos/osgvertexprogram/osgvertexprogram.cpp
Normal file
188
src/Demos/osgvertexprogram/osgvertexprogram.cpp
Normal file
@ -0,0 +1,188 @@
|
||||
#include <osg/Geode>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Material>
|
||||
#include <osg/Vec3>
|
||||
#include <osg/VertexProgram>
|
||||
|
||||
#include <osgGA/TrackballManipulator>
|
||||
|
||||
#include <osgGLUT/Viewer>
|
||||
#include <osgGLUT/glut>
|
||||
|
||||
// A simple ambient, specular, and diffuse infinite lighting computation
|
||||
// with a single light and an eye-space normal
|
||||
// This vertex program is a slightly modified version of an example in
|
||||
// the ARB_vertex_program spec. It uses local parameter 0 for ambient.
|
||||
// If your cube have a blue ambient component it shows the vertex-
|
||||
// program is working.
|
||||
|
||||
const char vpstr[] =
|
||||
"!!ARBvp1.0 \n"
|
||||
"ATTRIB iPos = vertex.position; \n"
|
||||
"ATTRIB iNormal = vertex.normal; \n"
|
||||
"PARAM mvinv[4] = { state.matrix.modelview.invtrans }; \n"
|
||||
"PARAM mvp[4] = { state.matrix.mvp }; \n"
|
||||
"PARAM lightDir = state.light[0].position; \n"
|
||||
"PARAM halfDir = state.light[0].half; \n"
|
||||
"PARAM specExp = state.material.shininess; \n"
|
||||
"PARAM ambientCol = program.local[0]; \n"
|
||||
"PARAM diffuseCol = state.lightprod[0].diffuse; \n"
|
||||
"PARAM specularCol = state.lightprod[0].specular; \n"
|
||||
"TEMP xfNormal, temp, dots, newDiffuse; \n"
|
||||
"OUTPUT oPos = result.position; \n"
|
||||
"OUTPUT oColor = result.color; \n"
|
||||
" \n"
|
||||
"# Transform the vertex to clip coordinates. \n"
|
||||
"DP4 oPos.x, mvp[0], iPos; \n"
|
||||
"DP4 oPos.y, mvp[1], iPos; \n"
|
||||
"DP4 oPos.z, mvp[2], iPos; \n"
|
||||
"DP4 oPos.w, mvp[3], iPos; \n"
|
||||
" \n"
|
||||
"# Transform the normal to eye coordinates. \n"
|
||||
"DP3 xfNormal.x, mvinv[0], iNormal; \n"
|
||||
"DP3 xfNormal.y, mvinv[1], iNormal; \n"
|
||||
"DP3 xfNormal.z, mvinv[2], iNormal; \n"
|
||||
" \n"
|
||||
"# Compute diffuse and specular dot products and use LIT to compute \n"
|
||||
"# lighting coefficients. \n"
|
||||
"DP3 dots.x, xfNormal, lightDir; \n"
|
||||
"DP3 dots.y, xfNormal, halfDir; \n"
|
||||
"MOV dots.w, specExp.x; \n"
|
||||
"LIT dots, dots; \n"
|
||||
" \n"
|
||||
"# Accumulate color contributions. \n"
|
||||
"MAD temp, dots.y, diffuseCol, ambientCol; \n"
|
||||
"MAD oColor.xyz, dots.z, specularCol, temp; \n"
|
||||
"MOV oColor.w, diffuseCol.w; \n"
|
||||
"END \n";
|
||||
|
||||
|
||||
osg::Geode* createGeometryCube()
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
|
||||
// -------------------------------------------
|
||||
// Set up a new Geometry which will be our cube
|
||||
// -------------------------------------------
|
||||
osg::Geometry* cube = new osg::Geometry();
|
||||
|
||||
// set up the primitives
|
||||
|
||||
cube->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,4));
|
||||
cube->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,4,4));
|
||||
cube->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,8,4));
|
||||
cube->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,12,4));
|
||||
cube->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,16,4));
|
||||
cube->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,20,4));
|
||||
|
||||
|
||||
// set up coords.
|
||||
osg::Vec3Array* coords = new osg::Vec3Array;
|
||||
coords->resize(24);
|
||||
|
||||
(*coords)[0].set( -1.0000f, 1.0000f, -1.000f );
|
||||
(*coords)[1].set( 1.0000f, 1.0000f, -1.0000f );
|
||||
(*coords)[2].set( 1.0000f, -1.0000f, -1.0000f );
|
||||
(*coords)[3].set( -1.0000f, -1.0000f, -1.000 );
|
||||
|
||||
(*coords)[4].set( 1.0000f, 1.0000f, -1.0000f );
|
||||
(*coords)[5].set( 1.0000f, 1.0000f, 1.0000f );
|
||||
(*coords)[6].set( 1.0000f, -1.0000f, 1.0000f );
|
||||
(*coords)[7].set( 1.0000f, -1.0000f, -1.0000f );
|
||||
|
||||
(*coords)[8].set( 1.0000f, 1.0000f, 1.0000f );
|
||||
(*coords)[9].set( -1.0000f, 1.0000f, 1.000f );
|
||||
(*coords)[10].set( -1.0000f, -1.0000f, 1.000f );
|
||||
(*coords)[11].set( 1.0000f, -1.0000f, 1.0000f );
|
||||
|
||||
(*coords)[12].set( -1.0000f, 1.0000f, 1.000 );
|
||||
(*coords)[13].set( -1.0000f, 1.0000f, -1.000 );
|
||||
(*coords)[14].set( -1.0000f, -1.0000f, -1.000 );
|
||||
(*coords)[15].set( -1.0000f, -1.0000f, 1.000 );
|
||||
|
||||
(*coords)[16].set( -1.0000f, 1.0000f, 1.000 );
|
||||
(*coords)[17].set( 1.0000f, 1.0000f, 1.0000f );
|
||||
(*coords)[18].set( 1.0000f, 1.0000f, -1.0000f );
|
||||
(*coords)[19].set( -1.0000f, 1.0000f, -1.000f );
|
||||
|
||||
(*coords)[20].set( -1.0000f, -1.0000f, 1.000f );
|
||||
(*coords)[21].set( -1.0000f, -1.0000f, -1.000f );
|
||||
(*coords)[22].set( 1.0000f, -1.0000f, -1.0000f );
|
||||
(*coords)[23].set( 1.0000f, -1.0000f, 1.0000f );
|
||||
|
||||
|
||||
cube->setVertexArray( coords );
|
||||
|
||||
|
||||
// set up the normals.
|
||||
osg::Vec3Array* cubeNormals = new osg::Vec3Array;
|
||||
cubeNormals->resize(6);
|
||||
|
||||
(*cubeNormals)[0].set(0.0f,0.0f,-1.0f);
|
||||
(*cubeNormals)[1].set(1.0f,0.0f,0.0f);
|
||||
(*cubeNormals)[2].set(0.0f,0.0f,1.0f);
|
||||
(*cubeNormals)[3].set(-1.0f,0.0f,0.0f);
|
||||
(*cubeNormals)[4].set(0.0f,1.0f,0.0f);
|
||||
(*cubeNormals)[5].set(0.0f,-1.0f,0.0f);
|
||||
|
||||
cube->setNormalArray( cubeNormals );
|
||||
cube->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE );
|
||||
|
||||
// -------------------------
|
||||
// make diffuse material red
|
||||
// -------------------------
|
||||
osg::StateSet* cubeState = new osg::StateSet();
|
||||
osg::Material* redMaterial = new osg::Material();
|
||||
const osg::Vec4 red( 1.0f, 0.0f, 0.0f, 1.0f );
|
||||
redMaterial->setAmbient( osg::Material::FRONT_AND_BACK, red );
|
||||
redMaterial->setDiffuse( osg::Material::FRONT_AND_BACK, red );
|
||||
cubeState->setAttribute( redMaterial );
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Use vp local parameter 0 for ambient product (blue)
|
||||
// ---------------------------------------------------
|
||||
osg::VertexProgram* vp = new osg::VertexProgram();
|
||||
vp->setVertexProgram( vpstr );
|
||||
const osg::Vec4 blue( 0.0f, 0.0f, 1.0f, 1.0f );
|
||||
vp->setProgramLocalParameter( 0, blue );
|
||||
cubeState->setAttributeAndModes( vp, osg::StateAttribute::ON );
|
||||
|
||||
cube->setStateSet( cubeState );
|
||||
|
||||
geode->addDrawable( cube );
|
||||
|
||||
return geode;
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
|
||||
glutInit( &argc, argv );
|
||||
|
||||
// create the commandline args.
|
||||
std::vector<std::string> commandLine;
|
||||
for(int i=1;i<argc;++i) commandLine.push_back(argv[i]);
|
||||
|
||||
// create the viewer and the model to it.
|
||||
osgGLUT::Viewer viewer;
|
||||
|
||||
viewer.setWindowTitle(argv[0]);
|
||||
|
||||
|
||||
// configure the viewer from the commandline arguments, and eat any
|
||||
// parameters that have been matched.
|
||||
viewer.readCommandLine(commandLine);
|
||||
|
||||
// add model to viewer.
|
||||
viewer.addViewport( createGeometryCube() );
|
||||
|
||||
// register trackball maniupulators.
|
||||
viewer.registerCameraManipulator(new osgGA::TrackballManipulator);
|
||||
|
||||
viewer.open();
|
||||
|
||||
viewer.run();
|
||||
|
||||
return 0;
|
||||
}
|
@ -160,22 +160,23 @@ class DrawFogCoord : public osg::ConstValueVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
DrawFogCoord(const FloatArray* fogcoords,const IndexArray* indices,
|
||||
FogCoordProc fogCoordProc):
|
||||
DrawFogCoord(const Array* fogcoords,const IndexArray* indices,FogCoordProc fogCoordProc):
|
||||
_fogcoords(fogcoords),
|
||||
_indices(indices),
|
||||
_glFogCoord1fv(fogCoordProc) {}
|
||||
|
||||
void operator () (unsigned int pos)
|
||||
{
|
||||
if (_indices) _glFogCoord1fv(&(*_fogcoords)[_indices->index(pos)]);
|
||||
else _glFogCoord1fv(&(*_fogcoords)[pos]);
|
||||
if (_indices) _fogcoords->accept(_indices->index(pos),*this);
|
||||
else _fogcoords->accept(pos,*this);
|
||||
}
|
||||
|
||||
const FloatArray* _fogcoords;
|
||||
virtual void apply(const GLfloat& v) { _glFogCoord1fv(&v); }
|
||||
|
||||
const Array* _fogcoords;
|
||||
const IndexArray* _indices;
|
||||
|
||||
FogCoordProc _glFogCoord1fv;
|
||||
FogCoordProc _glFogCoord1fv;
|
||||
};
|
||||
|
||||
|
||||
|
@ -87,6 +87,7 @@ CXXFILES =\
|
||||
UnitTestFramework.cpp\
|
||||
Version.cpp\
|
||||
Vec3.cpp\
|
||||
VertexProgram.cpp\
|
||||
Viewport.cpp\
|
||||
|
||||
DEF += -DSG_LIBRARY
|
||||
|
100
src/osg/VertexProgram.cpp
Normal file
100
src/osg/VertexProgram.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
#include <osg/Notify>
|
||||
#include <osg/GLExtensions>
|
||||
#include <osg/VertexProgram>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
|
||||
VertexProgram::VertexProgram() :
|
||||
_vertexProgramId(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
VertexProgram::VertexProgram(const VertexProgram& vp,const CopyOp& copyop):
|
||||
osg::StateAttribute(vp,copyop),
|
||||
_vertexProgramId(vp._vertexProgramId)
|
||||
{}
|
||||
|
||||
|
||||
// virtual
|
||||
VertexProgram::~VertexProgram()
|
||||
{}
|
||||
|
||||
|
||||
typedef void (APIENTRY * BindProgramProc) (GLenum target, GLuint id);
|
||||
typedef void (APIENTRY * GenProgramsProc) (GLsizei n, GLuint *programs);
|
||||
typedef void (APIENTRY * ProgramStringProc) (GLenum target, GLenum format, GLsizei len, const void *string);
|
||||
typedef void (APIENTRY * ProgramLocalParameter4fvProc) (GLenum target, GLuint index, const GLfloat *params);
|
||||
|
||||
void VertexProgram::apply(State& state) const
|
||||
{
|
||||
static bool supported = osg::isGLExtensionSupported("GL_ARB_vertex_program");
|
||||
if (!supported) return;
|
||||
|
||||
static BindProgramProc s_glBindProgram =
|
||||
(BindProgramProc)osg::getGLExtensionFuncPtr("glBindProgramARB");
|
||||
static GenProgramsProc s_glGenPrograms =
|
||||
(GenProgramsProc)osg::getGLExtensionFuncPtr("glGenProgramsARB");
|
||||
static ProgramStringProc s_glProgramString =
|
||||
(ProgramStringProc)osg::getGLExtensionFuncPtr("glProgramStringARB");
|
||||
static ProgramLocalParameter4fvProc s_glProgramLocalParameter4fv =
|
||||
(ProgramLocalParameter4fvProc)osg::getGLExtensionFuncPtr("glProgramLocalParameter4fvARB");
|
||||
|
||||
// Vertex Program
|
||||
if (_vertexProgramId != 0)
|
||||
{
|
||||
s_glBindProgram( GL_VERTEX_PROGRAM_ARB, _vertexProgramId );
|
||||
}
|
||||
else if (!_vertexProgram.empty())
|
||||
{
|
||||
::glGetError(); // Reset Error flags.
|
||||
s_glGenPrograms( 1, &_vertexProgramId );
|
||||
s_glBindProgram( GL_VERTEX_PROGRAM_ARB, _vertexProgramId );
|
||||
s_glProgramString( GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
|
||||
_vertexProgram.length(), _vertexProgram.c_str());
|
||||
|
||||
// Check for errors
|
||||
int errorposition;
|
||||
::glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorposition);
|
||||
if (errorposition != -1)
|
||||
{
|
||||
notify(osg::FATAL) << "VertexProgram: " << ::glGetString(GL_PROGRAM_ERROR_STRING_ARB) << std::endl;
|
||||
|
||||
std::string::size_type start = _vertexProgram.rfind('\n', errorposition);
|
||||
std::string::size_type stop = _vertexProgram.find('\n', errorposition);
|
||||
if (start!=std::string::npos && stop!=std::string::npos)
|
||||
{
|
||||
notify(osg::FATAL) << " : " << _vertexProgram.substr(start+1, stop-start-2) << std::endl;
|
||||
std::string pointAtproblem(errorposition-(start+1), ' ');
|
||||
notify(osg::FATAL) << " : " << pointAtproblem << '^' << std::endl;
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Update local program parameters
|
||||
{
|
||||
for(LocalParamList::const_iterator itr=_programLocalParameters.begin();
|
||||
itr!=_programLocalParameters.end();
|
||||
++itr)
|
||||
{
|
||||
s_glProgramLocalParameter4fv(GL_VERTEX_PROGRAM_ARB, (*itr).first, (*itr).second.ptr());
|
||||
}
|
||||
}
|
||||
|
||||
// Update matrix
|
||||
if (!_matrixList.empty())
|
||||
{
|
||||
for(MatrixList::const_iterator itr = _matrixList.begin();
|
||||
itr!=_matrixList.end();
|
||||
++itr)
|
||||
{
|
||||
::glMatrixMode((*itr).first);
|
||||
::glLoadMatrixf((*itr).second->ptr());
|
||||
}
|
||||
::glMatrixMode(GL_MODELVIEW); // restore matrix mode
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -230,36 +230,15 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr.matchSequence("FogCoordArray %i {"))
|
||||
if (fr.matchSequence("FogCoordArray %w %i {"))
|
||||
{
|
||||
int entry = fr[0].getNoNestedBrackets();
|
||||
|
||||
int capacity;
|
||||
fr[1].getInt(capacity);
|
||||
|
||||
FloatArray* fogcoords = new FloatArray;
|
||||
fogcoords->reserve(capacity);
|
||||
|
||||
fr += 3;
|
||||
|
||||
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
|
||||
{
|
||||
float fc;
|
||||
if (fr[0].getFloat(fc))
|
||||
{
|
||||
++fr;
|
||||
fogcoords->push_back(fc);
|
||||
}
|
||||
else
|
||||
{
|
||||
++fr;
|
||||
}
|
||||
}
|
||||
|
||||
geom.setFogCoordArray(fogcoords);
|
||||
|
||||
iteratorAdvanced = true;
|
||||
++fr;
|
||||
Array* fogcoords = Array_readLocalData(fr);
|
||||
if (fogcoords)
|
||||
{
|
||||
geom.setFogCoordArray(fogcoords);
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr.matchSequence("FogCoordIndices %w %i {"))
|
||||
@ -963,12 +942,8 @@ bool Geometry_writeLocalData(const Object& obj, Output& fw)
|
||||
if (geom.getFogCoordArray())
|
||||
{
|
||||
fw.indent()<<"FogCoordBinding "<<Geometry_getBindingTypeStr(geom.getFogCoordBinding())<<std::endl;
|
||||
|
||||
const FloatArray& fogcoords = *geom.getFogCoordArray();
|
||||
fw.indent()<<"FogCoordArray "<<fogcoords.size()<<std::endl;
|
||||
|
||||
Array_writeLocalData(fw,fogcoords.begin(),fogcoords.end());
|
||||
|
||||
fw.indent()<<"FogCoordArray ";
|
||||
Array_writeLocalData(*geom.getFogCoordArray(),fw);
|
||||
}
|
||||
if (geom.getFogCoordIndices())
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user