Colobot
nulldevice.h
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.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 
20 #pragma once
21 
22 #include "graphics/core/device.h"
23 
24 #include "graphics/core/light.h"
25 #include "graphics/core/material.h"
26 
27 #include "math/matrix.h"
28 
29 // Graphics module namespace
30 namespace Gfx
31 {
32 
37 class CNullDevice : public CDevice
38 {
39 public:
40  CNullDevice();
41  virtual ~CNullDevice();
42 
43  void DebugHook() override;
44  void DebugLights() override;
45 
46  std::string GetName() override;
47 
48  bool Create() override;
49  void Destroy() override;
50 
51  void ConfigChanged(const DeviceConfig &newConfig) override;
52 
53  void BeginScene() override;
54  void EndScene() override;
55 
56  void Clear() override;
57 
58  void SetRenderMode(RenderMode mode) override;
59 
60  void SetTransform(TransformType type, const Math::Matrix &matrix) override;
61 
62  void SetMaterial(const Material &material) override;
63 
64  int GetMaxLightCount() override;
65  void SetLight(int index, const Light &light) override;
66  void SetLightEnabled(int index, bool enabled) override;
67 
68  Texture CreateTexture(CImage *image, const TextureCreateParams &params) override;
69  Texture CreateTexture(ImageData *data, const TextureCreateParams &params) override;
70  Texture CreateDepthTexture(int width, int height, int depth) override;
71  void UpdateTexture(const Texture& texture, Math::IntPoint offset, ImageData* data, TexImgFormat format) override;
72  void DestroyTexture(const Texture &texture) override;
73  void DestroyAllTextures() override;
74 
75  int GetMaxTextureStageCount() override;
76  void SetTexture(int index, const Texture &texture) override;
77  void SetTexture(int index, unsigned int textureId) override;
78  void SetTextureEnabled(int index, bool enabled) override;
79 
80  void SetTextureStageParams(int index, const TextureStageParams &params) override;
81 
82  void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT) override;
83 
84  void DrawPrimitive(PrimitiveType type, const Vertex* vertices, int vertexCount, Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override;
85  void DrawPrimitive(PrimitiveType type, const VertexTex2* vertices, int vertexCount, Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override;
86  void DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount) override;
87 
88  void DrawPrimitives(PrimitiveType type, const Vertex *vertices,
89  int first[], int count[], int drawCount,
90  Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override;
91  void DrawPrimitives(PrimitiveType type, const VertexTex2 *vertices,
92  int first[], int count[], int drawCount,
93  Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override;
94  void DrawPrimitives(PrimitiveType type, const VertexCol *vertices,
95  int first[], int count[], int drawCount) override;
96 
97  unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) override;
98  unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) override;
99  unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) override;
100  void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) override;
101  void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) override;
102  void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) override;
103  void DrawStaticBuffer(unsigned int bufferId) override;
104  void DestroyStaticBuffer(unsigned int bufferId) override;
105 
106  int ComputeSphereVisibility(const Math::Vector &center, float radius) override;
107 
108  void SetViewport(int x, int y, int width, int height) override;
109 
110  void SetRenderState(RenderState state, bool enabled) override;
111 
112  void SetColorMask(bool red, bool green, bool blue, bool alpha) override;
113 
114  void SetDepthTestFunc(CompFunc func) override;
115 
116  void SetDepthBias(float factor, float units) override;
117 
118  void SetAlphaTestFunc(CompFunc func, float refValue) override;
119 
120  void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) override;
121 
122  void SetClearColor(const Color &color) override;
123 
124  void SetGlobalAmbient(const Color &color) override;
125 
126  void SetFogParams(FogMode mode, const Color &color, float start, float end, float density) override;
127 
128  void SetCullMode(CullMode mode) override;
129 
130  void SetShadeModel(ShadeModel model) override;
131 
132  void SetShadowColor(float value) override;
133 
134  void SetFillMode(FillMode mode) override;
135 
136  void CopyFramebufferToTexture(Texture& texture, int xOffset, int yOffset, int x, int y, int width, int height) override;
137 
138  std::unique_ptr<CFrameBufferPixels> GetFrameBufferPixels() const override;
139 
140  CFramebuffer* GetFramebuffer(std::string name) override;
141 
142  CFramebuffer* CreateFramebuffer(std::string name, const FramebufferParams& params) override;
143 
144  void DeleteFramebuffer(std::string name) override;
145 
146  bool IsAnisotropySupported() override;
147  int GetMaxAnisotropyLevel() override;
148 
149  int GetMaxSamples() override;
150 
151  bool IsShadowMappingSupported() override;
152 
153  int GetMaxTextureSize() override;
154 
155  bool IsFramebufferSupported() override;
156 };
157 
158 
159 } // namespace Gfx
void BeginScene() override
Begins drawing the 3D scene.
Definition: nulldevice.cpp:62
RenderMode
Render modes the graphics device can be in.
Definition: device.h:172
void SetCullMode(CullMode mode) override
Sets the current cull mode.
Definition: nulldevice.cpp:266
void SetColorMask(bool red, bool green, bool blue, bool alpha) override
Sets the color mask.
Definition: nulldevice.cpp:234
void DrawPrimitives(PrimitiveType type, const Vertex *vertices, int first[], int count[], int drawCount, Color color=Color(1.0f, 1.0f, 1.0f, 1.0f)) override
Renders primitives composed of lists of vertices with single texture.
Definition: nulldevice.cpp:171
std::unique_ptr< CFrameBufferPixels > GetFrameBufferPixels() const override
Returns the pixels of the entire screen.
Definition: nulldevice.cpp:286
void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) override
Sets the blending functions for source and destination operations.
Definition: nulldevice.cpp:250
void DeleteFramebuffer(std::string name) override
Deletes framebuffer.
Definition: nulldevice.cpp:301
Material struct.
void SetFillMode(FillMode mode) override
Sets the current fill mode.
Definition: nulldevice.cpp:278
Vertex of a primitive.
Definition: vertex.h:52
Vertex with secondary texture coordinates.
Definition: vertex.h:113
void SetLightEnabled(int index, bool enabled) override
Enables/disables the light at given index.
Definition: nulldevice.cpp:95
void SetShadeModel(ShadeModel model) override
Sets the shade model.
Definition: nulldevice.cpp:270
bool Create() override
Initializes the device, setting the initial state.
Definition: nulldevice.cpp:49
void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex *vertices, int vertexCount) override
Updates the static buffer composed of given primitives with single texture vertices.
Definition: nulldevice.cpp:201
FogMode
Type of fog calculation function.
Definition: device.h:218
void SetShadowColor(float value) override
Sets shadow color.
Definition: nulldevice.cpp:274
int GetMaxLightCount() override
Returns the maximum number of lights available.
Definition: nulldevice.cpp:86
bool IsShadowMappingSupported() override
Checks if shadow mapping is supported.
Definition: nulldevice.cpp:320
int GetMaxTextureSize() override
Returns max texture size supported.
Definition: nulldevice.cpp:325
void SetFogParams(FogMode mode, const Color &color, float start, float end, float density) override
Sets the fog parameters: mode, color, start distance, end distance and density (for exp models) ...
Definition: nulldevice.cpp:262
4x4 matrix
Definition: matrix.h:65
void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT) override
Sets only the texture wrap modes (for faster than thru stage params)
Definition: nulldevice.cpp:153
void SetRenderState(RenderState state, bool enabled) override
Enables/disables the given render state.
Definition: nulldevice.cpp:230
TexWrapMode
Wrapping mode for texture coords.
Definition: texture.h:99
bool IsFramebufferSupported() override
Checks if framebuffers are supported.
Definition: nulldevice.cpp:330
void SetTexture(int index, const Texture &texture) override
Sets the texture at given texture stage.
Definition: nulldevice.cpp:137
void DrawStaticBuffer(unsigned int bufferId) override
Draws a static buffer.
Definition: nulldevice.cpp:213
FillMode
Polygon fill mode.
Definition: device.h:251
std::string GetName() override
Returns a name of this device.
Definition: nulldevice.cpp:44
void DestroyStaticBuffer(unsigned int bufferId) override
Deletes a static buffer.
Definition: nulldevice.cpp:217
CompFunc
Type of function used to compare values.
Definition: device.h:183
Parameters for a texture unit.
Definition: texture.h:180
Light struct and related enums.
Material of a surface.
Definition: material.h:45
void DestroyAllTextures() override
Deletes all textures created so far.
Definition: nulldevice.cpp:128
unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex *vertices, int vertexCount) override
Creates a static buffer composed of given primitives with single texture vertices.
Definition: nulldevice.cpp:186
void SetRenderMode(RenderMode mode) override
Sets current rendering mode.
Definition: nulldevice.cpp:74
void SetClearColor(const Color &color) override
Sets the clear color.
Definition: nulldevice.cpp:254
int ComputeSphereVisibility(const Math::Vector &center, float radius) override
Definition: nulldevice.cpp:221
void DebugHook() override
Provides a hook to debug graphics code (implementation-specific)
Definition: nulldevice.cpp:36
TexImgFormat
Format of image data.
Definition: texture.h:42
General config for graphics device.
Definition: device.h:64
Properties of light in 3D scene.
Definition: light.h:54
Device implementation that doesn&#39;t render anything.
Definition: nulldevice.h:37
void SetMaterial(const Material &material) override
Sets the current material.
Definition: nulldevice.cpp:82
void SetTextureEnabled(int index, bool enabled) override
Enables/disables the given texture stage.
Definition: nulldevice.cpp:145
void DestroyTexture(const Texture &texture) override
Deletes a given texture, freeing it from video memory.
Definition: nulldevice.cpp:124
void ConfigChanged(const DeviceConfig &newConfig) override
Changes configuration.
Definition: nulldevice.cpp:58
void SetGlobalAmbient(const Color &color) override
Sets the global ambient color.
Definition: nulldevice.cpp:258
Parameters for texture creation.
Definition: texture.h:155
Texture CreateDepthTexture(int width, int height, int depth) override
Creates a depth texture with specific dimensions and depth.
Definition: nulldevice.cpp:113
ShadeModel
Shade model used in rendering.
Definition: device.h:241
BlendFunc
Type of blending function.
Definition: device.h:199
Matrix struct and related functions.
void SetDepthTestFunc(CompFunc func) override
Sets the function of depth test.
Definition: nulldevice.cpp:238
void SetViewport(int x, int y, int width, int height) override
Changes rendering viewport.
Definition: nulldevice.cpp:226
Image loaded from file.
Definition: image.h:54
Contains parameters for new framebuffer.
Definition: framebuffer.h:34
void EndScene() override
Ends drawing the 3D scene.
Definition: nulldevice.cpp:66
PrimitiveType
Type of primitive to render.
Definition: device.h:265
CFramebuffer * CreateFramebuffer(std::string name, const FramebufferParams &params) override
Creates new framebuffer with given name or nullptr if it&#39;s not possible.
Definition: nulldevice.cpp:296
CullMode
Culling mode for polygons.
Definition: device.h:229
Colored vertex.
Definition: vertex.h:84
void SetTextureStageParams(int index, const TextureStageParams &params) override
Sets the params for texture stage with given index.
Definition: nulldevice.cpp:149
Namespace for (new) graphics code.
Definition: app.h:49
Implementation-specific image data.
Definition: image.h:41
RenderState
Render states that can be enabled/disabled.
Definition: device.h:155
Texture CreateTexture(CImage *image, const TextureCreateParams &params) override
Creates a texture from image; the image can be safely removed after that.
Definition: nulldevice.cpp:99
Info about a texture.
Definition: texture.h:256
int GetMaxSamples() override
Returns max samples supported.
Definition: nulldevice.cpp:315
void SetLight(int index, const Light &light) override
Sets the light at given index.
Definition: nulldevice.cpp:91
int GetMaxAnisotropyLevel() override
Returns max anisotropy level supported.
Definition: nulldevice.cpp:310
void DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount, Color color=Color(1.0f, 1.0f, 1.0f, 1.0f)) override
Renders primitive composed of vertices with single texture.
Definition: nulldevice.cpp:157
void Clear() override
Clears the screen to blank.
Definition: nulldevice.cpp:70
3D (3x1) vector
Definition: vector.h:53
Abstract graphics device - CDevice class and related structs/enums.
2D Point with integer coords
Definition: intpoint.h:41
void SetAlphaTestFunc(CompFunc func, float refValue) override
Sets the alpha test function and reference value.
Definition: nulldevice.cpp:246
RGBA color.
Definition: color.h:39
int GetMaxTextureStageCount() override
Returns the maximum number of multitexture stages.
Definition: nulldevice.cpp:132
void SetTransform(TransformType type, const Math::Matrix &matrix) override
Sets the transform matrix of given type.
Definition: nulldevice.cpp:78
void Destroy() override
Destroys the device, releasing every acquired resource.
Definition: nulldevice.cpp:54
bool IsAnisotropySupported() override
Checks if anisotropy is supported.
Definition: nulldevice.cpp:305
void CopyFramebufferToTexture(Texture &texture, int xOffset, int yOffset, int x, int y, int width, int height) override
Copies content of framebuffer to texture.
Definition: nulldevice.cpp:282
CFramebuffer * GetFramebuffer(std::string name) override
Returns framebuffer with given name or nullptr if it doesn&#39;t exist.
Definition: nulldevice.cpp:291
TransformType
Type of transformation in rendering pipeline.
Definition: device.h:143
void UpdateTexture(const Texture &texture, Math::IntPoint offset, ImageData *data, TexImgFormat format) override
Updates a part of texture from raw image data.
Definition: nulldevice.cpp:120
void SetDepthBias(float factor, float units) override
Sets the depth bias (constant value added to Z-coords)
Definition: nulldevice.cpp:242
Abstract interface of graphics device.
Definition: device.h:323
Abstract interface of default framebuffer and offscreen framebuffers.
Definition: framebuffer.h:67
void DebugLights() override
Displays light positions to aid in debuggings.
Definition: nulldevice.cpp:40