graphic_context_provider.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2020 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 #pragma once
31 
32 #include <memory>
33 #include "../Render/graphic_context.h"
34 #include "../Render/primitives_array.h"
35 #include "../Render/texture.h"
36 #include "../../Core/Math/mat4.h"
37 #include "../../Core/Signals/signal.h"
38 
39 namespace clan
40 {
43 
44  class Texture;
45  class Stencil;
46  class TextureProvider;
47  class FontProvider;
48  class Font;
49  class OcclusionQueryProvider;
50  class ProgramObjectProvider;
51  class ShaderObjectProvider;
52  class FrameBufferProvider;
53  class RenderBufferProvider;
54  class VertexArrayBufferProvider;
55  class ElementArrayBufferProvider;
56  class TransferBufferProvider;
57  class FontDescription;
58  class PixelBufferProvider;
59  class UniformBufferProvider;
60  class StorageBufferProvider;
61  class PrimitivesArrayProvider;
62  class RasterizerStateDescription;
63  class BlendStateDescription;
64  class DepthStencilStateDescription;
65 
67  {
68  public:
70  };
71 
73  {
74  public:
75  virtual ~BlendStateProvider() { }
76  };
77 
79  {
80  public:
82  };
83 
86  {
87  public:
88  virtual ~GraphicContextProvider() { return; }
89 
91  virtual int get_max_attributes() = 0;
92 
94 
96  virtual Size get_max_texture_size() const = 0;
97 
99  virtual Size get_display_window_size() const = 0;
100 
102  virtual float get_pixel_ratio() const = 0;
103 
106 
108  virtual ProgramObject get_program_object(StandardProgram standard_program) const = 0;
109 
111  virtual ClipZRange get_clip_z_range() const = 0;
112 
114  virtual TextureImageYAxis get_texture_image_y_axis() const = 0;
115 
117  virtual ShaderLanguage get_shader_language() const = 0;
118 
123  virtual int get_major_version() const = 0;
124 
129  virtual int get_minor_version() const = 0;
130 
135  virtual bool has_compute_shader_support() const = 0;
136 
138  virtual PixelBuffer get_pixeldata(const Rect& rect, TextureFormat texture_format, bool clamp) const = 0;
139 
141  virtual std::unique_ptr<TextureProvider> alloc_texture(TextureDimensions texture_dimensions) = 0;
142 
144  virtual std::unique_ptr<OcclusionQueryProvider> alloc_occlusion_query() = 0;
145 
147  virtual std::unique_ptr<ProgramObjectProvider> alloc_program_object() = 0;
148 
150  virtual std::unique_ptr<ShaderObjectProvider> alloc_shader_object() = 0;
151 
153  virtual std::unique_ptr<FrameBufferProvider> alloc_frame_buffer() = 0;
154 
156  virtual std::unique_ptr<RenderBufferProvider> alloc_render_buffer() = 0;
157 
159  virtual std::unique_ptr<VertexArrayBufferProvider> alloc_vertex_array_buffer() = 0;
160 
162  virtual std::unique_ptr<UniformBufferProvider> alloc_uniform_buffer() = 0;
163 
165  virtual std::unique_ptr<StorageBufferProvider> alloc_storage_buffer() = 0;
166 
168  virtual std::unique_ptr<ElementArrayBufferProvider> alloc_element_array_buffer() = 0;
169 
171  virtual std::unique_ptr<TransferBufferProvider> alloc_transfer_buffer() = 0;
172 
174  virtual std::unique_ptr<PixelBufferProvider> alloc_pixel_buffer() = 0;
175 
177  virtual std::unique_ptr<PrimitivesArrayProvider> alloc_primitives_array() = 0;
178 
180  virtual std::shared_ptr<RasterizerStateProvider> create_rasterizer_state(const RasterizerStateDescription &desc) = 0;
181 
183  virtual std::shared_ptr<BlendStateProvider> create_blend_state(const BlendStateDescription &desc) = 0;
184 
186  virtual std::shared_ptr<DepthStencilStateProvider> create_depth_stencil_state(const DepthStencilStateDescription &desc) = 0;
187 
189  virtual void set_rasterizer_state(RasterizerStateProvider *state) = 0;
190 
192  virtual void set_blend_state(BlendStateProvider *state, const Colorf &blend_color, unsigned int sample_mask) = 0;
193 
195  virtual void set_depth_stencil_state(DepthStencilStateProvider *state, int stencil_ref) = 0;
196 
198  virtual void set_program_object(StandardProgram standard_program) = 0;
199 
203  virtual void set_program_object(const ProgramObject &program) = 0;
204 
206  virtual void reset_program_object() = 0;
207 
209  virtual void set_uniform_buffer(int index, const UniformBuffer &buffer) = 0;
210 
212  virtual void reset_uniform_buffer(int index) = 0;
213 
215  virtual void set_storage_buffer(int index, const StorageBuffer &buffer) = 0;
216 
218  virtual void reset_storage_buffer(int index) = 0;
219 
221  virtual void set_texture(int unit_index, const Texture &texture) = 0;
222 
224  virtual void reset_texture(int unit_index) = 0;
225 
227  virtual void set_image_texture(int unit_index, const Texture &texture) = 0;
228 
230  virtual void reset_image_texture(int unit_index) = 0;
231 
233  virtual bool is_frame_buffer_owner(const FrameBuffer &fb) = 0;
234 
236  virtual void set_frame_buffer(const FrameBuffer &write_buffer, const FrameBuffer &read_buffer) = 0;
237 
239  virtual void reset_frame_buffer() = 0;
240 
241  virtual void set_draw_buffer(DrawBuffer buffer) = 0;
242 
244  virtual bool is_primitives_array_owner(const PrimitivesArray &primitives_array) = 0;
245 
247  virtual void draw_primitives(PrimitivesType type, int num_vertices, const PrimitivesArray &primitives_array) = 0;
248 
250  virtual void set_primitives_array(const PrimitivesArray &primitives_array) = 0;
251 
253  virtual void draw_primitives_array(PrimitivesType type, int offset, int num_vertices) = 0;
254 
256  virtual void draw_primitives_array_instanced(PrimitivesType type, int offset, int num_vertices, int instance_count) = 0;
257 
259  virtual void set_primitives_elements(ElementArrayBufferProvider *array_provider) = 0;
260 
267  virtual void draw_primitives_elements(PrimitivesType type, int count, VertexAttributeDataType indices_type, size_t offset = 0) = 0;
268 
276  virtual void draw_primitives_elements_instanced(PrimitivesType type, int count, VertexAttributeDataType indices_type, size_t offset, int instance_count) = 0;
277 
279  virtual void reset_primitives_elements() = 0;
280 
288  virtual void draw_primitives_elements(PrimitivesType type, int count, ElementArrayBufferProvider *array_provider, VertexAttributeDataType indices_type, void *offset) = 0;
289 
297  virtual void draw_primitives_elements_instanced(PrimitivesType type, int count, ElementArrayBufferProvider *array_provider, VertexAttributeDataType indices_type, void *offset, int instance_count) = 0;
298 
300  virtual void reset_primitives_array() = 0;
301 
303  virtual void set_scissor(const Rect &rect) = 0;
304 
306  virtual void reset_scissor() = 0;
307 
309  virtual void dispatch(int x, int y, int z) = 0;
310 
312  virtual void clear(const Colorf &color) = 0;
313 
317  virtual void clear_depth(float value) = 0;
318 
322  virtual void clear_stencil(int value) = 0;
323 
325  virtual void set_viewport(const Rectf &viewport) = 0;
326 
328  virtual void set_viewport(int index, const Rectf &viewport) = 0;
329 
331  virtual void set_depth_range(float n, float f) = 0;
332 
334  virtual void set_depth_range(int viewport, float n, float f) = 0;
335 
336  virtual void flush() = 0;
337  };
338 
340 }
Primitives array description.
Definition: primitives_array.h:67
Rasterizer state description.
Definition: rasterizer_state_description.h:41
Definition: clanapp.h:35
virtual ~DepthStencilStateProvider()
Definition: graphic_context_provider.h:81
Floating point color description class (for float).
Definition: color.h:798
virtual std::unique_ptr< UniformBufferProvider > alloc_uniform_buffer()=0
Allocate uniform buffer provider for this gc.
virtual std::shared_ptr< DepthStencilStateProvider > create_depth_stencil_state(const DepthStencilStateDescription &desc)=0
Retrieve depth-stencil state object.
virtual void clear_depth(float value)=0
Clear the depth buffer.
virtual bool is_primitives_array_owner(const PrimitivesArray &primitives_array)=0
Returns true if this primitives_array is owned by this graphic context.
Frame-buffer object class.
Definition: frame_buffer.h:71
virtual int get_max_attributes()=0
Returns the maximum amount of attributes available.
virtual void clear_stencil(int value)=0
Clear the stencil buffer.
virtual bool is_frame_buffer_owner(const FrameBuffer &fb)=0
Returns true if this frame buffer object is owned by this graphic context.
virtual void reset_texture(int unit_index)=0
Remove texture from unit.
Blend state description.
Definition: blend_state_description.h:41
Interface for implementing a GraphicContext target.
Definition: graphic_context_provider.h:85
Texture object class.
Definition: texture.h:102
virtual Signal< void(const Size &)> & sig_window_resized()=0
Get the window resized signal.
Pixel data container.
Definition: pixel_buffer.h:67
virtual void set_rasterizer_state(RasterizerStateProvider *state)=0
Set active rasterizer state.
virtual void set_primitives_elements(ElementArrayBufferProvider *array_provider)=0
Sets current elements array buffer.
TextureDimensions
Texture dimensions.
Definition: texture.h:90
virtual Size get_display_window_size() const =0
Returns the current size of the display window.
virtual void set_scissor(const Rect &rect)=0
Set scissor.
virtual void set_depth_stencil_state(DepthStencilStateProvider *state, int stencil_ref)=0
Set active depth stencil state.
virtual void clear(const Colorf &color)=0
Clears the whole context using the specified color.
virtual void reset_storage_buffer(int index)=0
Remove storage buffer from index.
virtual std::unique_ptr< PrimitivesArrayProvider > alloc_primitives_array()=0
Allocate primitives array provider for this gc.
virtual std::unique_ptr< ShaderObjectProvider > alloc_shader_object()=0
Allocate shader object provider of this gc.
virtual void reset_program_object()=0
Remove active program object.
virtual ~RasterizerStateProvider()
Definition: graphic_context_provider.h:69
DrawBuffer
Drawing buffers.
Definition: graphic_context.h:117
virtual void draw_primitives_elements_instanced(PrimitivesType type, int count, VertexAttributeDataType indices_type, size_t offset, int instance_count)=0
Draw primitives elements instanced.
virtual int get_major_version() const =0
Returns the major version / feature level supported by the hardware.
ShaderLanguage
Shader language used.
Definition: graphic_context.h:247
Definition: graphic_context_provider.h:78
virtual void set_frame_buffer(const FrameBuffer &write_buffer, const FrameBuffer &read_buffer)=0
Set a frame buffer for off-screen rendering.
virtual void reset_primitives_array()=0
Reset the primitives arrays.
ClipZRange
Definition: mat4.h:50
Definition: graphic_context_provider.h:66
virtual void set_program_object(StandardProgram standard_program)=0
Set active program object to the standard program specified.
virtual std::unique_ptr< FrameBufferProvider > alloc_frame_buffer()=0
Allocate frame buffer provider for this gc.
virtual ShaderLanguage get_shader_language() const =0
Returns the shader language used.
virtual void dispatch(int x, int y, int z)=0
Execute a compute shader.
virtual std::unique_ptr< ProgramObjectProvider > alloc_program_object()=0
Allocate program object provider of this gc.
virtual std::unique_ptr< OcclusionQueryProvider > alloc_occlusion_query()=0
Allocate occlusion query provider of this gc.
virtual void reset_image_texture(int unit_index)=0
Remove texture from image unit.
virtual std::shared_ptr< RasterizerStateProvider > create_rasterizer_state(const RasterizerStateDescription &desc)=0
Retrieve rasterizer state object.
virtual Size get_max_texture_size() const =0
Returns the maximum size of a texture this graphic context supports.
virtual void set_blend_state(BlendStateProvider *state, const Colorf &blend_color, unsigned int sample_mask)=0
Set active blend state.
StandardProgram
Standard Program.
Definition: graphic_context.h:238
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:445
virtual ProgramObject get_program_object(StandardProgram standard_program) const =0
Get a program object from the standard program specified.
virtual void draw_primitives_elements(PrimitivesType type, int count, VertexAttributeDataType indices_type, size_t offset=0)=0
Draw primitives elements.
virtual void reset_uniform_buffer(int index)=0
Remove uniform buffer from index.
virtual void set_uniform_buffer(int index, const UniformBuffer &buffer)=0
Select uniform buffer into index.
Definition: graphic_context_provider.h:72
2D (left,top,right,bottom) rectangle structure - Float
Definition: rect.h:459
virtual void draw_primitives(PrimitivesType type, int num_vertices, const PrimitivesArray &primitives_array)=0
Draw primitives on gc.
virtual bool has_compute_shader_support() const =0
Returns true if the hardware supports compute shaders.
virtual std::unique_ptr< TextureProvider > alloc_texture(TextureDimensions texture_dimensions)=0
Allocate texture provider for this gc.
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.
TextureFormat
Texture format.
Definition: texture_format.h:38
TextureImageYAxis
Y axis direction for viewports, clipping rects, textures and render targets.
Definition: graphic_context.h:231
Definition: signal.h:104
virtual float get_pixel_ratio() const =0
Physical pixels/dots per inch.
virtual void set_depth_range(float n, float f)=0
Specifies the depth range for all viewports.
virtual void reset_primitives_elements()=0
Resets current elements array buffer.
Uniform Buffer.
Definition: uniform_buffer.h:46
virtual std::shared_ptr< BlendStateProvider > create_blend_state(const BlendStateDescription &desc)=0
Retrieve blend state object.
virtual ClipZRange get_clip_z_range() const =0
Returns in what range clip space z values are clipped.
virtual std::unique_ptr< TransferBufferProvider > alloc_transfer_buffer()=0
Allocate transfer buffer provider for this gc.
virtual void reset_scissor()=0
Reset scissor.
virtual void set_viewport(const Rectf &viewport)=0
Set the viewport to be used in user projection map mode.
DepthStencil state description.
Definition: depth_stencil_state_description.h:41
virtual std::unique_ptr< StorageBufferProvider > alloc_storage_buffer()=0
Allocate storage buffer provider for this gc.
virtual std::unique_ptr< ElementArrayBufferProvider > alloc_element_array_buffer()=0
Allocate element array buffer provider for this gc.
VertexAttributeDataType
Primitives array description.
Definition: primitives_array.h:55
virtual std::unique_ptr< PixelBufferProvider > alloc_pixel_buffer()=0
Allocate pixel buffer provider for this gc.
virtual void set_texture(int unit_index, const Texture &texture)=0
Select texture into unit.
Program Object.
Definition: program_object.h:68
virtual void reset_frame_buffer()=0
Set the rendering buffer back to the screen.
virtual void set_draw_buffer(DrawBuffer buffer)=0
virtual TextureImageYAxis get_texture_image_y_axis() const =0
Returns the Y axis direction for viewports, clipping rects, textures and render targets.
2D (width,height) size structure - Integer
Definition: size.h:175
Storage Buffer.
Definition: storage_buffer.h:46
virtual std::unique_ptr< VertexArrayBufferProvider > alloc_vertex_array_buffer()=0
Allocate vertex array buffer provider for this gc.
virtual ~GraphicContextProvider()
Definition: graphic_context_provider.h:88
virtual void set_primitives_array(const PrimitivesArray &primitives_array)=0
Set the primitives array on the gc.
Element Array Buffer provider.
Definition: element_array_buffer_provider.h:39
PrimitivesType
Primitive types.
Definition: graphic_context.h:219
virtual int get_minor_version() const =0
Returns the major version / feature level supported by the hardware.
virtual std::unique_ptr< RenderBufferProvider > alloc_render_buffer()=0
Allocate render buffer provider for this gc.
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.
virtual void set_storage_buffer(int index, const StorageBuffer &buffer)=0
Select storage buffer into index.
virtual void set_image_texture(int unit_index, const Texture &texture)=0
Select texture into image unit.
virtual ~BlendStateProvider()
Definition: graphic_context_provider.h:75
virtual void draw_primitives_array(PrimitivesType type, int offset, int num_vertices)=0
Draws primitives from the current assigned primitives array.