aboutsummaryrefslogtreecommitdiff
path: root/Gem/develop/include/Gem/Gem/State.h
blob: b09ace4366ad09387f84d16841a576f761dfaaa2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*-----------------------------------------------------------------
  LOG
  GEM - Graphics Environment for Multimedia

  The state to pass among GEM objects

  Copyright (c) 1997-2000 Mark Danks. mark@danks.org
  Copyright (c) Günther Geiger. geiger@epy.co.at
  Copyright (c) 2001-2011 IOhannes m zmölnig. forum::für::umläute. IEM. zmoelnig@iem.at
  For information on usage and redistribution, and for a DISCLAIMER OF ALL
  WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.

  -----------------------------------------------------------------*/

#ifndef _INCLUDE__GEM_GEM_STATE_H_
#define _INCLUDE__GEM_GEM_STATE_H_

#include "Gem/ExportDef.h"
#include "Gem/GemGL.h"

#include "Gem/RTE.h"
#include "Utils/any.h"

struct pixBlock;
class TexCoord;

/*-----------------------------------------------------------------
  -------------------------------------------------------------------
  CLASS
  TexCoord


  DESCRIPTION

  -----------------------------------------------------------------*/
class GEM_EXTERN TexCoord
{
public:
  TexCoord() : s(0.f), t(0.f) { }
  TexCoord(float s_, float t_) : s(s_), t(t_) { }
  float         s;
  float         t;
};


/*-----------------------------------------------------------------
  -------------------------------------------------------------------
  CLASS
  GemState

  The state to pass among GEM objects

  DESCRIPTION

  -----------------------------------------------------------------*/

class GemStateData;
class GEM_EXTERN GemState
{
public:
  typedef enum {
    _ILLEGAL=-1,
    _DIRTY, /* "dirty" */
    _TIMING_TICK, /* "timing.tick" */
    _PIX, /* "pix" */
    _GL_STACKS, /* "stacks" */
    _GL_DISPLAYLIST, /* */
    _GL_LIGHTING, /* */
    _GL_SMOOTH, /* */
    _GL_DRAWTYPE, /* */
    _GL_TEX_TYPE, /* "tex.type" */
    _GL_TEX_COORDS, /* "tex.coords" */
    _GL_TEX_NUMCOORDS, /* "tex.numcoords" */
    _GL_TEX_UNITS,       /* "tex.units" <int> # of texUnits */
    _GL_TEX_ORIENTATION, /* "tex.orientation" <bool> false=bottomleft; true=topleft */
    _GL_TEX_BASECOORD,   /* "tex.basecoords" <TexCoord> width/height of texture  */




    _LAST
  } key_t;

  //////////
  // Has something changed since the last time?
  // deprecated: use property 'dirty' instead
  GEM_DEPRECATED  bool                 dirty;

  //////////
  // Are we in a display list creation?
  // deprecated: use property 'gl.displaylist' instead
  GEM_DEPRECATED  bool              inDisplayList;

  //////////
  // Lighting on?
  // deprecated: use property 'gl.lighting' instead
  GEM_DEPRECATED  bool              lighting;

  //////////
  // Smooth shading (flat is other type)
  // deprecated: use property 'gl.smooth' instead
  GEM_DEPRECATED  bool              smooth;

  //////////
  // Texture mapping on?
  // 0..off
  // 1..normalized texture
  // 2..rectangle texture
  // deprecated: use property 'gl.tex.type' instead
  GEM_DEPRECATED  int               texture;

  //////////
  // The image to texture map
  // deprecated: use property 'pix' instead
  GEM_DEPRECATED  pixBlock              *image;

  //////////
  // Texture coordinates.
  // This can be NULL if there aren't any coordinates
  // deprecated: use property 'gl.tex.coords' instead
  GEM_DEPRECATED  TexCoord          *texCoords;

  //////////
  // The number of TexCoords
  // deprecated: use property 'gl.tex.numcoords' instead
  GEM_DEPRECATED  int               numTexCoords;

  //////////
  // The number of multiTexUnits
  //   default = 0, max = 7
  // deprecated: use property 'gl.tex.units' instead
  GEM_DEPRECATED  int               multiTexUnits;

  //////////
  // Milliseconds since last frame
  // If in Stereoscopic mode, then it is the same number for both left
  //            and right renderings
  // deprecated: use property 'timing.tick' instead
  GEM_DEPRECATED  float                         tickTime;

  //////////////////
  // the default draw-type (might be overridden within a Geo)
  // deprecated: use property 'gl.drawtype' instead
  GEM_DEPRECATED  GLenum                                drawType;

  //////////
  // how deep is the current stack /* 4 fields for the 4 stacks */
  // deprecated: use property 'gl.stacks' instead
  GEM_DEPRECATED  int stackDepth[4];

  ////////////
  //vertex-array data
  // deprecated: use property 'vertex.dirty' instead
  GEM_DEPRECATED  int
  VertexDirty; // the vertex-arrays has changed
  // deprecated: use property 'vertex.array.vertex' instead
  GEM_DEPRECATED  GLfloat                               *VertexArray;
  // deprecated: use property 'vertex.array.vertex' instead
  GEM_DEPRECATED  int                                   VertexArraySize;
  // deprecated: use property 'vertex.array.vertex' instead
  GEM_DEPRECATED  int                                   VertexArrayStride;

  // deprecated: use property 'vertex.array.color' instead
  GEM_DEPRECATED  GLfloat                               *ColorArray;
  // deprecated: use property 'vertex.array.color' instead
  GEM_DEPRECATED  bool                                  HaveColorArray;

  // deprecated: use property 'vertex.array.normal' instead
  GEM_DEPRECATED  GLfloat                               *NormalArray;
  // deprecated: use property 'vertex.array.normal' instead
  GEM_DEPRECATED  bool                                  HaveNormalArray;

  // deprecated: use property 'vertex.array.texcoord' instead
  GEM_DEPRECATED  GLfloat                               *TexCoordArray;
  // deprecated: use property 'vertex.array.texcoord' instead
  GEM_DEPRECATED  bool                                  HaveTexCoordArray;

  //////////
  // Constructor
  GemState(void);
  GemState(const GemState&);

  //////////
  // Destructor
  virtual ~GemState(void);

  float texCoordX(int num) const;

  float texCoordY(int num) const;

  /* reset (parts of?) the GemState: to be called from [gemhead] */
  void reset(void);


  /* get a named property */
  /* if the property exists (as the given type),
   * the value of the 2nd argument is set accordingly and <code>true</code> is returned
   * if the key does not exist (or the type is wrong) the value is not touched and <code>false</code> is returned instead
   */
  virtual bool get(const key_t key, gem::any&value);

  template<class T>
  bool get(const key_t key, T&value)
  {
    try {
      gem::any val;
      if(!get(key,val)) {
        // key not found
        return false;
      }
      value=gem::any_cast<T>(val);
      return true;
    } catch (gem::bad_any_cast&x) {
      ::verbose(3, "%s:%d [%s] %d :: %s", __FILE__, __LINE__, __FUNCTION__, key,
                x.what());
      // type problem
    }
    return false;
  };
  /* set a named property */
  virtual bool set(const key_t key, gem::any value);
  /* remove a named property */
  virtual bool remove(const key_t key);

  // Copy assignment
  GemState& operator=(const GemState&);

  static const key_t getKey(const std::string&);

protected:
  GemStateData*data;
};

#endif  // for header file