graphic_context_provider.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 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 <memory>
34 #include "../Render/graphic_context.h"
35 #include "../Render/primitives_array.h"
36 #include "../Render/texture.h"
37 #include "../../Core/Math/mat4.h"
38 #include "../../Core/Signals/signal.h"
39
40 namespace clan
41 {
44
45 class Texture;
46 class Stencil;
47 class TextureProvider;
48 class FontProvider;
49 class Font;
50 class OcclusionQueryProvider;
51 class ProgramObjectProvider;
52 class ShaderObjectProvider;
53 class FrameBufferProvider;
54 class RenderBufferProvider;
55 class VertexArrayBufferProvider;
56 class ElementArrayBufferProvider;
57 class TransferBufferProvider;
58 class FontDescription;
59 class PixelBufferProvider;
60 class UniformBufferProvider;
61 class StorageBufferProvider;
62 class PrimitivesArrayProvider;
63 class RasterizerStateDescription;
64 class BlendStateDescription;
65 class DepthStencilStateDescription;
66
67 class RasterizerStateProvider
68 {
69 public:
70 virtual ~RasterizerStateProvider() { }
71 };
72
73 class BlendStateProvider
74 {
75 public:
76 virtual ~BlendStateProvider() { }
77 };
78
79 class DepthStencilStateProvider
80 {
81 public:
82 virtual ~DepthStencilStateProvider() { }
83 };
84
86 class GraphicContextProvider
87 {
90
91 public:
92 virtual ~GraphicContextProvider() { return; }
93
97
98 public:
100 virtual int get_max_attributes() = 0;
101
103
105 virtual Size get_max_texture_size() const = 0;
106
108 virtual Size get_display_window_size() const = 0;
109
111 virtual float get_pixel_ratio() const = 0;
112
114 virtual Signal<void(const Size &)> &sig_window_resized() = 0;
115
117 virtual ProgramObject get_program_object(StandardProgram standard_program) const = 0;
118
122
123 public:
124
126 virtual ClipZRange get_clip_z_range() const = 0;
127
129 virtual TextureImageYAxis get_texture_image_y_axis() const = 0;
130
132 virtual ShaderLanguage get_shader_language() const = 0;
133
138 virtual int get_major_version() const = 0;
139
144 virtual int get_minor_version() const = 0;
145
150 virtual bool has_compute_shader_support() const = 0;
151
153 virtual PixelBuffer get_pixeldata(const Rect& rect, TextureFormat texture_format, bool clamp) const = 0;
154
156 virtual TextureProvider *alloc_texture(TextureDimensions texture_dimensions) = 0;
157
159 virtual OcclusionQueryProvider *alloc_occlusion_query() = 0;
160
162 virtual ProgramObjectProvider *alloc_program_object() = 0;
163
165 virtual ShaderObjectProvider *alloc_shader_object() = 0;
166
168 virtual FrameBufferProvider *alloc_frame_buffer() = 0;
169
171 virtual RenderBufferProvider *alloc_render_buffer() = 0;
172
174 virtual VertexArrayBufferProvider *alloc_vertex_array_buffer() = 0;
175
177 virtual UniformBufferProvider *alloc_uniform_buffer() = 0;
178
180 virtual StorageBufferProvider *alloc_storage_buffer() = 0;
181
183 virtual ElementArrayBufferProvider *alloc_element_array_buffer() = 0;
184
186 virtual TransferBufferProvider *alloc_transfer_buffer() = 0;
187
189 virtual PixelBufferProvider *alloc_pixel_buffer() = 0;
190
192 virtual PrimitivesArrayProvider *alloc_primitives_array() = 0;
193
195 virtual std::shared_ptr<RasterizerStateProvider> create_rasterizer_state(const RasterizerStateDescription &desc) = 0;
196
198 virtual std::shared_ptr<BlendStateProvider> create_blend_state(const BlendStateDescription &desc) = 0;
199
201 virtual std::shared_ptr<DepthStencilStateProvider> create_depth_stencil_state(const DepthStencilStateDescription &desc) = 0;
202
204 virtual void set_rasterizer_state(RasterizerStateProvider *state) = 0;
205
207 virtual void set_blend_state(BlendStateProvider *state, const Colorf &blend_color, unsigned int sample_mask) = 0;
208
210 virtual void set_depth_stencil_state(DepthStencilStateProvider *state, int stencil_ref) = 0;
211
213 virtual void set_program_object(StandardProgram standard_program) = 0;
214
218 virtual void set_program_object(const ProgramObject &program) = 0;
219
221 virtual void reset_program_object() = 0;
222
224 virtual void set_uniform_buffer(int index, const UniformBuffer &buffer) = 0;
225
227 virtual void reset_uniform_buffer(int index) = 0;
228
230 virtual void set_storage_buffer(int index, const StorageBuffer &buffer) = 0;
231
233 virtual void reset_storage_buffer(int index) = 0;
234
236 virtual void set_texture(int unit_index, const Texture &texture) = 0;
237
239 virtual void reset_texture(int unit_index) = 0;
240
242 virtual void set_image_texture(int unit_index, const Texture &texture) = 0;
243
245 virtual void reset_image_texture(int unit_index) = 0;
246
248 virtual bool is_frame_buffer_owner(const FrameBuffer &fb) = 0;
249
251 virtual void set_frame_buffer(const FrameBuffer &write_buffer, const FrameBuffer &read_buffer) = 0;
252
254 virtual void reset_frame_buffer() = 0;
255
256 virtual void set_draw_buffer(DrawBuffer buffer) = 0;
257
259 virtual bool is_primitives_array_owner(const PrimitivesArray &primitives_array) = 0;
260
262 virtual void draw_primitives(PrimitivesType type, int num_vertices, const PrimitivesArray &primitives_array) = 0;
263
265 virtual void set_primitives_array(const PrimitivesArray &primitives_array) = 0;
266
268 virtual void draw_primitives_array(PrimitivesType type, int offset, int num_vertices) = 0;
269
271 virtual void draw_primitives_array_instanced(PrimitivesType type, int offset, int num_vertices, int instance_count) = 0;
272
274 virtual void set_primitives_elements(ElementArrayBufferProvider *array_provider) = 0;
275
282 virtual void draw_primitives_elements(PrimitivesType type, int count, VertexAttributeDataType indices_type, size_t offset = 0) = 0;
283
291 virtual void draw_primitives_elements_instanced(PrimitivesType type, int count, VertexAttributeDataType indices_type, size_t offset, int instance_count) = 0;
292
294 virtual void reset_primitives_elements() = 0;
295
303 virtual void draw_primitives_elements(PrimitivesType type, int count, ElementArrayBufferProvider *array_provider, VertexAttributeDataType indices_type, void *offset) = 0;
304
312 virtual void draw_primitives_elements_instanced(PrimitivesType type, int count, ElementArrayBufferProvider *array_provider, VertexAttributeDataType indices_type, void *offset, int instance_count) = 0;
313
315 virtual void reset_primitives_array() = 0;
316
318 virtual void set_scissor(const Rect &rect) = 0;
319
321 virtual void reset_scissor() = 0;
322
324 virtual void dispatch(int x, int y, int z) = 0;
325
327 virtual void clear(const Colorf &color) = 0;
328
332 virtual void clear_depth(float value) = 0;
333
337 virtual void clear_stencil(int value) = 0;
338
340 virtual void set_viewport(const Rectf &viewport) = 0;
341
343 virtual void set_viewport(int index, const Rectf &viewport) = 0;
344
346 virtual void set_depth_range(float n, float f) = 0;
347
349 virtual void set_depth_range(int viewport, float n, float f) = 0;
350
351 virtual void flush() = 0;
352
356
357 private:
359 };
360
361 }
362
clan::PrimitivesArray
Primitives array description.
Definition: primitives_array.h:68
clan::GraphicContextProvider::set_image_texture
virtual void set_image_texture(int unit_index, const Texture &texture)=0
Select texture into image unit.
clan::Key::n
clan::DepthStencilStateProvider::~DepthStencilStateProvider
virtual ~DepthStencilStateProvider()
Definition: graphic_context_provider.h:82
clan::GraphicContextProvider::set_draw_buffer
virtual void set_draw_buffer(DrawBuffer buffer)=0
clan::GraphicContextProvider::set_rasterizer_state
virtual void set_rasterizer_state(RasterizerStateProvider *state)=0
Set active rasterizer state.
clan::GraphicContextProvider::reset_image_texture
virtual void reset_image_texture(int unit_index)=0
Remove texture from image unit.
clan::RasterizerStateDescription
Rasterizer state description.
Definition: rasterizer_state_description.h:42
clan
Definition: clanapp.h:35
clan::Colorf
Floating point color description class (for float).
Definition: color.h:660
clan::GraphicContextProvider::alloc_uniform_buffer
virtual UniformBufferProvider * alloc_uniform_buffer()=0
Allocate uniform buffer provider for this gc.
clan::PrimitivesArrayProvider
Interface for implementing a PrimitivesArray target.
Definition: primitives_array_provider.h:40
clan::ProgramObjectProvider
Program Object provider.
Definition: program_object_provider.h:43
clan::FrameBuffer
Frame-buffer object class.
Definition: frame_buffer.h:72
clan::GraphicContextProvider::get_clip_z_range
virtual ClipZRange get_clip_z_range() const =0
Returns in what range clip space z values are clipped.
clan::RenderBufferProvider
Interface for implementing a RenderBuffer target.
Definition: render_buffer_provider.h:43
clan::GraphicContextProvider::get_pixel_ratio
virtual float get_pixel_ratio() const =0
Physical pixels/dots per inch.
clan::GraphicContextProvider::set_depth_stencil_state
virtual void set_depth_stencil_state(DepthStencilStateProvider *state, int stencil_ref)=0
Set active depth stencil state.
clan::BlendStateDescription
Blend state description.
Definition: blend_state_description.h:42
clan::GraphicContextProvider
Interface for implementing a GraphicContext target.
Definition: graphic_context_provider.h:86
clan::Texture
Texture object class.
Definition: texture.h:103
clan::GraphicContextProvider::get_shader_language
virtual ShaderLanguage get_shader_language() const =0
Returns the shader language used.
clan::GraphicContextProvider::draw_primitives
virtual void draw_primitives(PrimitivesType type, int num_vertices, const PrimitivesArray &primitives_array)=0
Draw primitives on gc.
clan::GraphicContextProvider::set_primitives_elements
virtual void set_primitives_elements(ElementArrayBufferProvider *array_provider)=0
Sets current elements array buffer.
clan::OcclusionQueryProvider
Occlusion query provider.
Definition: occlusion_query_provider.h:40
clan::PixelBuffer
Pixel data container.
Definition: pixel_buffer.h:68
clan::RasterizerStateProvider::~RasterizerStateProvider
virtual ~RasterizerStateProvider()
Definition: graphic_context_provider.h:70
clan::GraphicContextProvider::draw_primitives_array
virtual void draw_primitives_array(PrimitivesType type, int offset, int num_vertices)=0
Draws primitives from the current assigned primitives array.
clan::GraphicContextProvider::is_frame_buffer_owner
virtual bool is_frame_buffer_owner(const FrameBuffer &fb)=0
Returns true if this frame buffer object is owned by this graphic context.
clan::Key::x
clan::TextureDimensions
TextureDimensions
Texture dimensions.
Definition: texture.h:91
clan::GraphicContextProvider::set_viewport
virtual void set_viewport(const Rectf &viewport)=0
Set the viewport to be used in user projection map mode.
clan::PixelBufferProvider
Element Array Buffer provider.
Definition: pixel_buffer_provider.h:42
clan::GraphicContextProvider::reset_scissor
virtual void reset_scissor()=0
Reset scissor.
clan::DrawBuffer
DrawBuffer
Drawing buffers.
Definition: graphic_context.h:118
clan::GraphicContextProvider::set_texture
virtual void set_texture(int unit_index, const Texture &texture)=0
Select texture into unit.
clan::GraphicContextProvider::get_display_window_size
virtual Size get_display_window_size() const =0
Returns the current size of the display window.
clan::GraphicContextProvider::draw_primitives_elements
virtual void draw_primitives_elements(PrimitivesType type, int count, VertexAttributeDataType indices_type, size_t offset=0)=0
Draw primitives elements.
clan::GraphicContextProvider::get_major_version
virtual int get_major_version() const =0
Returns the major version / feature level supported by the hardware.
clan::ShaderLanguage
ShaderLanguage
Shader language used.
Definition: graphic_context.h:248
clan::TransferBufferProvider
Transfer Buffer provider.
Definition: transfer_buffer_provider.h:42
clan::DepthStencilStateProvider
Definition: graphic_context_provider.h:79
clan::ClipZRange
ClipZRange
Definition: mat4.h:51
clan::GraphicContextProvider::reset_storage_buffer
virtual void reset_storage_buffer(int index)=0
Remove storage buffer from index.
clan::RasterizerStateProvider
Definition: graphic_context_provider.h:67
clan::BlendStateProvider::~BlendStateProvider
virtual ~BlendStateProvider()
Definition: graphic_context_provider.h:76
clan::GraphicContextProvider::draw_primitives_array_instanced
virtual void draw_primitives_array_instanced(PrimitivesType type, int offset, int num_vertices, int instance_count)=0
Draws instanced primitives from the current assigned primitives array.
clan::GraphicContextProvider::set_depth_range
virtual void set_depth_range(float n, float f)=0
Specifies the depth range for all viewports.
clan::GraphicContextProvider::alloc_vertex_array_buffer
virtual VertexArrayBufferProvider * alloc_vertex_array_buffer()=0
Allocate vertex array buffer provider for this gc.
clan::GraphicContextProvider::set_program_object
virtual void set_program_object(StandardProgram standard_program)=0
Set active program object to the standard program specified.
clan::GraphicContextProvider::clear
virtual void clear(const Colorf &color)=0
Clears the whole context using the specified color.
clan::GraphicContextProvider::dispatch
virtual void dispatch(int x, int y, int z)=0
Execute a compute shader.
clan::GraphicContextProvider::alloc_texture
virtual TextureProvider * alloc_texture(TextureDimensions texture_dimensions)=0
Allocate texture provider for this gc.
clan::GraphicContextProvider::set_blend_state
virtual void set_blend_state(BlendStateProvider *state, const Colorf &blend_color, unsigned int sample_mask)=0
Set active blend state.
clan::StandardProgram
StandardProgram
Standard Program.
Definition: graphic_context.h:239
clan::Rect
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:470
clan::GraphicContextProvider::alloc_render_buffer
virtual RenderBufferProvider * alloc_render_buffer()=0
Allocate render buffer provider for this gc.
clan::StorageBufferProvider
Storage Buffer provider.
Definition: storage_buffer_provider.h:40
clan::GraphicContextProvider::create_depth_stencil_state
virtual std::shared_ptr< DepthStencilStateProvider > create_depth_stencil_state(const DepthStencilStateDescription &desc)=0
Retrieve depth-stencil state object.
clan::Key::f
clan::ShaderObjectProvider
Shader Object provider.
Definition: shader_object_provider.h:42
clan::BlendStateProvider
Definition: graphic_context_provider.h:73
clan::Rectf
2D (left,top,right,bottom) rectangle structure - Float
Definition: rect.h:484
clan::GraphicContextProvider::draw_primitives_elements_instanced
virtual void draw_primitives_elements_instanced(PrimitivesType type, int count, VertexAttributeDataType indices_type, size_t offset, int instance_count)=0
Draw primitives elements instanced.
clan::Key::y
clan::GraphicContextProvider::set_primitives_array
virtual void set_primitives_array(const PrimitivesArray &primitives_array)=0
Set the primitives array on the gc.
clan::GraphicContextProvider::alloc_transfer_buffer
virtual TransferBufferProvider * alloc_transfer_buffer()=0
Allocate transfer buffer provider for this gc.
clan::TextureFormat
TextureFormat
Texture format.
Definition: texture_format.h:40
clan::GraphicContextProvider::has_compute_shader_support
virtual bool has_compute_shader_support() const =0
Returns true if the hardware supports compute shaders.
clan::TextureImageYAxis
TextureImageYAxis
Y axis direction for viewports, clipping rects, textures and render targets.
Definition: graphic_context.h:232
clan::GraphicContextProvider::alloc_primitives_array
virtual PrimitivesArrayProvider * alloc_primitives_array()=0
Allocate primitives array provider for this gc.
clan::GraphicContextProvider::reset_primitives_elements
virtual void reset_primitives_elements()=0
Resets current elements array buffer.
clan::Signal
Definition: signal.h:104
clan::GraphicContextProvider::alloc_frame_buffer
virtual FrameBufferProvider * alloc_frame_buffer()=0
Allocate frame buffer provider for this gc.
clan::GraphicContextProvider::get_texture_image_y_axis
virtual TextureImageYAxis get_texture_image_y_axis() const =0
Returns the Y axis direction for viewports, clipping rects, textures and render targets.
clan::GraphicContextProvider::get_minor_version
virtual int get_minor_version() const =0
Returns the major version / feature level supported by the hardware.
clan::GraphicContextProvider::~GraphicContextProvider
virtual ~GraphicContextProvider()
Definition: graphic_context_provider.h:92
clan::VertexArrayBufferProvider
Vertex Array Buffer provider.
Definition: vertex_array_buffer_provider.h:42
clan::UniformBuffer
Uniform Buffer.
Definition: uniform_buffer.h:47
clan::TextureProvider
Interface for implementing a Texture target.
Definition: texture_provider.h:50
clan::GraphicContextProvider::reset_primitives_array
virtual void reset_primitives_array()=0
Reset the primitives arrays.
clan::DepthStencilStateDescription
DepthStencil state description.
Definition: depth_stencil_state_description.h:42
clan::VertexAttributeDataType
VertexAttributeDataType
Primitives array description.
Definition: primitives_array.h:56
clan::GraphicContextProvider::set_scissor
virtual void set_scissor(const Rect &rect)=0
Set scissor.
clan::GraphicContextProvider::reset_texture
virtual void reset_texture(int unit_index)=0
Remove texture from unit.
clan::GraphicContextProvider::get_max_attributes
virtual int get_max_attributes()=0
Returns the maximum amount of attributes available.
clan::GraphicContextProvider::alloc_pixel_buffer
virtual PixelBufferProvider * alloc_pixel_buffer()=0
Allocate pixel buffer provider for this gc.
clan::GraphicContextProvider::create_rasterizer_state
virtual std::shared_ptr< RasterizerStateProvider > create_rasterizer_state(const RasterizerStateDescription &desc)=0
Retrieve rasterizer state object.
clan::GraphicContextProvider::get_max_texture_size
virtual Size get_max_texture_size() const =0
Returns the maximum size of a texture this graphic context supports.
clan::GraphicContextProvider::set_storage_buffer
virtual void set_storage_buffer(int index, const StorageBuffer &buffer)=0
Select storage buffer into index.
clan::BrushWrapMode::clamp
clan::ProgramObject
Program Object.
Definition: program_object.h:69
clan::GraphicContextProvider::clear_stencil
virtual void clear_stencil(int value)=0
Clear the stencil buffer.
clan::GraphicContextProvider::reset_frame_buffer
virtual void reset_frame_buffer()=0
Set the rendering buffer back to the screen.
clan::GraphicContextProvider::alloc_storage_buffer
virtual StorageBufferProvider * alloc_storage_buffer()=0
Allocate storage buffer provider for this gc.
clan::GraphicContextProvider::sig_window_resized
virtual Signal< void(const Size &)> & sig_window_resized()=0
Get the window resized signal.
clan::GraphicContextProvider::get_program_object
virtual ProgramObject get_program_object(StandardProgram standard_program) const =0
Get a program object from the standard program specified.
clan::Size
2D (width,height) size structure - Integer
Definition: size.h:156
clan::GraphicContextProvider::alloc_occlusion_query
virtual OcclusionQueryProvider * alloc_occlusion_query()=0
Allocate occlusion query provider of this gc.
clan::GraphicContextProvider::set_frame_buffer
virtual void set_frame_buffer(const FrameBuffer &write_buffer, const FrameBuffer &read_buffer)=0
Set a frame buffer for off-screen rendering.
clan::GraphicContextProvider::alloc_element_array_buffer
virtual ElementArrayBufferProvider * alloc_element_array_buffer()=0
Allocate element array buffer provider for this gc.
clan::StorageBuffer
Storage Buffer.
Definition: storage_buffer.h:47
clan::FrameBufferProvider
Interface for implementing a FrameBuffer target.
Definition: frame_buffer_provider.h:45
clan::GraphicContextProvider::alloc_program_object
virtual ProgramObjectProvider * alloc_program_object()=0
Allocate program object provider of this gc.
clan::GraphicContextProvider::reset_uniform_buffer
virtual void reset_uniform_buffer(int index)=0
Remove uniform buffer from index.
clan::GraphicContextProvider::alloc_shader_object
virtual ShaderObjectProvider * alloc_shader_object()=0
Allocate shader object provider of this gc.
clan::GraphicContextProvider::reset_program_object
virtual void reset_program_object()=0
Remove active program object.
clan::UniformBufferProvider
Uniform Buffer provider.
Definition: uniform_buffer_provider.h:40
clan::StyleValueType::color
value is an url
clan::ElementArrayBufferProvider
Element Array Buffer provider.
Definition: element_array_buffer_provider.h:40
clan::PrimitivesType
PrimitivesType
Primitive types.
Definition: graphic_context.h:220
clan::GraphicContextProvider::is_primitives_array_owner
virtual bool is_primitives_array_owner(const PrimitivesArray &primitives_array)=0
Returns true if this primitives_array is owned by this graphic context.
clan::GraphicContextProvider::clear_depth
virtual void clear_depth(float value)=0
Clear the depth buffer.
clan::GraphicContextProvider::get_pixeldata
virtual PixelBuffer get_pixeldata(const Rect &rect, TextureFormat texture_format, bool clamp) const =0
Return the content of the draw buffer into a pixel buffer.
clan::GraphicContextProvider::flush
virtual void flush()=0
clan::GraphicContextProvider::create_blend_state
virtual std::shared_ptr< BlendStateProvider > create_blend_state(const BlendStateDescription &desc)=0
Retrieve blend state object.
clan::GraphicContextProvider::set_uniform_buffer
virtual void set_uniform_buffer(int index, const UniformBuffer &buffer)=0
Select uniform buffer into index.
clan::Key::z