Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
device.h
Go to the documentation of this file.
1 // * This file is part of the COLOBOT source code
2 // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
3 // * Copyright (C) 2012, Polish Portal of Colobot (PPC)
4 // *
5 // * This program is free software: you can redistribute it and/or modify
6 // * it under the terms of the GNU General Public License as published by
7 // * the Free Software Foundation, either version 3 of the License, or
8 // * (at your option) any later version.
9 // *
10 // * This program is distributed in the hope that it will be useful,
11 // * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // * GNU General Public License for more details.
14 // *
15 // * You should have received a copy of the GNU General Public License
16 // * along with this program. If not, see http://www.gnu.org/licenses/.
17 
23 #pragma once
24 
25 
26 #include "graphics/core/color.h"
27 #include "graphics/core/light.h"
28 #include "graphics/core/material.h"
29 #include "graphics/core/texture.h"
30 #include "graphics/core/vertex.h"
31 
32 #include "math/intpoint.h"
33 #include "math/matrix.h"
34 
35 #include <string>
36 
37 
38 class CImage;
39 struct ImageData;
40 
41 
42 // Graphics module namespace
43 namespace Gfx {
44 
52 {
56  int bpp;
58  bool fullScreen;
60  bool resizeable;
62  bool doubleBuf;
64  bool noFrame;
65 
68 
70  inline void LoadDefault()
71  {
72  size = Math::IntPoint(800, 600);
73  bpp = 32;
74  fullScreen = false;
75  resizeable = true;
76  doubleBuf = true;
77  noFrame = false;
78  }
79 };
80 
81 
89 {
90  TRANSFORM_WORLD,
91  TRANSFORM_VIEW,
92  TRANSFORM_PROJECTION
93 };
94 
100 {
101  RENDER_STATE_LIGHTING,
102  RENDER_STATE_BLENDING,
103  RENDER_STATE_FOG,
104  RENDER_STATE_DEPTH_TEST,
105  RENDER_STATE_DEPTH_WRITE,
106  RENDER_STATE_ALPHA_TEST,
107  RENDER_STATE_CULLING
108 };
109 
115 {
116  COMP_FUNC_NEVER,
117  COMP_FUNC_LESS,
118  COMP_FUNC_EQUAL,
119  COMP_FUNC_NOTEQUAL,
120  COMP_FUNC_LEQUAL,
121  COMP_FUNC_GREATER,
122  COMP_FUNC_GEQUAL,
123  COMP_FUNC_ALWAYS
124 };
125 
131 {
132  BLEND_ZERO,
133  BLEND_ONE,
134  BLEND_SRC_COLOR,
135  BLEND_INV_SRC_COLOR,
136  BLEND_DST_COLOR,
137  BLEND_INV_DST_COLOR,
138  BLEND_SRC_ALPHA,
139  BLEND_INV_SRC_ALPHA,
140  BLEND_DST_ALPHA,
141  BLEND_INV_DST_ALPHA,
142  BLEND_SRC_ALPHA_SATURATE
143 };
144 
150 {
151  FOG_LINEAR,
152  FOG_EXP,
153  FOG_EXP2
154 };
155 
161 {
166 };
167 
173 {
174  SHADE_FLAT,
175  SHADE_SMOOTH
176 };
177 
183 {
190 };
191 
197 {
198  PRIMITIVE_POINTS,
199  PRIMITIVE_LINES,
200  PRIMITIVE_LINE_STRIP,
201  PRIMITIVE_TRIANGLES,
202  PRIMITIVE_TRIANGLE_STRIP
203 };
204 
212 {
213  FRUSTUM_PLANE_LEFT = 0x01,
214  FRUSTUM_PLANE_RIGHT = 0x02,
215  FRUSTUM_PLANE_TOP = 0x04,
216  FRUSTUM_PLANE_BOTTOM = 0x08,
217  FRUSTUM_PLANE_FRONT = 0x10,
218  FRUSTUM_PLANE_BACK = 0x20,
219  FRUSTUM_PLANE_ALL = FRUSTUM_PLANE_LEFT | FRUSTUM_PLANE_RIGHT |
220  FRUSTUM_PLANE_TOP | FRUSTUM_PLANE_BOTTOM |
221  FRUSTUM_PLANE_FRONT | FRUSTUM_PLANE_BACK
222 };
223 
235 class CDevice
236 {
237 public:
238  virtual ~CDevice() {}
239 
241  virtual void DebugHook() = 0;
242 
244  virtual void DebugLights() = 0;
245 
247  virtual bool Create() = 0;
249  virtual void Destroy() = 0;
250 
252  virtual void BeginScene() = 0;
254  virtual void EndScene() = 0;
255 
257  virtual void Clear() = 0;
258 
260  virtual void SetTransform(TransformType type, const Math::Matrix &matrix) = 0;
262  virtual const Math::Matrix& GetTransform(TransformType type) = 0;
264  virtual void MultiplyTransform(TransformType type, const Math::Matrix &matrix) = 0;
265 
267  virtual void SetMaterial(const Material &material) = 0;
269  virtual const Material& GetMaterial() = 0;
270 
272  virtual int GetMaxLightCount() = 0;
274  virtual void SetLight(int index, const Light &light) = 0;
276  virtual const Light& GetLight(int index) = 0;
278  virtual void SetLightEnabled(int index, bool enabled) = 0;
280  virtual bool GetLightEnabled(int index) = 0;
281 
283  virtual Texture CreateTexture(CImage *image, const TextureCreateParams &params) = 0;
285  virtual Texture CreateTexture(ImageData *data, const TextureCreateParams &params) = 0;
287  virtual void DestroyTexture(const Texture &texture) = 0;
289  virtual void DestroyAllTextures() = 0;
290 
292  virtual int GetMaxTextureStageCount() = 0;
294  virtual void SetTexture(int index, const Texture &texture) = 0;
296  virtual void SetTexture(int index, unsigned int textureId) = 0;
298  virtual Texture GetTexture(int index) = 0;
300  virtual void SetTextureEnabled(int index, bool enabled) = 0;
302  virtual bool GetTextureEnabled(int index) = 0;
303 
305  virtual void SetTextureStageParams(int index, const TextureStageParams &params) = 0;
307  virtual TextureStageParams GetTextureStageParams(int index) = 0;
308 
310  virtual void SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wrapT) = 0;
311 
313  virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount,
314  Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) = 0;
316  virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount,
317  Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) = 0;
319  virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) = 0;
320 
322  virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) = 0;
323 
325  virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) = 0;
326 
328  virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) = 0;
329 
331  virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) = 0;
332 
334  virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) = 0;
335 
337  virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) = 0;
338 
340  virtual void DrawStaticBuffer(unsigned int bufferId) = 0;
341 
343  virtual void DestroyStaticBuffer(unsigned int bufferId) = 0;
344 
347  virtual int ComputeSphereVisibility(const Math::Vector &center, float radius) = 0;
348 
350  virtual void SetRenderState(RenderState state, bool enabled) = 0;
352  virtual bool GetRenderState(RenderState state) = 0;
353 
355  virtual void SetDepthTestFunc(CompFunc func) = 0;
357  virtual CompFunc GetDepthTestFunc() = 0;
358 
360  virtual void SetDepthBias(float factor) = 0;
362  virtual float GetDepthBias() = 0;
363 
365  virtual void SetAlphaTestFunc(CompFunc func, float refValue) = 0;
367  virtual void GetAlphaTestFunc(CompFunc &func, float &refValue) = 0;
368 
370  virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) = 0;
372  virtual void GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend) = 0;
373 
375  virtual void SetClearColor(const Color &color) = 0;
377  virtual Color GetClearColor() = 0;
378 
380  virtual void SetGlobalAmbient(const Color &color) = 0;
382  virtual Color GetGlobalAmbient() = 0;
383 
385  virtual void SetFogParams(FogMode mode, const Color &color, float start, float end, float density) = 0;
387  virtual void GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density) = 0;
388 
390  virtual void SetCullMode(CullMode mode) = 0;
392  virtual CullMode GetCullMode() = 0;
393 
395  virtual void SetShadeModel(ShadeModel model) = 0;
397  virtual ShadeModel GetShadeModel() = 0;
398 
400  virtual void SetFillMode(FillMode mode) = 0;
402  virtual FillMode GetFillMode() = 0;
403 
405  virtual void* GetFrameBufferPixels()const = 0;
406 };
407 
408 
409 } // namespace Gfx
410 
virtual Texture GetTexture(int index)=0
Returns the (multi)texture at given index.
Draw only points.
Definition: device.h:185
void LoadDefault()
Loads the default values.
Definition: device.h:70
virtual void MultiplyTransform(TransformType type, const Math::Matrix &matrix)=0
Multiplies the current transform matrix of given type by given matrix.
Material struct.
virtual void GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend)=0
Returns the current blending functions for source and destination operations.
virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount, Color color=Color(1.0f, 1.0f, 1.0f, 1.0f))=0
Renders primitive composed of vertices with single texture.
virtual const Material & GetMaterial()=0
Returns the current material.
virtual void Clear()=0
Clears the screen to blank.
bool noFrame
No window frame (also set with full screen)
Definition: device.h:64
virtual float GetDepthBias()=0
Returns the current depth bias.
Vertex of a primitive.
Definition: vertex.h:48
virtual void SetShadeModel(ShadeModel model)=0
Sets the shade model.
bool fullScreen
Full screen.
Definition: device.h:58
Vertex with secondary texture coordinates.
Definition: vertex.h:109
virtual void SetLight(int index, const Light &light)=0
Sets the light at given index.
FogMode
Type of fog calculation function.
Definition: device.h:149
virtual void GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density)=0
Returns the current fog parameters: mode, color, start distance, end distance and density (for exp mo...
4x4 matrix
Definition: matrix.h:63
virtual void DestroyTexture(const Texture &texture)=0
Deletes a given texture, freeing it from video memory.
TexWrapMode
Wrapping mode for texture coords.
Definition: texture.h:82
Math::IntPoint size
Screen size.
Definition: device.h:54
virtual void SetRenderState(RenderState state, bool enabled)=0
Enables/disables the given render state.
virtual void DestroyAllTextures()=0
Deletes all textures created so far.
FillMode
Polygon fill mode.
Definition: device.h:182
virtual void SetDepthTestFunc(CompFunc func)=0
Sets the function of depth test.
virtual void SetFillMode(FillMode mode)=0
Sets the current fill mode.
Texture struct and related enums.
CompFunc
Type of function used to compare values.
Definition: device.h:114
virtual void GetAlphaTestFunc(CompFunc &func, float &refValue)=0
Returns the current alpha test function and reference value.
virtual void DestroyStaticBuffer(unsigned int bufferId)=0
Deletes a static buffer.
Parameters for a texture unit.
Definition: texture.h:165
Light struct and related enums.
Material of a surface.
Definition: material.h:41
virtual int ComputeSphereVisibility(const Math::Vector &center, float radius)=0
int bpp
Bits per pixel.
Definition: device.h:56
virtual void SetAlphaTestFunc(CompFunc func, float refValue)=0
Sets the alpha test function and reference value.
virtual ShadeModel GetShadeModel()=0
Returns the current shade model.
DeviceConfig()
Constructor calls LoadDefault()
Definition: device.h:67
virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex *vertices, int vertexCount)=0
Creates a static buffer composed of given primitives with single texture vertices.
virtual void DebugLights()=0
Displays light positions to aid in debuggings.
bool resizeable
Resizeable window.
Definition: device.h:60
FrustumPlane
Planes of frustum space.
Definition: device.h:211
General config for graphics device.
Definition: device.h:51
Properties of light in 3D scene.
Definition: light.h:51
virtual void SetCullMode(CullMode mode)=0
Sets the current cull mode.
virtual void SetGlobalAmbient(const Color &color)=0
Sets the global ambient color.
Color structs and related functions.
virtual CompFunc GetDepthTestFunc()=0
Returns the current function of depth test.
virtual FillMode GetFillMode()=0
Returns the current fill mode.
virtual void Destroy()=0
Destroys the device, releasing every acquired resource.
Parameters for texture creation.
Definition: texture.h:129
ShadeModel
Shade model used in rendering.
Definition: device.h:172
virtual void EndScene()=0
Ends drawing the 3D scene.
BlendFunc
Type of blending function.
Definition: device.h:130
Vertex structs.
Matrix struct and related functions.
virtual void BeginScene()=0
Begins drawing the 3D scene.
virtual void * GetFrameBufferPixels() const =0
Returns the pixels of the entire screen.
Image loaded from file.
Definition: image.h:54
Cull clockwise faces.
Definition: device.h:163
virtual void SetFogParams(FogMode mode, const Color &color, float start, float end, float density)=0
Sets the fog parameters: mode, color, start distance, end distance and density (for exp models) ...
virtual void SetTransform(TransformType type, const Math::Matrix &matrix)=0
Sets the transform matrix of given type.
PrimitiveType
Type of primitive to render.
Definition: device.h:196
virtual void DrawStaticBuffer(unsigned int bufferId)=0
Draws a static buffer.
Draw full polygons.
Definition: device.h:189
CullMode
Culling mode for polygons.
Definition: device.h:160
virtual Color GetClearColor()=0
Returns the current clear color.
Colored vertex.
Definition: vertex.h:80
virtual void SetMaterial(const Material &material)=0
Sets the current material.
virtual void SetTextureEnabled(int index, bool enabled)=0
Enables/disables the given texture stage.
virtual Color GetGlobalAmbient()=0
Returns the global ambient color.
Implementation-specific image data.
Definition: image.h:39
Cull counter-clockwise faces.
Definition: device.h:165
virtual void DebugHook()=0
Provides a hook to debug graphics code (implementation-specific)
RenderState
Render states that can be enabled/disabled.
Definition: device.h:99
virtual bool Create()=0
Initializes the device, setting the initial state.
virtual bool GetLightEnabled(int index)=0
Returns the current enable state of light at given index.
virtual const Math::Matrix & GetTransform(TransformType type)=0
Returns the current transform matrix of given type.
virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex *vertices, int vertexCount)=0
Updates the static buffer composed of given primitives with single texture vertices.
virtual void SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wrapT)=0
Sets only the texture wrap modes (for faster than thru stage params)
Info about a texture.
Definition: texture.h:212
bool doubleBuf
Double buffering.
Definition: device.h:62
virtual void SetTextureStageParams(int index, const TextureStageParams &params)=0
Sets the params for texture stage with given index.
3D (3x1) vector
Definition: vector.h:49
virtual TextureStageParams GetTextureStageParams(int index)=0
Returns the current params of texture stage with given index.
virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend)=0
Sets the blending functions for source and destination operations.
2D Point with integer coords
Definition: intpoint.h:35
virtual void SetDepthBias(float factor)=0
Sets the depth bias (constant value added to Z-coords)
RGBA color.
Definition: color.h:35
virtual CullMode GetCullMode()=0
Returns the current cull mode.
virtual void SetLightEnabled(int index, bool enabled)=0
Enables/disables the light at given index.
IntPoint struct.
virtual Texture CreateTexture(CImage *image, const TextureCreateParams &params)=0
Creates a texture from image; the image can be safely removed after that.
virtual bool GetRenderState(RenderState state)=0
Returns the current setting of given render state.
TransformType
Type of transformation in rendering pipeline.
Definition: device.h:88
virtual int GetMaxLightCount()=0
Returns the maximum number of lights available.
virtual bool GetTextureEnabled(int index)=0
Returns the current enable state of given texture stage.
virtual void SetClearColor(const Color &color)=0
Sets the clear color.
virtual int GetMaxTextureStageCount()=0
Returns the maximum number of multitexture stages.
Draw only lines.
Definition: device.h:187
virtual void SetTexture(int index, const Texture &texture)=0
Sets the texture at given texture stage.
virtual const Light & GetLight(int index)=0
Returns the current light at given index.
Abstract interface of graphics device.
Definition: device.h:235