OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GLBeginEndAdapter.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef OSG_GLBeginEndAdapter
15 #define OSG_GLBeginEndAdapter 1
16 
17 #include <osg/ref_ptr>
18 #include <osg/Array>
19 #include <osg/Matrixd>
20 
21 #ifndef GL_TEXTURE0
22 #define GL_TEXTURE0 0x84C0
23 #endif
24 
25 namespace osg {
26 
27 // forward declare
28 class State;
29 
32 {
33  public:
34 
35  GLBeginEndAdapter(State* state=0);
36 
37  void setState(State* state) { _state = state; }
38  State* getState() { return _state; }
39  const State* getState() const { return _state; }
40 
42  {
44  APPLY_LOCAL_MATRICES_TO_MODELVIEW
45  };
46 
47  void setMatrixMode(MatrixMode mode) { _mode = mode; }
48  MatrixMode setMatrixMode() const { return _mode; }
49 
50  void PushMatrix();
51  void PopMatrix();
52 
53  void LoadIdentity();
54  void LoadMatrixd(const GLdouble* m);
55  void MultMatrixd(const GLdouble* m);
56 
57  void Translatef(GLfloat x, GLfloat y, GLfloat z) { Translated(x,y,z); }
58  void Scalef(GLfloat x, GLfloat y, GLfloat z) { Scaled(x,y,z); }
59  void Rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { Rotated(angle,x,y,z); }
60 
61  void Translated(GLdouble x, GLdouble y, GLdouble z);
62  void Scaled(GLdouble x, GLdouble y, GLdouble z);
63  void Rotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
64 
65  void Vertex3f(GLfloat x, GLfloat y, GLfloat z);
66  void Vertex3fv(const GLfloat* v) { Vertex3f(v[0], v[1], v[2]); }
67 
68  void Vertex3dv(GLdouble x, GLdouble y, GLdouble z) { Vertex3f(x,y,z); }
69  void Vertex3dv(const GLdouble* v) { Vertex3f(v[0], v[1], v[2]); }
70 
71  void Color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
72  {
73  _overallColorAssigned = true;
74  _colorAssigned = true;
75  _color.set(red,green,blue,alpha);
76  }
77 
78  void Color3fv(const GLfloat* c) { Color4f(c[0], c[1], c[2], 1); }
79  void Color4fv(const GLfloat* c) { Color4f(c[0], c[1], c[2], c[3]); }
80  void Color4ubv(const GLubyte* c) { const float div = 1.0f/255.0f; Color4f(float(c[0])*div, float(c[1])*div, float(c[2])*div, float(c[3])*div); }
81 
82  void Normal3f(GLfloat x, GLfloat y, GLfloat z)
83  {
84  _overallNormalAssigned = true;
85  _normalAssigned = true;
86  _normal.set(x,y,z);
87  }
88 
89  void Normal3fv(const GLfloat* n) { Normal3f(n[0], n[1], n[2]); }
90 
91  void TexCoord1f(GLfloat x) { MultiTexCoord4f(GL_TEXTURE0, x, 0.0f, 0.0f, 1.0f); }
92  void TexCoord1fv(const GLfloat* tc) { MultiTexCoord4f(GL_TEXTURE0, tc[0], 0.0f, 0.0f, 1.0f); }
93 
94  void TexCoord2f(GLfloat x, GLfloat y) { MultiTexCoord4f(GL_TEXTURE0, x, y, 0.0f, 1.0f); }
95  void TexCoord2fv(const GLfloat* tc) { MultiTexCoord4f(GL_TEXTURE0, tc[0], tc[1], 0.0f, 1.0f); }
96 
97  void TexCoord3f(GLfloat x, GLfloat y, GLfloat z) { MultiTexCoord4f(GL_TEXTURE0, x, y, z, 1.0f); }
98  void TexCoord3fv(const GLfloat* tc) { MultiTexCoord4f(GL_TEXTURE0, tc[0], tc[1], tc[2], 1.0f); }
99 
100  void TexCoord4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) { MultiTexCoord4f(GL_TEXTURE0, x, y, z, w); }
101  void TexCoord4fv(const GLfloat* tc) { MultiTexCoord4f(GL_TEXTURE0, tc[0], tc[1], tc[2], tc[3]); }
102 
103  void MultiTexCoord1f(GLenum target, GLfloat x) { MultiTexCoord4f(target, x, 0.0f, 0.0f, 1.0f); }
104  void MultiTexCoord1fv(GLenum target, const GLfloat* tc) { MultiTexCoord4f(target, tc[0], 0.0f, 0.0f, 1.0f); }
105 
106  void MultiTexCoord2f(GLenum target, GLfloat x, GLfloat y) { MultiTexCoord4f(target, x, y, 0.0f, 1.0f); }
107  void MultiTexCoord2fv(GLenum target, const GLfloat* tc) { MultiTexCoord4f(target, tc[0],tc[1], 0.0f, 1.0f); }
108 
109  void MultiTexCoord3f(GLenum target, GLfloat x, GLfloat y, GLfloat z) {MultiTexCoord4f(target, x, y, z, 1.0f); }
110  void MultiTexCoord3fv(GLenum target, const GLfloat* tc) { MultiTexCoord4f(target, tc[0], tc[1], tc[2], 1.0f); }
111 
112  void MultiTexCoord4f(GLenum target, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
113  void MultiTexCoord4fv(GLenum target, const GLfloat* tc) { MultiTexCoord4f(target, tc[0], tc[1], tc[2], tc[3]); }
114 
115  void VertexAttrib1f(GLuint unit, GLfloat x) { VertexAttrib4f(unit, x, 0.0f, 0.0f, 0.0f); }
116  void VertexAttrib1fv(GLuint unit, const GLfloat* tc) { VertexAttrib4f(unit, tc[0], 0.0f, 0.0f, 0.0f); }
117 
118  void VertexAttrib2f(GLuint unit, GLfloat x, GLfloat y) { VertexAttrib4f(unit, x, y, 0.0f, 0.0f); }
119  void VertexAttrib2fv(GLuint unit, const GLfloat* tc) { VertexAttrib4f(unit, tc[0],tc[1], 0.0f, 0.0f); }
120 
121  void VertexAttrib3f(GLuint unit, GLfloat x, GLfloat y, GLfloat z) {VertexAttrib4f(unit, x, y, z, 0.0f); }
122  void VertexAttrib3fv(GLuint unit, const GLfloat* tc) { VertexAttrib4f(unit, tc[0], tc[1], tc[2], 0.0f); }
123 
124  void VertexAttrib4f(GLuint unit, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
125  void VertexAttrib4fv(GLuint unit, const GLfloat* tc) { VertexAttrib4f(unit, tc[0], tc[1], tc[2], tc[3]); }
126 
127  void Begin(GLenum mode);
128  void End();
129 
130  void reset();
131 
132  protected:
133 
135 
137 
138  typedef std::list<Matrixd> MatrixStack;
139  MatrixStack _matrixStack;
140 
143 
146 
151 
152  typedef std::vector<bool> AssignedList;
153  typedef std::vector<osg::Vec4f> VertexList;
154 
155  AssignedList _texCoordAssignedList;
156  VertexList _texCoordList;
157 
159  VertexList _vertexAttribList;
160 
161 
162  typedef std::vector< osg::ref_ptr<Vec4Array> > VertexArrayList;
163 
168  VertexArrayList _texCoordsList;
169  VertexArrayList _vertexAttribsList;
170 };
171 
172 }
173 
174 #endif
#define OSG_EXPORT
Definition: Export.h:43
void MultiTexCoord1f(GLenum target, GLfloat x)
VertexArrayList _vertexAttribsList
osg::ref_ptr< osg::Vec3Array > _vertices
void Rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
void Normal3f(GLfloat x, GLfloat y, GLfloat z)
void MultiTexCoord3f(GLenum target, GLfloat x, GLfloat y, GLfloat z)
#define GL_TEXTURE0
AssignedList _vertexAttribAssignedList
void Vertex3dv(GLdouble x, GLdouble y, GLdouble z)
osg::ref_ptr< osg::Vec3Array > _normals
MatrixMode setMatrixMode() const
void Translatef(GLfloat x, GLfloat y, GLfloat z)
void TexCoord4fv(const GLfloat *tc)
void Scalef(GLfloat x, GLfloat y, GLfloat z)
void MultiTexCoord2fv(GLenum target, const GLfloat *tc)
void VertexAttrib3f(GLuint unit, GLfloat x, GLfloat y, GLfloat z)
void TexCoord1f(GLfloat x)
void Color3fv(const GLfloat *c)
void MultiTexCoord2f(GLenum target, GLfloat x, GLfloat y)
void VertexAttrib1fv(GLuint unit, const GLfloat *tc)
osg::ref_ptr< osg::Vec4Array > _colors
AssignedList _texCoordAssignedList
void Color4ubv(const GLubyte *c)
double GLdouble
Definition: GL.h:159
void TexCoord4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
void VertexAttrib4fv(GLuint unit, const GLfloat *tc)
void TexCoord2f(GLfloat x, GLfloat y)
void Color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
void TexCoord2fv(const GLfloat *tc)
void MultiTexCoord3fv(GLenum target, const GLfloat *tc)
void TexCoord1fv(const GLfloat *tc)
const State * getState() const
void VertexAttrib3fv(GLuint unit, const GLfloat *tc)
std::vector< bool > AssignedList
void setMatrixMode(MatrixMode mode)
std::vector< osg::Vec4f > VertexList
void TexCoord3f(GLfloat x, GLfloat y, GLfloat z)
Definition: AlphaFunc.h:19
void Color4fv(const GLfloat *c)
std::list< Matrixd > MatrixStack
void VertexAttrib1f(GLuint unit, GLfloat x)
void Vertex3fv(const GLfloat *v)
void VertexAttrib2fv(GLuint unit, const GLfloat *tc)
void MultiTexCoord1fv(GLenum target, const GLfloat *tc)
void Normal3fv(const GLfloat *n)
void MultiTexCoord4fv(GLenum target, const GLfloat *tc)
VertexArrayList _texCoordsList
void VertexAttrib2f(GLuint unit, GLfloat x, GLfloat y)
void setState(State *state)
void Vertex3dv(const GLdouble *v)
std::vector< osg::ref_ptr< Vec4Array > > VertexArrayList
void TexCoord3fv(const GLfloat *tc)