From 37ee16403afdb2578f3fff831632ecf30ffe4272 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 25 Oct 2009 11:52:01 +0000 Subject: [PATCH] Introduced usage of OSG_GLES*_AVAILABLE macros to headers and .cpp's to enable building against OpenGL ES 1.x and 2.x headers --- CMakeLists.txt | 2 + include/osg/AlphaFunc | 4 + include/osg/ArrayDispatchers | 8 ++ include/osg/ClipPlane | 4 + include/osg/Fog | 6 + include/osg/GL | 63 ++++++++- include/osg/GL2Extensions | 7 +- include/osg/Light | 8 ++ include/osg/LineStipple | 4 + include/osg/LogicOp | 19 +++ include/osg/Material | 9 ++ include/osg/Point | 4 + include/osg/PolygonMode | 6 + include/osg/PolygonOffset | 2 + include/osg/PolygonStipple | 4 + include/osg/ShadeModel | 5 + include/osg/State | 157 ++++++++++++++------- include/osg/TexEnv | 7 + include/osg/TexEnvCombine | 3 +- include/osg/TexGen | 14 +- include/osg/Texture | 10 ++ include/osg/Texture1D | 4 + include/osg/Uniform | 9 ++ src/osg/ArrayDispatchers.cpp | 20 ++- src/osg/ClipPlane.cpp | 2 +- src/osg/ColorMatrix.cpp | 2 +- src/osg/Config.in | 1 + src/osg/Fog.cpp | 6 + src/osg/Hint.cpp | 4 +- src/osg/Image.cpp | 261 +++++++++++++++++++---------------- src/osg/LightModel.cpp | 8 ++ src/osg/Material.cpp | 4 + src/osg/State.cpp | 21 ++- src/osg/StateSet.cpp | 7 +- src/osg/Texture.cpp | 22 ++- src/osg/Texture1D.cpp | 21 ++- src/osg/TextureRectangle.cpp | 9 +- 37 files changed, 538 insertions(+), 209 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7130c569c..2506a7ad8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -290,11 +290,13 @@ OPTION(OSG_GLES2_AVAILABLE "Set to OFF to disable use of OpenGL ES 2.x functions # SET(OSG_GL_DISPLAYLISTS_AVAILABLE ${OSG_GL1_AVAILABLE}) # SET(OSG_GL_MATRICES_AVAILABLE ${OSG_GL1_AVAILABLE}) # SET(OSG_GL_VERTEX_FUNCS_AVAILABLE ${OSG_GL1_AVAILABLE}) +# SET(OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE ${OSG_GL1_AVAILABLE}) # SET(OSG_GL_FIXED_FUNCTION_AVAILABLE ${OSG_GL1_AVAILABLE}) OPTION(OSG_GL_DISPLAYLISTS_AVAILABLE "Set to OFF to disable use of OpenGL display lists." ${OSG_GL1_AVAILABLE}) OPTION(OSG_GL_MATRICES_AVAILABLE "Set to OFF to disable use of OpenGL built-in matrices." ${OSG_GL1_AVAILABLE}) OPTION(OSG_GL_VERTEX_FUNCS_AVAILABLE "Set to OFF to disable use of OpenGL vertex functions such as glVertex/glColor etc." ${OSG_GL1_AVAILABLE}) +OPTION(OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE "Set to OFF to disable use of OpenGL vertex functions such as glVertex/glColor etc." ${OSG_GL1_AVAILABLE}) OPTION(OSG_GL_FIXED_FUNCTION_AVAILABLE "Set to OFF to disable use of OpenGL fixed function pipeline." ${OSG_GL1_AVAILABLE}) ################################################################################ diff --git a/include/osg/AlphaFunc b/include/osg/AlphaFunc index 703d8e052..a21661517 100644 --- a/include/osg/AlphaFunc +++ b/include/osg/AlphaFunc @@ -16,6 +16,10 @@ #include +#ifndef GL_ALPHA_TEST + #define GL_ALPHA_TEST 0x0BC0 +#endif + namespace osg { /** Encapsulates OpenGL glAlphaFunc. diff --git a/include/osg/ArrayDispatchers b/include/osg/ArrayDispatchers index 92c1a0911..d2c0505f1 100644 --- a/include/osg/ArrayDispatchers +++ b/include/osg/ArrayDispatchers @@ -85,14 +85,22 @@ class OSG_EXPORT ArrayDispatchers : public osg::Referenced void Begin(GLenum mode) { +#ifdef OSG_GL1_AVAILABLE if (_useGLBeginEndAdapter) _glBeginEndAdapter->Begin(mode); else ::glBegin(mode); +#else + _glBeginEndAdapter->Begin(mode); +#endif } void End() { +#ifdef OSG_GL1_AVAILABLE if (_useGLBeginEndAdapter) _glBeginEndAdapter->End(); else ::glEnd(); +#else + _glBeginEndAdapter->End(); +#endif } protected: diff --git a/include/osg/ClipPlane b/include/osg/ClipPlane index fab24d98e..4ebdf73be 100644 --- a/include/osg/ClipPlane +++ b/include/osg/ClipPlane @@ -18,6 +18,10 @@ #include #include +#ifndef GL_CLIP_PLANE0 + #define GL_CLIP_PLANE0 0x3000 +#endif + namespace osg { /** Encapsulates OpenGL glClipPlane(). diff --git a/include/osg/Fog b/include/osg/Fog index d1b07da29..91601fbd1 100644 --- a/include/osg/Fog +++ b/include/osg/Fog @@ -24,6 +24,12 @@ #define GL_FRAGMENT_DEPTH 0x8452 #endif +#ifndef GL_FOG + #define GL_FOG 0x0B60 + #define GL_EXP 0x0800 + #define GL_EXP2 0x0801 +#endif + namespace osg { diff --git a/include/osg/GL b/include/osg/GL index 6f21c528f..2e2dccc5b 100644 --- a/include/osg/GL +++ b/include/osg/GL @@ -101,10 +101,69 @@ #ifdef OSG_GL_MATRICES_AVAILABLE + inline void glLoadMatrix(const float* mat) { glLoadMatrixf(static_cast(mat)); } - inline void glLoadMatrix(const double* mat) { glLoadMatrixd(static_cast(mat)); } inline void glMultMatrix(const float* mat) { glMultMatrixf(static_cast(mat)); } - inline void glMultMatrix(const double* mat) { glMultMatrixd(static_cast(mat)); } + + #ifdef OSG_GLES1_AVAILABLE + inline void glLoadMatrix(const double* mat) + { + GLfloat flt_mat[16]; + for(unsigned int i=0;i<16;++i) flt_mat[i] = mat[i]; + glLoadMatrixf(flt_mat); + } + + inline void glMultMatrix(const double* mat) + { + GLfloat flt_mat[16]; + for(unsigned int i=0;i<16;++i) flt_mat[i] = mat[i]; + glMultMatrixf(flt_mat); + } + + #else + inline void glLoadMatrix(const double* mat) { glLoadMatrixd(static_cast(mat)); } + inline void glMultMatrix(const double* mat) { glMultMatrixd(static_cast(mat)); } + #endif +#endif + +// add defines for OpenGL targets that don't define them, just to ease compatibility across targets +#ifndef GL_DOUBLE + #define GL_DOUBLE 0x140A + typedef double GLdouble; +#endif + +#ifndef GL_INT + #define GL_INT 0x1404 +#endif + +#ifndef GL_UNSIGNED_INT + #define GL_UNSIGNED_INT 0x1405 +#endif + +#ifndef GL_NONE + // OpenGL ES1 doesn't provide GL_NONE + #define GL_NONE 0x0 +#endif + +#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) + #define GL_POLYGON 0x0009 + #define GL_QUADS 0x0007 + #define GL_QUAD_STRIP 0x0008 + + void glDepthRange(double near_val, double far_val) { glDepthRangef(near_val, far_val); } +#endif + +#ifdef OSG_GLES1_AVAILABLE + void glColor4ubv(const GLubyte* c) { glColor4ub(c[0], c[1], c[2], c[3]); } + void glColor3fv(const GLfloat* c) { glColor4f(c[0], c[1], c[2], 1.0f); } + void glColor4fv(const GLfloat* c) { glColor4f(c[0], c[1], c[2], c[3]); } + void glColor3dv(const GLdouble* c) { glColor4f(c[0], c[1], c[2], 1.0f); } + void glColor4dv(const GLdouble* c) { glColor4f(c[0], c[1], c[2], c[3]); } + + void glNormal3bv(const GLbyte* n) { const float div = 1.0f/128.0f; glNormal3f(float(n[0])*div, float(n[1])*div, float(n[3])*div); } + void glNormal3sv(const GLshort* n) { const float div = 1.0f/32768.0f; glNormal3f(float(n[0])*div, float(n[1])*div, float(n[3])*div); } + void glNormal3fv(const GLfloat* n) { glNormal3f(n[0], n[1], n[3]); } + void glNormal3dv(const GLdouble* n) { glNormal3f(n[0], n[1], n[3]); } #endif #endif // __osgGL_h diff --git a/include/osg/GL2Extensions b/include/osg/GL2Extensions index db614d6f3..63ff7433d 100644 --- a/include/osg/GL2Extensions +++ b/include/osg/GL2Extensions @@ -32,9 +32,12 @@ #define GL_SAMPLER_2D_ARRAY_SHADOW_EXT 0x8DC4 #endif -#ifndef GL_VERSION_2_0 -#define GL_VERSION_2_0 1 +#if !defined(GL_VERSION_2_0) typedef char GLchar; +#endif + +#if !defined(GL_VERSION_2_0) && !defined(GL_ES_VERSION_2_0) +#define GL_VERSION_2_0 1 #define GL_BLEND_EQUATION_RGB GL_BLEND_EQUATION #define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 #define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 diff --git a/include/osg/Light b/include/osg/Light index db9d25a13..ac6984eae 100644 --- a/include/osg/Light +++ b/include/osg/Light @@ -18,6 +18,14 @@ #include #include +#ifndef GL_LIGHT0 + #define GL_LIGHT0 0x4000 +#endif + +#ifndef GL_LIGHTING + #define GL_LIGHTING 0x0B50 +#endif + namespace osg { /** Light state class which encapsulates OpenGL glLight() functionality. */ diff --git a/include/osg/LineStipple b/include/osg/LineStipple index c8d889244..1179eaa5a 100644 --- a/include/osg/LineStipple +++ b/include/osg/LineStipple @@ -16,6 +16,10 @@ #include +#ifndef GL_LINE_STIPPLE + #define GL_LINE_STIPPLE 0x0B24 +#endif + namespace osg { class OSG_EXPORT LineStipple : public StateAttribute diff --git a/include/osg/LogicOp b/include/osg/LogicOp index 8b0d53aa2..cd3d5699a 100644 --- a/include/osg/LogicOp +++ b/include/osg/LogicOp @@ -16,6 +16,25 @@ #include +#ifndef OSG_GL_FIXED_FUNCTION_AVAILABLE + #define GL_CLEAR 0x1500 + #define GL_SET 0x150F + #define GL_COPY 0x1503 + #define GL_COPY_INVERTED 0x150C + #define GL_NOOP 0x1505 + #define GL_AND 0x1501 + #define GL_NAND 0x150E + #define GL_OR 0x1507 + #define GL_NOR 0x1508 + #define GL_XOR 0x1506 + #define GL_EQUIV 0x1509 + #define GL_AND_REVERSE 0x1502 + #define GL_AND_INVERTED 0x1504 + #define GL_OR_REVERSE 0x150B + #define GL_OR_INVERTED 0x150D + #define GL_COLOR_LOGIC_OP 0x0BF2 +#endif + namespace osg { /** Encapsulates OpenGL LogicOp state. */ diff --git a/include/osg/Material b/include/osg/Material index f8128abe0..6a2f41a0e 100644 --- a/include/osg/Material +++ b/include/osg/Material @@ -17,6 +17,15 @@ #include #include +#ifndef OSG_GL_FIXED_FUNCTION_AVAILABLE + #define GL_AMBIENT 0x1200 + #define GL_DIFFUSE 0x1201 + #define GL_SPECULAR 0x1202 + #define GL_EMISSION 0x1600 + #define GL_AMBIENT_AND_DIFFUSE 0x1602 + #define GL_COLOR_MATERIAL 0x0B57 +#endif + namespace osg { /** Material - encapsulates OpenGL glMaterial state.*/ class OSG_EXPORT Material : public StateAttribute diff --git a/include/osg/Point b/include/osg/Point index eaddb61cd..dcddc40a8 100644 --- a/include/osg/Point +++ b/include/osg/Point @@ -17,6 +17,10 @@ #include #include +#ifndef GL_POINT_SMOOTH + #define GL_POINT_SMOOTH 0x0B10 +#endif + namespace osg { /** Point - encapsulates the OpenGL point smoothing and size state.*/ diff --git a/include/osg/PolygonMode b/include/osg/PolygonMode index 9534f4271..98d549998 100644 --- a/include/osg/PolygonMode +++ b/include/osg/PolygonMode @@ -17,6 +17,12 @@ #include #include +#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) + #define GL_POINT 0x1B00 + #define GL_LINE 0x1B01 + #define GL_FILL 0x1B02 +#endif + namespace osg { /** State Class for setting OpenGL's polygon culling mode. diff --git a/include/osg/PolygonOffset b/include/osg/PolygonOffset index 6cd149b2a..5a4ce91a7 100644 --- a/include/osg/PolygonOffset +++ b/include/osg/PolygonOffset @@ -52,8 +52,10 @@ class OSG_EXPORT PolygonOffset : public StateAttribute virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const { usage.usesMode(GL_POLYGON_OFFSET_FILL); +#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) usage.usesMode(GL_POLYGON_OFFSET_LINE); usage.usesMode(GL_POLYGON_OFFSET_POINT); +#endif return true; } diff --git a/include/osg/PolygonStipple b/include/osg/PolygonStipple index bc78f85df..5d9720566 100644 --- a/include/osg/PolygonStipple +++ b/include/osg/PolygonStipple @@ -17,6 +17,10 @@ #include +#ifndef GL_POLYGON_STIPPLE + #define GL_POLYGON_STIPPLE 0x0B42 +#endif + namespace osg { diff --git a/include/osg/ShadeModel b/include/osg/ShadeModel index 97be547eb..82b2e4032 100644 --- a/include/osg/ShadeModel +++ b/include/osg/ShadeModel @@ -19,6 +19,11 @@ namespace osg { +#ifndef OSG_GL_FIXED_FUNCTION_AVAILABLE + #define GL_FLAT 0x1D00 + #define GL_SMOOTH 0x1D01 +#endif + /** Class which encapsulates glShadeModel(..). */ class OSG_EXPORT ShadeModel : public StateAttribute diff --git a/include/osg/State b/include/osg/State index 35aecddc7..cbf655cfd 100644 --- a/include/osg/State +++ b/include/osg/State @@ -33,10 +33,6 @@ #include #include -#ifndef GL_TEXTURE0 -#define GL_TEXTURE0 0x84C0 -#endif - #ifndef GL_FOG_COORDINATE_ARRAY #ifdef GL_FOG_COORDINATE_ARRAY_EXT #define GL_FOG_COORDINATE_ARRAY GL_FOG_COORDINATE_ARRAY_EXT @@ -497,32 +493,56 @@ class OSG_EXPORT State : public Referenced, public Observer inline void Vertex(float x, float y, float z, float w=1.0f) { + #if defined(OSG_GL_VERTEX_FUNCS_AVAILABLE) && !defined(OSG_GLES1_AVAILABLE) if (_useVertexAttributeAliasing) _glVertexAttrib4f( _vertexAlias._location, x,y,z,w); else glVertex4f(x,y,z,w); + #else + _glVertexAttrib4f( _vertexAlias._location, x,y,z,w); + #endif } inline void Color(float r, float g, float b, float a=1.0f) { + #ifdef OSG_GL_VERTEX_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) _glVertexAttrib4f( _colorAlias._location, r,g,b,a); else glColor4f(r,g,b,a); + #else + _glVertexAttrib4f( _colorAlias._location, r,g,b,a); + #endif } void Normal(float x, float y, float z) { + #ifdef OSG_GL_VERTEX_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) _glVertexAttrib4f( _normalAlias._location, x,y,z,0.0); else glNormal3f(x,y,z); + #else + _glVertexAttrib4f( _normalAlias._location, x,y,z,0.0); + #endif } void TexCoord(float x, float y=0.0f, float z=0.0f, float w=1.0f) { - if (_useVertexAttributeAliasing) _glVertexAttrib4f( _texCoordAliasList[0]._location, x,y,z,w); - else glTexCoord4f(x,y,z,w); + #if !defined(OSG_GLES1_AVAILABLE) + #ifdef OSG_GL_VERTEX_FUNCS_AVAILABLE + if (_useVertexAttributeAliasing) _glVertexAttrib4f( _texCoordAliasList[0]._location, x,y,z,w); + else glTexCoord4f(x,y,z,w); + #else + _glVertexAttrib4f( _texCoordAliasList[0]._location, x,y,z,w); + #endif + #endif } void MultiTexCoord(unsigned int unit, float x, float y=0.0f, float z=0.0f, float w=1.0f) { - if (_useVertexAttributeAliasing) _glVertexAttrib4f( _texCoordAliasList[unit]._location, x,y,z,w); - else _glMultiTexCoord4f(GL_TEXTURE0+unit,x,y,z,w); + #if !defined(OSG_GLES1_AVAILABLE) + #ifdef OSG_GL_VERTEX_FUNCS_AVAILABLE + if (_useVertexAttributeAliasing) _glVertexAttrib4f( _texCoordAliasList[unit]._location, x,y,z,w); + else _glMultiTexCoord4f(GL_TEXTURE0+unit,x,y,z,w); + #else + _glVertexAttrib4f( _texCoordAliasList[unit]._location, x,y,z,w); + #endif + #endif } void VerteAttrib(unsigned int location, float x, float y=0.0f, float z=0.0f, float w=0.0f) @@ -531,19 +551,16 @@ class OSG_EXPORT State : public Referenced, public Observer } - - /** Wrapper around glInterleavedArrays(..). - * also resets the internal array points and modes within osg::State to keep the other - * vertex array operations consistent. */ - void setInterleavedArrays( GLenum format, GLsizei stride, const GLvoid* pointer); - - /** Mark all the vertex attributes as being disabled but leave the disabling till a later call to applyDisablingOfVertexAttributes.*/ void lazyDisablingOfVertexAttributes(); /** Disable all the vertex attributes that have been marked as to be disabled.*/ void applyDisablingOfVertexAttributes(); + /** Wrapper around glInterleavedArrays(..). + * also resets the internal array points and modes within osg::State to keep the other + * vertex array operations consistent. */ + void setInterleavedArrays( GLenum format, GLsizei stride, const GLvoid* pointer); /** Set the vertex pointer using an osg::Array, and manage any VBO that are required.*/ inline void setVertexPointer(const Array* array) @@ -569,6 +586,7 @@ class OSG_EXPORT State : public Referenced, public Observer inline void setVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *ptr ) { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { setVertexAttribPointer(_vertexAlias._location, size, type, GL_FALSE, stride, ptr); @@ -588,12 +606,16 @@ class OSG_EXPORT State : public Referenced, public Observer _vertexArray._lazy_disable = false; _vertexArray._dirty = false; } + #else + setVertexAttribPointer(_vertexAlias._location, size, type, GL_FALSE, stride, ptr); + #endif } /** wrapper around glDisableClientState(GL_VERTEX_ARRAY). * note, only updates values that change.*/ inline void disableVertexPointer() { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { disableVertexAttribPointer(_vertexAlias._location); @@ -608,10 +630,14 @@ class OSG_EXPORT State : public Referenced, public Observer glDisableClientState(GL_VERTEX_ARRAY); } } + #else + disableVertexAttribPointer(_vertexAlias._location); + #endif } inline void dirtyVertexPointer() { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { dirtyVertexAttribPointer(_vertexAlias._location); @@ -621,6 +647,9 @@ class OSG_EXPORT State : public Referenced, public Observer _vertexArray._pointer = 0; _vertexArray._dirty = true; } + #else + dirtyVertexAttribPointer(_vertexAlias._location); + #endif } @@ -648,6 +677,7 @@ class OSG_EXPORT State : public Referenced, public Observer inline void setNormalPointer( GLenum type, GLsizei stride, const GLvoid *ptr ) { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { setVertexAttribPointer(_normalAlias._location, 3, type, GL_FALSE, stride, ptr); @@ -667,12 +697,16 @@ class OSG_EXPORT State : public Referenced, public Observer _normalArray._lazy_disable = false; _normalArray._dirty = false; } + #else + setVertexAttribPointer(_normalAlias._location, 3, type, GL_FALSE, stride, ptr); + #endif } /** wrapper around glDisableClientState(GL_NORMAL_ARRAY); * note, only updates values that change.*/ inline void disableNormalPointer() { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { disableVertexAttribPointer(_normalAlias._location); @@ -687,10 +721,14 @@ class OSG_EXPORT State : public Referenced, public Observer glDisableClientState(GL_NORMAL_ARRAY); } } + #else + disableVertexAttribPointer(_normalAlias._location); + #endif } inline void dirtyNormalPointer() { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { dirtyVertexAttribPointer(_normalAlias._location); @@ -700,6 +738,9 @@ class OSG_EXPORT State : public Referenced, public Observer _normalArray._pointer = 0; _normalArray._dirty = true; } + #else + dirtyVertexAttribPointer(_normalAlias._location); + #endif } /** Set the color pointer using an osg::Array, and manage any VBO that are required.*/ @@ -727,6 +768,7 @@ class OSG_EXPORT State : public Referenced, public Observer inline void setColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *ptr ) { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { setVertexAttribPointer(_colorAlias._location, size, type, GL_FALSE, stride, ptr); @@ -746,12 +788,16 @@ class OSG_EXPORT State : public Referenced, public Observer _colorArray._lazy_disable = false; _colorArray._dirty = false; } + #else + setVertexAttribPointer(_colorAlias._location, size, type, GL_FALSE, stride, ptr); + #endif } /** wrapper around glDisableClientState(GL_COLOR_ARRAY); * note, only updates values that change.*/ inline void disableColorPointer() { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { disableVertexAttribPointer(_colorAlias._location); @@ -766,10 +812,14 @@ class OSG_EXPORT State : public Referenced, public Observer glDisableClientState(GL_COLOR_ARRAY); } } + #else + disableVertexAttribPointer(_colorAlias._location); + #endif } inline void dirtyColorPointer() { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { dirtyVertexAttribPointer(_colorAlias._location); @@ -779,6 +829,9 @@ class OSG_EXPORT State : public Referenced, public Observer _colorArray._pointer = 0; _colorArray._dirty = true; } + #else + dirtyVertexAttribPointer(_colorAlias._location); + #endif } @@ -812,6 +865,7 @@ class OSG_EXPORT State : public Referenced, public Observer * note, only updates values that change.*/ inline void disableSecondaryColorPointer() { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { disableVertexAttribPointer(_secondaryColorAlias._location); @@ -826,10 +880,14 @@ class OSG_EXPORT State : public Referenced, public Observer if (isSecondaryColorSupported()) glDisableClientState(GL_SECONDARY_COLOR_ARRAY); } } + #else + disableVertexAttribPointer(_secondaryColorAlias._location); + #endif } inline void dirtySecondaryColorPointer() { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { dirtyVertexAttribPointer(_secondaryColorAlias._location); @@ -839,45 +897,11 @@ class OSG_EXPORT State : public Referenced, public Observer _secondaryColorArray._pointer = 0; _secondaryColorArray._dirty = true; } + #else + dirtyVertexAttribPointer(_secondaryColorAlias._location); + #endif } - /** wrapper around glEnableClientState(GL_INDEX_ARRAY);glIndexPointer(..); - * note, only updates values that change.*/ - inline void setIndexPointer( GLenum type, GLsizei stride, - const GLvoid *ptr ) - { - if (!_indexArray._enabled || _indexArray._dirty) - { - _indexArray._enabled = true; - glEnableClientState(GL_INDEX_ARRAY); - } - //if (_indexArray._pointer!=ptr || _indexArray._dirty) - { - _indexArray._pointer=ptr; - glIndexPointer( type, stride, ptr ); - } - _indexArray._dirty = false; - } - - /** wrapper around glDisableClientState(GL_INDEX_ARRAY); - * note, only updates values that change.*/ - inline void disableIndexPointer() - { - if (_indexArray._enabled || _indexArray._dirty) - { - _indexArray._enabled = false; - _indexArray._dirty = false; - glDisableClientState(GL_INDEX_ARRAY); - } - } - - inline void dirtyIndexPointer() - { - _indexArray._pointer = 0; - _indexArray._dirty = true; - } - - inline bool isFogCoordSupported() const { return _isFogCoordSupportResolved?_isFogCoordSupported:computeFogCoordSupported(); } @@ -909,6 +933,7 @@ class OSG_EXPORT State : public Referenced, public Observer * note, only updates values that change.*/ inline void disableFogCoordPointer() { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { disableVertexAttribPointer(_fogCoordAlias._location); @@ -923,10 +948,14 @@ class OSG_EXPORT State : public Referenced, public Observer if (isFogCoordSupported()) glDisableClientState(GL_FOG_COORDINATE_ARRAY); } } + #else + disableVertexAttribPointer(_fogCoordAlias._location); + #endif } inline void dirtyFogCoordPointer() { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { dirtyVertexAttribPointer(_fogCoordAlias._location); @@ -936,6 +965,9 @@ class OSG_EXPORT State : public Referenced, public Observer _fogArray._pointer = 0; _fogArray._dirty = true; } + #else + dirtyVertexAttribPointer(_fogCoordAlias._location); + #endif } @@ -965,6 +997,7 @@ class OSG_EXPORT State : public Referenced, public Observer GLint size, GLenum type, GLsizei stride, const GLvoid *ptr ) { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { setVertexAttribPointer(_texCoordAliasList[unit]._location, size, type, GL_FALSE, stride, ptr); @@ -990,12 +1023,16 @@ class OSG_EXPORT State : public Referenced, public Observer eap._dirty = false; } } + #else + setVertexAttribPointer(_texCoordAliasList[unit]._location, size, type, GL_FALSE, stride, ptr); + #endif } /** wrapper around glDisableClientState(GL_TEXTURE_COORD_ARRAY); * note, only updates values that change.*/ inline void disableTexCoordPointer( unsigned int unit ) { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { disableVertexAttribPointer(_texCoordAliasList[unit]._location); @@ -1016,10 +1053,14 @@ class OSG_EXPORT State : public Referenced, public Observer } } } + #else + disableVertexAttribPointer(_texCoordAliasList[unit]._location); + #endif } inline void dirtyTexCoordPointer( unsigned int unit ) { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { dirtyVertexAttribPointer(_texCoordAliasList[unit]._location); @@ -1031,11 +1072,15 @@ class OSG_EXPORT State : public Referenced, public Observer eap._pointer = 0; eap._dirty = true; } + #else + dirtyVertexAttribPointer(_texCoordAliasList[unit]._location); + #endif } inline void disableTexCoordPointersAboveAndIncluding( unsigned int unit ) { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { disableVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location); @@ -1058,10 +1103,14 @@ class OSG_EXPORT State : public Referenced, public Observer ++unit; } } + #else + disableVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location); + #endif } inline void dirtyTexCoordPointersAboveAndIncluding( unsigned int unit ) { + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (_useVertexAttributeAliasing) { dirtyVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location); @@ -1076,6 +1125,9 @@ class OSG_EXPORT State : public Referenced, public Observer ++unit; } } + #else + dirtyVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location); + #endif } @@ -1483,7 +1535,6 @@ class OSG_EXPORT State : public Referenced, public Observer EnabledArrayPair _normalArray; EnabledArrayPair _colorArray; EnabledArrayPair _secondaryColorArray; - EnabledArrayPair _indexArray; EnabledArrayPair _fogArray; EnabledTexCoordArrayList _texCoordArrayList; EnabledVertexAttribArrayList _vertexAttribArrayList; diff --git a/include/osg/TexEnv b/include/osg/TexEnv index 73602e603..322757fb3 100644 --- a/include/osg/TexEnv +++ b/include/osg/TexEnv @@ -18,6 +18,13 @@ #include #include +#ifndef OSG_GL_FIXED_FUNCTION_AVAILABLE + #define GL_MODULATE 0x2100 + #define GL_ADD 0x0104 + #define GL_MODULATE 0x2100 + #define GL_DECAL 0x2101 +#endif + namespace osg { /** TexEnv encapsulates the OpenGL glTexEnv (texture environment) state. diff --git a/include/osg/TexEnvCombine b/include/osg/TexEnvCombine index 251614c68..47992340a 100644 --- a/include/osg/TexEnvCombine +++ b/include/osg/TexEnvCombine @@ -14,8 +14,7 @@ #ifndef OSG_TEXENVCOMBINE #define OSG_TEXENVCOMBINE 1 -#include -#include +#include #include #include diff --git a/include/osg/TexGen b/include/osg/TexGen index d5fa295f6..d6d3dca4a 100644 --- a/include/osg/TexGen +++ b/include/osg/TexGen @@ -17,12 +17,22 @@ #include #include +#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) + #define GL_OBJECT_LINEAR 0x2401 + #define GL_EYE_LINEAR 0x2400 + #define GL_SPHERE_MAP 0x2402 + #define GL_TEXTURE_GEN_S 0x0C60 + #define GL_TEXTURE_GEN_T 0x0C61 + #define GL_TEXTURE_GEN_R 0x0C62 + #define GL_TEXTURE_GEN_Q 0x0C63 +#endif + #ifndef GL_NORMAL_MAP_ARB -#define GL_NORMAL_MAP_ARB 0x8511 + #define GL_NORMAL_MAP_ARB 0x8511 #endif #ifndef GL_REFLECTION_MAP_ARB -#define GL_REFLECTION_MAP_ARB 0x8512 + #define GL_REFLECTION_MAP_ARB 0x8512 #endif namespace osg { diff --git a/include/osg/Texture b/include/osg/Texture index ec6e5f07e..41b30ccea 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -144,10 +144,20 @@ #define GL_CLAMP_TO_EDGE 0x812F #endif +#ifndef GL_CLAMP + // OpenGL ES1 and ES2 doesn't provide GL_CLAMP but has GL_CLAMP_TO_EDGE + #define GL_CLAMP GL_CLAMP_TO_EDGE +#endif + #ifndef GL_CLAMP_TO_BORDER_ARB #define GL_CLAMP_TO_BORDER_ARB 0x812D #endif +#ifndef GL_INTENSITY + // OpenGL ES1 and ES2 doesn't provide GL_INTENSITY + #define GL_INTENSITY 0x8049 +#endif + #ifndef GL_GENERATE_MIPMAP_SGIS #define GL_GENERATE_MIPMAP_SGIS 0x8191 #define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192 diff --git a/include/osg/Texture1D b/include/osg/Texture1D index b62ae9111..1397a9ef5 100644 --- a/include/osg/Texture1D +++ b/include/osg/Texture1D @@ -18,6 +18,10 @@ #include +#ifndef GL_TEXTURE_1D + #define GL_TEXTURE_1D 0x0DE0 +#endif + namespace osg { /** Encapsulates OpenGl 1D texture functionality. Doesn't support cube maps, diff --git a/include/osg/Uniform b/include/osg/Uniform index 09659ae50..4b05a745b 100644 --- a/include/osg/Uniform +++ b/include/osg/Uniform @@ -29,6 +29,15 @@ #include #include +#ifndef GL_SAMPLER_1D + #define GL_SAMPLER_1D 0x8B5D + #define GL_SAMPLER_2D 0x8B5E + #define GL_SAMPLER_3D 0x8B5F + #define GL_SAMPLER_1D_SHADOW 0x8B61 + #define GL_SAMPLER_2D_SHADOW 0x8B62 +#endif + + namespace osg { // forward declare diff --git a/src/osg/ArrayDispatchers.cpp b/src/osg/ArrayDispatchers.cpp index 711ec13f8..4a01d45b8 100644 --- a/src/osg/ArrayDispatchers.cpp +++ b/src/osg/ArrayDispatchers.cpp @@ -400,15 +400,19 @@ void ArrayDispatchers::init() _secondaryColorDispatchers = new AttributeDispatchMap(&(_state->getGLBeginEndAdapter())); _fogCoordDispatchers = new AttributeDispatchMap(&(_state->getGLBeginEndAdapter())); - Drawable::Extensions* extensions = Drawable::getExtensions(_state->getContextID(),true); _glBeginEndAdapter = &(_state->getGLBeginEndAdapter()); _useGLBeginEndAdapter = false; - _vertexDispatchers->assign(Array::Vec2ArrayType, glVertex2fv, 2); - _vertexDispatchers->assign(Array::Vec3ArrayType, glVertex3fv, 3); - _vertexDispatchers->assign(Array::Vec2dArrayType, glVertex2dv, 2); - _vertexDispatchers->assign(Array::Vec3dArrayType, glVertex3dv, 3); - _vertexDispatchers->assignGLBeginEnd(Array::Vec3ArrayType, &GLBeginEndAdapter::Vertex3fv, 3); +#ifdef OSG_GL_VERTEX_FUNCS_AVAILABLE + Drawable::Extensions* extensions = Drawable::getExtensions(_state->getContextID(),true); + + #ifndef OSG_GLES1_AVAILABLE + _vertexDispatchers->assign(Array::Vec2ArrayType, glVertex2fv, 2); + _vertexDispatchers->assign(Array::Vec3ArrayType, glVertex3fv, 3); + _vertexDispatchers->assign(Array::Vec2dArrayType, glVertex2dv, 2); + _vertexDispatchers->assign(Array::Vec3dArrayType, glVertex3dv, 3); + _vertexDispatchers->assignGLBeginEnd(Array::Vec3ArrayType, &GLBeginEndAdapter::Vertex3fv, 3); + #endif _normalDispatchers->assign(Array::Vec3bArrayType, glNormal3bv, 3); _normalDispatchers->assign(Array::Vec3sArrayType, glNormal3sv, 3); @@ -427,6 +431,7 @@ void ArrayDispatchers::init() _secondaryColorDispatchers->assign(Array::Vec3ArrayType, extensions->_glSecondaryColor3fv, 3); _fogCoordDispatchers->assign(Array::FloatArrayType, extensions->_glFogCoordfv, 1); +#endif // pre allocate. _activeDispatchList.resize(5); @@ -483,8 +488,8 @@ AttributeDispatch* ArrayDispatchers::vertexAttribDispatcher(unsigned int unit, A void ArrayDispatchers::assignTexCoordDispatchers(unsigned int unit) { +#if defined(OSG_GL_VERTEX_FUNCS_AVAILABLE) && !defined(OSG_GLES1_AVAILABLE) Drawable::Extensions* extensions = Drawable::getExtensions(_state->getContextID(),true); - for(unsigned int i=_texCoordDispatchers.size(); i<=unit; ++i) { _texCoordDispatchers.push_back(new AttributeDispatchMap(_glBeginEndAdapter)); @@ -512,6 +517,7 @@ void ArrayDispatchers::assignTexCoordDispatchers(unsigned int unit) texCoordDispatcher.targetGLBeginEndAssign((GLenum)(GL_TEXTURE0+i), Array::Vec4ArrayType, &GLBeginEndAdapter::MultiTexCoord4fv, 4); } } +#endif } void ArrayDispatchers::assignVertexAttribDispatchers(unsigned int unit) diff --git a/src/osg/ClipPlane.cpp b/src/osg/ClipPlane.cpp index ec08292eb..05a1a47a7 100644 --- a/src/osg/ClipPlane.cpp +++ b/src/osg/ClipPlane.cpp @@ -75,7 +75,7 @@ unsigned int ClipPlane::getClipPlaneNum() const void ClipPlane::apply(State&) const { -#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE +#if defined(OSG_GL_FIXED_FUNCTION_AVAILABLE) && !defined(OSG_GLES1_AVAILABLE) glClipPlane((GLenum)(GL_CLIP_PLANE0+_clipPlaneNum),_clipPlane.ptr()); #else osg::notify(osg::NOTICE)<<"Warning: ClipPlane::apply(State&) - not supported."< #include #include +#include #include #include #include +#include #include #include #include "dxtctool.h" +#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) +#define GL_BITMAP 0x1A00 +#define GL_RED 0x1903 +#define GL_GREEN 0x1904 +#define GL_BLUE 0x1905 +#define GL_COLOR_INDEX 0x1900 +#define GL_DEPTH_COMPONENT 0x1902 +#define GL_INTENSITY12 0x804C +#define GL_INTENSITY16 0x804D +#define GL_INTENSITY4 0x804A +#define GL_INTENSITY8 0x804B +#define GL_LUMINANCE12 0x8041 +#define GL_LUMINANCE12_ALPHA4 0x8046 +#define GL_LUMINANCE12_ALPHA12 0x8047 +#define GL_LUMINANCE16 0x8042 +#define GL_LUMINANCE16_ALPHA16 0x8048 +#define GL_LUMINANCE4 0x803F +#define GL_LUMINANCE4_ALPHA4 0x8043 +#define GL_LUMINANCE6_ALPHA2 0x8044 +#define GL_LUMINANCE8 0x8040 +#define GL_LUMINANCE8_ALPHA8 0x8045 +#define GL_STENCIL_INDEX 0x1901 +#define GL_RGBA8 0x8058 +#endif + using namespace osg; using namespace std; @@ -682,6 +709,7 @@ void Image::readPixels(int x,int y,int width,int height, void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMapsIfAvailable, GLenum type) { +#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) // osg::notify(osg::NOTICE)<<"Image::readImageFromCurrentTexture()"<isTexture2DArraySupported()) { glGetBooleanv(GL_TEXTURE_BINDING_2D_ARRAY_EXT, &binding2DArray); } - else - { - binding2DArray = GL_FALSE; - } GLenum textureMode = binding1D ? GL_TEXTURE_1D : binding2D ? GL_TEXTURE_2D : binding3D ? GL_TEXTURE_3D : binding2DArray ? GL_TEXTURE_2D_ARRAY_EXT : 0; @@ -873,137 +897,134 @@ void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMaps dirty(); } +#else + osg::notify(osg::NOTICE)<<"Warning: Image::readImageFromCurrentTexture() not supported."<s(),t_offset+source->t(),r_offset+source->r(), + source->getPixelFormat(),source->getDataType(), + source->getPacking()); + } + + if (s_offset>=_s || t_offset>=_t || r_offset>=_r) + { + notify(WARN)<<"Warning: offsets passed to Image::copySubImage(..) outside destination image, operation ignored."<getPixelFormat()) + { + notify(WARN)<<"Warning: image with an incompatible pixel formats passed to Image::copySubImage(..), operation ignored."<getPacking()); + glPixelStorei(GL_PACK_ROW_LENGTH,_s); + + glPixelStorei(GL_UNPACK_ALIGNMENT,_packing); + + GLint status = gluScaleImage(_pixelFormat, + source->s(), + source->t(), + source->getDataType(), + source->data(), + source->s(), + source->t(), + _dataType, + data_destination); + + glPixelStorei(GL_PACK_ROW_LENGTH,0); + + if (status!=0) + { + notify(WARN) << "Error Image::scaleImage() do not succeed : errorString = "<s(),t_offset+source->t(),r_offset+source->r(), - source->getPixelFormat(),source->getDataType(), - source->getPacking()); - } - - if (s_offset>=_s || t_offset>=_t || r_offset>=_r) - { - notify(WARN)<<"Warning: offsets passed to Image::copySubImage(..) outside destination image, operation ignored."<getPixelFormat()) - { - notify(WARN)<<"Warning: image with an incompatible pixel formats passed to Image::copySubImage(..), operation ignored."<getPacking()); - glPixelStorei(GL_PACK_ROW_LENGTH,_s); - - glPixelStorei(GL_UNPACK_ALIGNMENT,_packing); - - GLint status = gluScaleImage(_pixelFormat, - source->s(), - source->t(), - source->getDataType(), - source->data(), - source->s(), - source->t(), - _dataType, - data_destination); - - glPixelStorei(GL_PACK_ROW_LENGTH,0); - - if (status!=0) - { - notify(WARN) << "Error Image::scaleImage() do not succeed : errorString = "<=0; @@ -66,7 +71,10 @@ void LightModel::apply(State&) const } } + #ifndef OSG_GLES1_AVAILABLE glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,_localViewer); + #endif + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,_twoSided); #else osg::notify(osg::NOTICE)<<"Warning: LightModel::apply(State&) - not supported."<set(*_projection); updateModelViewAndProjectionMatrixUniforms(); } - +#ifdef OSG_GL_MATRICES_AVAILABLE glMatrixMode( GL_PROJECTION ); glLoadMatrix(_projection->ptr()); glMatrixMode( GL_MODELVIEW ); +#endif } } @@ -1228,7 +1237,9 @@ void State::applyModelViewMatrix(const osg::RefMatrix* matrix) updateModelViewAndProjectionMatrixUniforms(); } +#ifdef OSG_GL_MATRICES_AVAILABLE glLoadMatrix(_modelView->ptr()); +#endif } } diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index 8648d5387..0567de9f1 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -21,11 +21,14 @@ #include #include #include +#include #include #include #include #include +#include +#include #include #include #include @@ -789,7 +792,7 @@ void StateSet::setMode(StateAttribute::GLMode mode, StateAttribute::GLModeValue { notify(NOTICE)<<"Error: Setting mode 'GL_COLOR_MATERIAL' via osg::StateSet::setMode(mode,value) ignored.\n"; notify(NOTICE)<<" The mode 'GL_COLOR_MATERIAL' is set by the osg::Material StateAttribute.\n"; - notify(NOTICE)<<" Setting this as a mode fools osg's State tracking."< #include #include +#include #include #include @@ -1589,6 +1590,12 @@ void Texture::applyTexParameters(GLenum target, State& state) const if (extensions->isTextureBorderClampSupported()) { + + #ifndef GL_TEXTURE_BORDER_COLOR + #define GL_TEXTURE_BORDER_COLOR 0x1004 + #endif + + if (_internalFormatType == SIGNED_INTEGER) { GLint color[4] = {(GLint)_borderColor.r(), (GLint)_borderColor.g(), (GLint)_borderColor.b(), (GLint)_borderColor.a()}; @@ -1726,22 +1733,25 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima case GL_COMPRESSED_INTENSITY: _internalFormat = GL_INTENSITY; break; } } - + glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking()); - + bool useClientStorage = extensions->isClientStorageSupported() && getClientStorageHint(); if (useClientStorage) { glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE,GL_TRUE); - glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_PRIORITY,0.0f); - + + #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) + glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_PRIORITY,0.0f); + #endif + #ifdef GL_TEXTURE_STORAGE_HINT_APPLE glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_STORAGE_HINT_APPLE , GL_STORAGE_CACHED_APPLE); #endif } - + unsigned char* dataPtr = (unsigned char*)image->data(); - + // osg::notify(osg::NOTICE)<<"inwidth="<getFileName()"<getFileName()<s() || inheight!=image->t(); diff --git a/src/osg/Texture1D.cpp b/src/osg/Texture1D.cpp index c4bc5d6c3..5ebc811b8 100644 --- a/src/osg/Texture1D.cpp +++ b/src/osg/Texture1D.cpp @@ -119,7 +119,7 @@ void Texture1D::setImage(Image* image) void Texture1D::apply(State& state) const { - +#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) // get the contextID (user defined ID of 0 upwards) for the // current OpenGL context. const unsigned int contextID = state.getContextID(); @@ -229,6 +229,9 @@ void Texture1D::apply(State& state) const { generateMipmap(state); } +#else + osg::notify(osg::NOTICE)<<"Warning: Texture1D::apply(State& state) not supported."<data()) return; @@ -348,10 +352,14 @@ void Texture1D::applyTexImage1D(GLenum target, Image* image, State& state, GLsiz } inwidth = image->s(); +#else + osg::notify(osg::NOTICE)<<"Warning: Texture1D::applyTexImage1D(State& state) not supported."<