graphic_context_provider.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Harry Storbacka
28 */
29 
30 
31 #pragma once
32 
33 #include "../api_display.h"
34 #include <memory>
35 #include "../Render/graphic_context.h"
36 #include "../Render/primitives_array.h"
37 #include "../Render/texture.h"
38 #include "../../Core/Math/mat4.h"
39 #include "../../Core/Signals/signal_v1.h"
40 
41 namespace clan
42 {
45 
46 class Texture;
47 class Stencil;
48 class TextureProvider;
49 class FontProvider;
50 class Font;
51 class OcclusionQueryProvider;
52 class ProgramObjectProvider;
53 class ShaderObjectProvider;
54 class FrameBufferProvider;
55 class RenderBufferProvider;
56 class VertexArrayBufferProvider;
57 class ElementArrayBufferProvider;
58 class TransferBufferProvider;
59 class FontDescription;
60 class PixelBufferProvider;
61 class UniformBufferProvider;
62 class StorageBufferProvider;
63 class PrimitivesArrayProvider;
64 class RasterizerStateDescription;
65 class BlendStateDescription;
66 class DepthStencilStateDescription;
67 
69 {
70 public:
72 };
73 
75 {
76 public:
77  virtual ~BlendStateProvider() { }
78 };
79 
81 {
82 public:
84 };
85 
87 class CL_API_DISPLAY GraphicContextProvider
88 {
91 
92 public:
93  virtual ~GraphicContextProvider() { return; }
94 
98 
99 public:
101  virtual int get_max_attributes() = 0;
102 
104 
106  virtual Size get_max_texture_size() const = 0;
107 
109  virtual Size get_display_window_size() const = 0;
110 
112  virtual Signal_v1<const Size &> &sig_window_resized() = 0;
113 
115  virtual ProgramObject get_program_object(StandardProgram standard_program) const = 0;
116 
120 
121 public:
122 
124  virtual ClipZRange get_clip_z_range() const = 0;
125 
127  virtual TextureImageYAxis get_texture_image_y_axis() const = 0;
128 
130  virtual ShaderLanguage get_shader_language() const = 0;
131 
136  virtual int get_major_version() const = 0;
137 
142  virtual int get_minor_version() const = 0;
143 
148  virtual bool has_compute_shader_support() const = 0;
149 
151  virtual PixelBuffer get_pixeldata(const Rect& rect, TextureFormat texture_format, bool clamp) const = 0;
152 
154  virtual TextureProvider *alloc_texture(TextureDimensions texture_dimensions) = 0;
155 
157  virtual OcclusionQueryProvider *alloc_occlusion_query() = 0;
158 
160  virtual ProgramObjectProvider *alloc_program_object() = 0;
161 
163  virtual ShaderObjectProvider *alloc_shader_object() = 0;
164 
166  virtual FrameBufferProvider *alloc_frame_buffer() = 0;
167 
169  virtual RenderBufferProvider *alloc_render_buffer() = 0;
170 
172  virtual VertexArrayBufferProvider *alloc_vertex_array_buffer() = 0;
173 
175  virtual UniformBufferProvider *alloc_uniform_buffer() = 0;
176 
178  virtual StorageBufferProvider *alloc_storage_buffer() = 0;
179 
181  virtual ElementArrayBufferProvider *alloc_element_array_buffer() = 0;
182 
184  virtual TransferBufferProvider *alloc_transfer_buffer() = 0;
185 
187  virtual PixelBufferProvider *alloc_pixel_buffer() = 0;
188 
190  virtual PrimitivesArrayProvider *alloc_primitives_array() = 0;
191 
193  virtual std::shared_ptr<RasterizerStateProvider> create_rasterizer_state(const RasterizerStateDescription &desc) = 0;
194 
196  virtual std::shared_ptr<BlendStateProvider> create_blend_state(const BlendStateDescription &desc) = 0;
197 
199  virtual std::shared_ptr<DepthStencilStateProvider> create_depth_stencil_state(const DepthStencilStateDescription &desc) = 0;
200 
202  virtual void set_rasterizer_state(RasterizerStateProvider *state) = 0;
203 
205  virtual void set_blend_state(BlendStateProvider *state, const Colorf &blend_color, unsigned int sample_mask) = 0;
206 
208  virtual void set_depth_stencil_state(DepthStencilStateProvider *state, int stencil_ref) = 0;
209 
211  virtual void set_program_object(StandardProgram standard_program) = 0;
212 
216  virtual void set_program_object(const ProgramObject &program) = 0;
217 
219  virtual void reset_program_object() = 0;
220 
222  virtual void set_uniform_buffer(int index, const UniformBuffer &buffer) = 0;
223 
225  virtual void reset_uniform_buffer(int index) = 0;
226 
228  virtual void set_storage_buffer(int index, const StorageBuffer &buffer) = 0;
229 
231  virtual void reset_storage_buffer(int index) = 0;
232 
234  virtual void set_texture(int unit_index, const Texture &texture) = 0;
235 
237  virtual void reset_texture(int unit_index) = 0;
238 
240  virtual void set_image_texture(int unit_index, const Texture &texture) = 0;
241 
243  virtual void reset_image_texture(int unit_index) = 0;
244 
246  virtual bool is_frame_buffer_owner(const FrameBuffer &fb) = 0;
247 
249  virtual void set_frame_buffer(const FrameBuffer &write_buffer, const FrameBuffer &read_buffer) = 0;
250 
252  virtual void reset_frame_buffer() = 0;
253 
254  virtual void set_draw_buffer(DrawBuffer buffer) = 0;
255 
257  virtual bool is_primitives_array_owner(const PrimitivesArray &primitives_array) = 0;
258 
260  virtual void draw_primitives(PrimitivesType type, int num_vertices, const PrimitivesArray &primitives_array) = 0;
261 
263  virtual void set_primitives_array(const PrimitivesArray &primitives_array) = 0;
264 
266  virtual void draw_primitives_array(PrimitivesType type, int offset, int num_vertices) = 0;
267 
269  virtual void draw_primitives_array_instanced(PrimitivesType type, int offset, int num_vertices, int instance_count) = 0;
270 
272  virtual void set_primitives_elements(ElementArrayBufferProvider *array_provider) = 0;
273 
280  virtual void draw_primitives_elements(PrimitivesType type, int count, VertexAttributeDataType indices_type, size_t offset = 0) = 0;
281 
289  virtual void draw_primitives_elements_instanced(PrimitivesType type, int count, VertexAttributeDataType indices_type, size_t offset, int instance_count) = 0;
290 
292  virtual void reset_primitives_elements() = 0;
293 
301  virtual void draw_primitives_elements(PrimitivesType type, int count, ElementArrayBufferProvider *array_provider, VertexAttributeDataType indices_type, void *offset) = 0;
302 
310  virtual void draw_primitives_elements_instanced(PrimitivesType type, int count, ElementArrayBufferProvider *array_provider, VertexAttributeDataType indices_type, void *offset, int instance_count) = 0;
311 
313  virtual void reset_primitives_array() = 0;
314 
316  virtual void set_scissor(const Rect &rect) = 0;
317 
319  virtual void reset_scissor() = 0;
320 
322  virtual void dispatch(int x, int y, int z) = 0;
323 
325  virtual void clear(const Colorf &color) = 0;
326 
330  virtual void clear_depth(float value) = 0;
331 
335  virtual void clear_stencil(int value) = 0;
336 
338  virtual void set_viewport(const Rectf &viewport) = 0;
339 
341  virtual void set_viewport(int index, const Rectf &viewport) = 0;
342 
344  virtual void set_depth_range(float n, float f) = 0;
345 
347  virtual void set_depth_range(int viewport, float n, float f) = 0;
348 
352 
353 private:
355 };
356 
357 }
358 
Primitives array description.
Definition: primitives_array.h:69
virtual ~DepthStencilStateProvider()
Definition: graphic_context_provider.h:83
Rasterizer state description.
Definition: rasterizer_state_description.h:43
Floating point color description class (for float).
Definition: color.h:661
Interface for implementing a PrimitivesArray target.
Definition: primitives_array_provider.h:41
Program Object provider.
Definition: program_object_provider.h:43
Frame-buffer object class.
Definition: frame_buffer.h:73
Interface for implementing a RenderBuffer target.
Definition: render_buffer_provider.h:44
Blend state description.
Definition: blend_state_description.h:43
Interface for implementing a GraphicContext target.
Definition: graphic_context_provider.h:87
Texture object class.
Definition: texture.h:104
Occlusion query provider.
Definition: occlusion_query_provider.h:41
Pixel data container.
Definition: pixel_buffer.h:69
virtual ~RasterizerStateProvider()
Definition: graphic_context_provider.h:71
TextureDimensions
Texture dimensions.
Definition: texture.h:92
Element Array Buffer provider.
Definition: pixel_buffer_provider.h:42
DrawBuffer
Drawing buffers.
Definition: graphic_context.h:119
ShaderLanguage
Shader language used.
Definition: graphic_context.h:248
Transfer Buffer provider.
Definition: transfer_buffer_provider.h:42
Definition: graphic_context_provider.h:80
ClipZRange
Definition: mat4.h:52
Definition: graphic_context_provider.h:68
virtual ~BlendStateProvider()
Definition: graphic_context_provider.h:77
StandardProgram
Standard Program.
Definition: graphic_context.h:240
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:453
Signal_v1.
Definition: signal_v1.h:110
Storage Buffer provider.
Definition: storage_buffer_provider.h:40
Shader Object provider.
Definition: shader_object_provider.h:42
Definition: graphic_context_provider.h:74
2D (left,top,right,bottom) rectangle structure - Float
Definition: rect.h:467
TextureFormat
Texture format.
Definition: texture_format.h:41
TextureImageYAxis
Y axis direction for viewports, clipping rects, textures and render targets.
Definition: graphic_context.h:233
virtual ~GraphicContextProvider()
Definition: graphic_context_provider.h:93
Vertex Array Buffer provider.
Definition: vertex_array_buffer_provider.h:42
Uniform Buffer.
Definition: uniform_buffer.h:48
Interface for implementing a Texture target.
Definition: texture_provider.h:51
DepthStencil state description.
Definition: depth_stencil_state_description.h:43
VertexAttributeDataType
Primitives array description.
Definition: primitives_array.h:57
Program Object.
Definition: program_object.h:70
2D (width,height) size structure - Integer
Definition: size.h:157
Storage Buffer.
Definition: storage_buffer.h:48
Interface for implementing a FrameBuffer target.
Definition: frame_buffer_provider.h:46
Uniform Buffer provider.
Definition: uniform_buffer_provider.h:40
Element Array Buffer provider.
Definition: element_array_buffer_provider.h:40
PrimitivesType
Primitive types.
Definition: graphic_context.h:221
C clamp(A val, B minval, C maxval)
Definition: cl_math.h:91