00001 #ifndef GL_WRAPPER_H
00002 #define GL_WRAPPER_H
00003
00004 #ifdef USE_TILE
00005
00006 #include "tiletex.h"
00007
00008 #include <stdlib.h>
00009 #include <vector>
00010
00011 struct coord_def;
00012
00013 struct VColour
00014 {
00015 VColour() {}
00016 VColour(unsigned char _r, unsigned char _g, unsigned char _b,
00017 unsigned char _a = 255) : r(_r), g(_g), b(_b), a(_a) {}
00018 VColour(const VColour &vc) : r(vc.r), g(vc.g), b(vc.b), a(vc.a) {}
00019
00020 inline void set(const VColour &in)
00021 {
00022 r = in.r;
00023 g = in.g;
00024 b = in.b;
00025 a = in.a;
00026 }
00027
00028 bool operator==(const VColour &vc) const;
00029 bool operator!=(const VColour &vc) const;
00030
00031 unsigned char r;
00032 unsigned char g;
00033 unsigned char b;
00034 unsigned char a;
00035
00036 static VColour white;
00037 static VColour black;
00038 static VColour transparent;
00039 };
00040
00041 struct GLW_2VF
00042 {
00043 GLW_2VF() {}
00044 GLW_2VF(float l, float m) : x(l), y(m) {}
00045
00046 inline void set(float l, float m)
00047 {
00048 x = l;
00049 y = m;
00050 }
00051
00052 inline void set(const GLW_2VF &in)
00053 {
00054 x = in.x;
00055 y = in.y;
00056 }
00057
00058 float x;
00059 float y;
00060 };
00061
00062 struct GLW_3VF
00063 {
00064 GLW_3VF() {}
00065 GLW_3VF(float l, float m, float n) : x(l), y(m), z(n) {}
00066 GLW_3VF(float l, float m) : x(l), y(m), z(0.0) {}
00067
00068 inline void set(float l, float m, float n = 0.0)
00069 {
00070 x = l;
00071 y = m;
00072 z = n;
00073 }
00074
00075 inline void set(const GLW_3VF &in)
00076 {
00077 x = in.x;
00078 y = in.y;
00079 z = in.z;
00080 }
00081
00082 float x;
00083 float y;
00084 float z;
00085 };
00086
00087 enum drawing_modes
00088 {
00089 GLW_LINES,
00090 GLW_RECTANGLE,
00091 };
00092
00093
00094 class GLWPrim
00095 {
00096 public:
00097
00098 GLWPrim(float sx, float sy, float ex, float ey, float z = 0.0f) :
00099 pos_sx(sx), pos_sy(sy), pos_ex(ex), pos_ey(ey), pos_z(z),
00100 tex_sx(0.0f), tex_sy(0.0f), tex_ex(0.0f), tex_ey(0.0f),
00101 col_s(VColour::white), col_e(VColour::white) {}
00102
00103 inline void set_tex(float sx, float sy, float ex, float ey)
00104 {
00105 tex_sx = sx;
00106 tex_sy = sy;
00107 tex_ex = ex;
00108 tex_ey = ey;
00109 }
00110
00111 inline void set_col(const VColour &vc)
00112 {
00113 col_s = vc;
00114 col_e = vc;
00115 }
00116
00117 inline void set_col(const VColour &s, const VColour &e)
00118 {
00119 col_s = s;
00120 col_e = e;
00121 }
00122
00123 float pos_sx, pos_sy, pos_ex, pos_ey, pos_z;
00124 float tex_sx, tex_sy, tex_ex, tex_ey;
00125 VColour col_s, col_e;
00126 };
00127
00128
00129
00130
00131
00132
00133 struct GLState
00134 {
00135 GLState();
00136 GLState(const GLState &state);
00137
00138 const GLState &operator=(const GLState &state);
00139 bool operator==(const GLState &state) const;
00140
00141
00142 bool array_vertex;
00143 bool array_texcoord;
00144 bool array_colour;
00145
00146
00147 bool blend;
00148 bool texture;
00149 bool depthtest;
00150 bool alphatest;
00151 unsigned char alpharef;
00152 VColour colour;
00153 };
00154
00155 class GLStateManager
00156 {
00157 public:
00158
00159 virtual ~GLStateManager() {}
00160
00161
00162
00163 static void init();
00164 static void shutdown();
00165
00166
00167 virtual void set(const GLState& state) = 0;
00168 virtual void pixelstore_unpack_alignment(unsigned int bpp) = 0;
00169 virtual void reset_view_for_redraw(float x, float y) = 0;
00170 virtual void reset_view_for_resize(const coord_def &m_windowsz) = 0;
00171 virtual void set_transform(const GLW_3VF &trans, const GLW_3VF &scale) = 0;
00172 virtual void reset_transform() = 0;
00173
00174
00175 virtual void delete_textures(size_t count, unsigned int *textures) = 0;
00176 virtual void generate_textures(size_t count, unsigned int *textures) = 0;
00177 virtual void bind_texture(unsigned int texture) = 0;
00178 virtual void load_texture(unsigned char *pixels, unsigned int width,
00179 unsigned int height, MipMapOptions mip_opt) = 0;
00180
00181
00182 #ifdef ASSERTS
00183 static bool _valid(int num_verts, drawing_modes mode);
00184 #endif
00185 };
00186
00187 class GenericTexture;
00188
00189 class GLShapeBuffer
00190 {
00191 public:
00192 virtual ~GLShapeBuffer() {}
00193
00194
00195
00196
00197 static GLShapeBuffer *create(bool texture = false, bool colour = false,
00198 drawing_modes prim = GLW_RECTANGLE);
00199
00200 virtual const char *print_statistics() const = 0;
00201 virtual unsigned int size() const = 0;
00202
00203
00204 virtual void add(const GLWPrim &prim) = 0;
00205
00206
00207 virtual void draw(const GLState &state) = 0;
00208
00209
00210 virtual void clear() = 0;
00211 };
00212
00213
00214 extern GLStateManager *glmanager;
00215
00216 #endif // use_tile
00217 #endif // include guard