Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
nulldevice.h
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 
28 #include "graphics/core/device.h"
29 
30 // Graphics module namespace
31 namespace Gfx {
32 
38 class CNullDevice : public CDevice
39 {
40 public:
41  CNullDevice();
42  virtual ~CNullDevice();
43 
44  virtual void DebugHook();
45  virtual void DebugLights();
46 
47  virtual bool Create();
48  virtual void Destroy();
49 
50  virtual void BeginScene();
51  virtual void EndScene();
52 
53  virtual void Clear();
54 
55  virtual void SetTransform(TransformType type, const Math::Matrix &matrix);
56  virtual const Math::Matrix& GetTransform(TransformType type);
57  virtual void MultiplyTransform(TransformType type, const Math::Matrix &matrix);
58 
59  virtual void SetMaterial(const Material &material);
60  virtual const Material& GetMaterial();
61 
62  virtual int GetMaxLightCount();
63  virtual void SetLight(int index, const Light &light);
64  virtual const Light& GetLight(int index);
65  virtual void SetLightEnabled(int index, bool enabled);
66  virtual bool GetLightEnabled(int index);
67 
68  virtual Texture CreateTexture(CImage *image, const TextureCreateParams &params);
69  virtual Texture CreateTexture(ImageData *data, const TextureCreateParams &params);
70  virtual Texture CreateDepthTexture(int width, int height, int depth);
71  virtual void DestroyTexture(const Texture &texture);
72  virtual void DestroyAllTextures();
73 
74  virtual int GetMaxTextureStageCount();
75  virtual void SetTexture(int index, const Texture &texture);
76  virtual void SetTexture(int index, unsigned int textureId);
77  virtual Texture GetTexture(int index);
78  virtual void SetTextureEnabled(int index, bool enabled);
79  virtual bool GetTextureEnabled(int index);
80 
81  virtual void SetTextureStageParams(int index, const TextureStageParams &params);
82  virtual TextureStageParams GetTextureStageParams(int index);
83 
84  virtual void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT);
85  virtual void SetTextureCoordGeneration(int index, TextureGenerationParams &params);
86 
87  virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount,
88  Color color = Color(1.0f, 1.0f, 1.0f, 1.0f));
89  virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount,
90  Color color = Color(1.0f, 1.0f, 1.0f, 1.0f));
91  virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount);
92 
93  virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount);
94  virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount);
95  virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount);
96  virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount);
97  virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount);
98  virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount);
99  virtual void DrawStaticBuffer(unsigned int bufferId);
100  virtual void DestroyStaticBuffer(unsigned int bufferId);
101 
102  virtual int ComputeSphereVisibility(const Math::Vector &center, float radius);
103 
104  virtual void SetViewport(int x, int y, int width, int height);
105 
106  virtual void SetRenderState(RenderState state, bool enabled);
107  virtual bool GetRenderState(RenderState state);
108 
109  virtual void SetColorMask(bool red, bool green, bool blue, bool alpha);
110 
111  virtual void SetDepthTestFunc(CompFunc func);
112  virtual CompFunc GetDepthTestFunc();
113 
114  virtual void SetDepthBias(float factor, float units);
115  virtual float GetDepthBias();
116 
117  virtual void SetAlphaTestFunc(CompFunc func, float refValue);
118  virtual void GetAlphaTestFunc(CompFunc &func, float &refValue);
119 
120  virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend);
121  virtual void GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend);
122 
123  virtual void SetClearColor(const Color &color);
124  virtual Color GetClearColor();
125 
126  virtual void SetGlobalAmbient(const Color &color);
127  virtual Color GetGlobalAmbient();
128 
129  virtual void SetFogParams(FogMode mode, const Color &color, float start, float end, float density);
130  virtual void GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density);
131 
132  virtual void SetCullMode(CullMode mode);
133  virtual CullMode GetCullMode();
134 
135  virtual void SetShadeModel(ShadeModel model);
136  virtual ShadeModel GetShadeModel();
137 
138  virtual void SetShadowColor(float value);
139 
140  virtual void SetFillMode(FillMode mode) ;
141  virtual FillMode GetFillMode();
142 
143  virtual void InitOffscreenBuffer(int width, int height);
144 
145  virtual void SetRenderTexture(RenderTarget target, int texture);
146 
147  virtual void CopyFramebufferToTexture(Texture& texture, int xOffset, int yOffset, int x, int y, int width, int height);
148 
149  virtual void* GetFrameBufferPixels() const;
150 
151 private:
152  Math::Matrix m_matrix;
153  Material m_material;
154  Light m_light;
155 };
156 
157 
158 } // namespace Gfx
159 
virtual void SetAlphaTestFunc(CompFunc func, float refValue)
Sets the alpha test function and reference value.
Definition: nulldevice.cpp:279
virtual void SetTextureCoordGeneration(int index, TextureGenerationParams &params)
Sets the texture coordinate generation mode for given texture unit.
Definition: nulldevice.cpp:181
virtual int GetMaxTextureStageCount()
Returns the maximum number of multitexture stages.
Definition: nulldevice.cpp:146
virtual void EndScene()
Ends drawing the 3D scene.
Definition: nulldevice.cpp:64
virtual int GetMaxLightCount()
Returns the maximum number of lights available.
Definition: nulldevice.cpp:94
virtual void SetMaterial(const Material &material)
Sets the current material.
Definition: nulldevice.cpp:85
Vertex of a primitive.
Definition: vertex.h:51
virtual void SetDepthBias(float factor, float units)
Sets the depth bias (constant value added to Z-coords)
Definition: nulldevice.cpp:270
Vertex with secondary texture coordinates.
Definition: vertex.h:112
virtual void SetShadeModel(ShadeModel model)
Sets the shade model.
Definition: nulldevice.cpp:336
FogMode
Type of fog calculation function.
Definition: device.h:154
virtual void SetGlobalAmbient(const Color &color)
Sets the global ambient color.
Definition: nulldevice.cpp:309
virtual void CopyFramebufferToTexture(Texture &texture, int xOffset, int yOffset, int x, int y, int width, int height)
Copies content of framebuffer to texture.
Definition: nulldevice.cpp:366
virtual void DestroyStaticBuffer(unsigned int bufferId)
Deletes a static buffer.
Definition: nulldevice.cpp:235
4x4 matrix
Definition: matrix.h:66
TexWrapMode
Wrapping mode for texture coords.
Definition: texture.h:98
virtual void SetViewport(int x, int y, int width, int height)
Changes rendering viewport.
Definition: nulldevice.cpp:244
virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex *vertices, int vertexCount)
Creates a static buffer composed of given primitives with single texture vertices.
Definition: nulldevice.cpp:204
virtual void InitOffscreenBuffer(int width, int height)
Initializes offscreen buffer.
Definition: nulldevice.cpp:358
FillMode
Polygon fill mode.
Definition: device.h:187
virtual void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT)
Sets only the texture wrap modes (for faster than thru stage params)
Definition: nulldevice.cpp:177
CompFunc
Type of function used to compare values.
Definition: device.h:119
virtual void DebugLights()
Displays light positions to aid in debuggings.
Definition: nulldevice.cpp:47
virtual void SetColorMask(bool red, bool green, bool blue, bool alpha)
Sets the color mask.
Definition: nulldevice.cpp:257
Parameters for a texture unit.
Definition: texture.h:187
Material of a surface.
Definition: material.h:44
virtual void SetLight(int index, const Light &light)
Sets the light at given index.
Definition: nulldevice.cpp:99
virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex *vertices, int vertexCount)
Updates the static buffer composed of given primitives with single texture vertices.
Definition: nulldevice.cpp:219
Parameters for texture coordinate generation.
Definition: texture.h:253
virtual void SetTransform(TransformType type, const Math::Matrix &matrix)
Sets the transform matrix of given type.
Definition: nulldevice.cpp:72
virtual void DrawStaticBuffer(unsigned int bufferId)
Draws a static buffer.
Definition: nulldevice.cpp:231
Properties of light in 3D scene.
Definition: light.h:53
Device implementation that doesn't render anything.
Definition: nulldevice.h:38
virtual void SetRenderState(RenderState state, bool enabled)
Enables/disables the given render state.
Definition: nulldevice.cpp:248
virtual void BeginScene()
Begins drawing the 3D scene.
Definition: nulldevice.cpp:60
virtual void SetDepthTestFunc(CompFunc func)
Sets the function of depth test.
Definition: nulldevice.cpp:261
virtual void SetRenderTexture(RenderTarget target, int texture)
Sets render target to texture.
Definition: nulldevice.cpp:362
virtual void Clear()
Clears the screen to blank.
Definition: nulldevice.cpp:68
Parameters for texture creation.
Definition: texture.h:154
ShadeModel
Shade model used in rendering.
Definition: device.h:177
BlendFunc
Type of blending function.
Definition: device.h:135
virtual void SetClearColor(const Color &color)
Sets the clear color.
Definition: nulldevice.cpp:300
virtual void SetFillMode(FillMode mode)
Sets the current fill mode.
Definition: nulldevice.cpp:349
virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount, Color color=Color(1.0f, 1.0f, 1.0f, 1.0f))
Renders primitive composed of vertices with single texture.
Definition: nulldevice.cpp:190
Image loaded from file.
Definition: image.h:57
PrimitiveType
Type of primitive to render.
Definition: device.h:201
virtual void SetShadowColor(float value)
Sets shadow color.
Definition: nulldevice.cpp:345
virtual void SetTextureEnabled(int index, bool enabled)
Enables/disables the given texture stage.
Definition: nulldevice.cpp:164
virtual Texture CreateTexture(CImage *image, const TextureCreateParams &params)
Creates a texture from image; the image can be safely removed after that.
Definition: nulldevice.cpp:117
virtual Texture CreateDepthTexture(int width, int height, int depth)
Creates a depth texture with specific dimensions and depth.
Definition: nulldevice.cpp:131
CullMode
Culling mode for polygons.
Definition: device.h:165
Colored vertex.
Definition: vertex.h:83
virtual void DestroyAllTextures()
Deletes all textures created so far.
Definition: nulldevice.cpp:142
virtual void SetLightEnabled(int index, bool enabled)
Enables/disables the light at given index.
Definition: nulldevice.cpp:108
Namespace for (new) graphics code.
Definition: app.h:49
Implementation-specific image data.
Definition: image.h:42
RenderState
Render states that can be enabled/disabled.
Definition: device.h:102
Info about a texture.
Definition: texture.h:282
virtual void SetCullMode(CullMode mode)
Sets the current cull mode.
Definition: nulldevice.cpp:327
virtual void Destroy()
Destroys the device, releasing every acquired resource.
Definition: nulldevice.cpp:56
3D (3x1) vector
Definition: vector.h:52
virtual void SetTexture(int index, const Texture &texture)
Sets the texture at given texture stage.
Definition: nulldevice.cpp:151
Abstract graphics device - CDevice class and related structs/enums.
virtual void SetFogParams(FogMode mode, const Color &color, float start, float end, float density)
Sets the fog parameters: mode, color, start distance, end distance and density (for exp models) ...
Definition: nulldevice.cpp:318
virtual void DebugHook()
Provides a hook to debug graphics code (implementation-specific)
Definition: nulldevice.cpp:43
virtual void * GetFrameBufferPixels() const
Returns the pixels of the entire screen.
Definition: nulldevice.cpp:370
RGBA color.
Definition: color.h:38
virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend)
Sets the blending functions for source and destination operations.
Definition: nulldevice.cpp:290
virtual void SetTextureStageParams(int index, const TextureStageParams &params)
Sets the params for texture stage with given index.
Definition: nulldevice.cpp:173
virtual int ComputeSphereVisibility(const Math::Vector &center, float radius)
Definition: nulldevice.cpp:239
TransformType
Type of transformation in rendering pipeline.
Definition: device.h:90
virtual void DestroyTexture(const Texture &texture)
Deletes a given texture, freeing it from video memory.
Definition: nulldevice.cpp:138
Abstract interface of graphics device.
Definition: device.h:251
virtual bool Create()
Initializes the device, setting the initial state.
Definition: nulldevice.cpp:51
RenderTarget
Render targets for rendering to textures.
Definition: device.h:233