Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
gldevice.h
Go to the documentation of this file.
1 // * This file is part of the COLOBOT source code
2 // * Copyright (C) 2012, Polish Portal of Colobot (PPC)
3 // *
4 // * This program is free software: you can redistribute it and/or modify
5 // * it under the terms of the GNU General Public License as published by
6 // * the Free Software Foundation, either version 3 of the License, or
7 // * (at your option) any later version.
8 // *
9 // * This program is distributed in the hope that it will be useful,
10 // * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // * GNU General Public License for more details.
13 // *
14 // * You should have received a copy of the GNU General Public License
15 // * along with this program. If not, see http://www.gnu.org/licenses/.
16 
22 #pragma once
23 
24 
25 #include "graphics/core/device.h"
26 
27 #include <string>
28 #include <vector>
29 #include <set>
30 #include <map>
31 
32 
33 // Graphics module namespace
34 namespace Gfx {
35 
40 enum VBOMode
41 {
42  VBO_MODE_ENABLE,
45 };
46 
51 {
53  int redSize;
55  int greenSize;
57  int blueSize;
59  int alphaSize;
61  int depthSize;
62 
65 
68 
71 
73  void LoadDefault();
74 };
75 
76 struct GLDevicePrivate;
77 
89 class CGLDevice : public CDevice
90 {
91 public:
92  CGLDevice(const GLDeviceConfig &config);
93  virtual ~CGLDevice();
94 
95  virtual void DebugHook();
96  virtual void DebugLights();
97 
98  virtual bool Create();
99  virtual void Destroy();
100 
101  void ConfigChanged(const GLDeviceConfig &newConfig);
102 
103  void SetUseVbo(bool useVbo);
104  bool GetUseVbo();
105 
106  virtual void BeginScene();
107  virtual void EndScene();
108 
109  virtual void Clear();
110 
111  virtual void SetTransform(TransformType type, const Math::Matrix &matrix);
112  virtual const Math::Matrix& GetTransform(TransformType type);
113  virtual void MultiplyTransform(TransformType type, const Math::Matrix &matrix);
114 
115  virtual void SetMaterial(const Material &material);
116  virtual const Material& GetMaterial();
117 
118  virtual int GetMaxLightCount();
119  virtual void SetLight(int index, const Light &light);
120  virtual const Light& GetLight(int index);
121  virtual void SetLightEnabled(int index, bool enabled);
122  virtual bool GetLightEnabled(int index);
123 
124  virtual Texture CreateTexture(CImage *image, const TextureCreateParams &params);
125  virtual Texture CreateTexture(ImageData *data, const TextureCreateParams &params);
126  virtual void DestroyTexture(const Texture &texture);
127  virtual void DestroyAllTextures();
128 
129  virtual int GetMaxTextureStageCount();
130  virtual void SetTexture(int index, const Texture &texture);
131  virtual void SetTexture(int index, unsigned int textureId);
132  virtual Texture GetTexture(int index);
133  virtual void SetTextureEnabled(int index, bool enabled);
134  virtual bool GetTextureEnabled(int index);
135 
136  virtual void SetTextureStageParams(int index, const TextureStageParams &params);
137  virtual TextureStageParams GetTextureStageParams(int index);
138 
139  virtual void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT);
140 
141  virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount,
142  Color color = Color(1.0f, 1.0f, 1.0f, 1.0f));
143  virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount,
144  Color color = Color(1.0f, 1.0f, 1.0f, 1.0f));
145  virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount);
146 
147  virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount);
148  virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount);
149  virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount);
150  virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount);
151  virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount);
152  virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount);
153  virtual void DrawStaticBuffer(unsigned int bufferId);
154  virtual void DestroyStaticBuffer(unsigned int bufferId);
155 
156  virtual int ComputeSphereVisibility(const Math::Vector &center, float radius);
157 
158  virtual void SetRenderState(RenderState state, bool enabled);
159  virtual bool GetRenderState(RenderState state);
160 
161  virtual void SetDepthTestFunc(CompFunc func);
162  virtual CompFunc GetDepthTestFunc();
163 
164  virtual void SetDepthBias(float factor);
165  virtual float GetDepthBias();
166 
167  virtual void SetAlphaTestFunc(CompFunc func, float refValue);
168  virtual void GetAlphaTestFunc(CompFunc &func, float &refValue);
169 
170  virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend);
171  virtual void GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend);
172 
173  virtual void SetClearColor(const Color &color);
174  virtual Color GetClearColor();
175 
176  virtual void SetGlobalAmbient(const Color &color);
177  virtual Color GetGlobalAmbient();
178 
179  virtual void SetFogParams(FogMode mode, const Color &color, float start, float end, float density);
180  virtual void GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density);
181 
182  virtual void SetCullMode(CullMode mode);
183  virtual CullMode GetCullMode();
184 
185  virtual void SetShadeModel(ShadeModel model);
186  virtual ShadeModel GetShadeModel();
187 
188  virtual void SetFillMode(FillMode mode) ;
189  virtual FillMode GetFillMode();
190 
191  virtual void* GetFrameBufferPixels()const;
192 
193 private:
195  void UpdateModelviewMatrix();
197  void UpdateLightPosition(int index);
199  void UpdateTextureParams(int index);
200 
201 private:
203  GLDeviceConfig m_config;
204 
206  Math::Matrix m_worldMat;
208  Math::Matrix m_viewMat;
210  Math::Matrix m_modelviewMat;
212  Math::Matrix m_projectionMat;
213 
215  Material m_material;
216 
218  bool m_lighting;
220  std::vector<Light> m_lights;
222  std::vector<bool> m_lightsEnabled;
223 
225  std::vector<Texture> m_currentTextures;
227  std::vector<bool> m_texturesEnabled;
229  std::vector<TextureStageParams> m_textureStageParams;
230 
232  std::set<Texture> m_allTextures;
233 
235  enum VertexType
236  {
237  VERTEX_TYPE_NORMAL,
238  VERTEX_TYPE_TEX2,
239  VERTEX_TYPE_COL,
240  };
241 
243  struct VboObjectInfo
244  {
245  PrimitiveType primitiveType;
246  unsigned int bufferId;
247  VertexType vertexType;
248  int vertexCount;
249  };
250 
252  bool m_multitextureAvailable;
254  bool m_vboAvailable;
256  std::map<unsigned int, VboObjectInfo> m_vboObjects;
258  unsigned int m_lastVboId;
259 };
260 
261 
262 } // namespace Gfx
263