ClanLib  2.3.7
graphic_context.h
Go to the documentation of this file.
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2011 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 ** Kenneth Gangstoe
29 */
30 
33 
34 #pragma once
35 
36 #include "../api_display.h"
37 #include "../2D/color.h"
38 #include "../Image/texture_format.h"
39 #include "../../Core/System/sharedptr.h"
40 #include "../../Core/Math/mat4.h"
41 #include "../../Core/IOData/virtual_directory.h"
42 #include "../../Core/Math/rect.h"
43 #include "../../Core/Signals/signal_v0.h"
44 #include "primitives_array.h"
45 #include "frame_buffer.h"
46 
47 class CL_Size;
48 class CL_BufferControl;
50 class CL_Pen;
51 class CL_BlendMode;
52 class CL_Texture;
53 class CL_FrameBuffer;
54 class CL_PixelBuffer;
55 class CL_PrimitivesArray;
56 class CL_Font;
57 class CL_FontMetrics;
59 class CL_GraphicContext_Impl;
60 class CL_ProgramObject;
62 class CL_Angle;
63 class CL_RenderBatcher;
64 class CL_FontProvider_Freetype;
65 
70 {
78 };
79 
84 {
88 };
89 
96 {
100 };
101 
108 {
114 
116 
117 };
118 
123 {
126 
127 public:
130 
135 
137 
141 public:
143  bool is_null() const { return !impl; }
144 
146  void throw_if_null() const;
147 
152  CL_Texture get_texture(int index) const;
153 
157  std::vector<CL_Texture> get_textures() const;
158 
162  CL_BlendMode get_blend_mode() const;
163 
167  CL_BufferControl get_buffer_control() const;
168 
172  CL_PolygonRasterizer get_polygon_rasterizer() const;
173 
177  CL_FrameBuffer get_write_frame_buffer() const;
178 
182  CL_FrameBuffer get_read_frame_buffer() const;
183 
187  CL_Pen get_pen() const;
188 
190  int get_width() const;
191 
193  int get_height() const;
194 
196  CL_Size get_size() const;
197 
199  CL_Rect get_cliprect() const;
200 
202  const CL_Mat4f &get_modelview() const;
203 
205 
207  CL_Size get_max_texture_size() const;
208 
210  CL_GraphicContextProvider *get_provider();
211 
212  const CL_GraphicContextProvider * const get_provider() const;
213 
217 public:
219  CL_PixelBuffer get_pixeldata(const CL_Rect& rect, CL_TextureFormat pixel_format = cl_abgr8, bool clamp = true) const;
220 
222  CL_PixelBuffer get_pixeldata(CL_TextureFormat pixel_format = cl_abgr8, bool clamp = true) const;
223 
225  void set_frame_buffer(const CL_FrameBuffer &write_buffer);
226  void set_frame_buffer(const CL_FrameBuffer &write_buffer, const CL_FrameBuffer &read_buffer);
227 
229  void reset_frame_buffer();
230 
235  void set_texture(int unit_index, const CL_Texture &texture);
236 
242  void set_textures(std::vector<CL_Texture> &textures);
243 
247  void reset_texture(int unit_index);
248 
250  void reset_textures();
251 
253  void set_program_object(CL_StandardProgram standard_program);
254 
259  void set_program_object(const CL_ProgramObject &program, int program_matrix_flags = cl_program_matrix_all_standard);
260 
262  void reset_program_object();
263 
265  void set_blend_mode(const CL_BlendMode &blend_mode);
266 
268  void reset_blend_mode();
269 
271  void set_buffer_control(const CL_BufferControl &buffer_control);
272 
274  void reset_buffer_control();
275 
277  void set_pen(const CL_Pen &pen);
278 
280  void reset_pen();
281 
283  void set_polygon_rasterizer(const CL_PolygonRasterizer &raster);
284 
286  void reset_polygon_rasterizer();
287 
289  void draw_primitives(CL_PrimitivesType type, int num_vertices, const CL_PrimitivesArray &array);
290 
292  void set_primitives_array(const CL_PrimitivesArray &array);
293 
295  void draw_primitives_array(CL_PrimitivesType type, int num_vertices);
296 
302  void draw_primitives_array(CL_PrimitivesType type, int offset, int num_vertices);
303 
310  void draw_primitives_array_instanced(CL_PrimitivesType type, int offset, int num_vertices, int instance_count);
311 
317  void draw_primitives_elements(CL_PrimitivesType type, int count, unsigned int *indices);
318 
324  void draw_primitives_elements(CL_PrimitivesType type, int count, unsigned short *indices);
325 
331  void draw_primitives_elements(CL_PrimitivesType type, int count, unsigned char *indices);
332 
339  void draw_primitives_elements_instanced(CL_PrimitivesType type, int count, unsigned int *indices, int instance_count);
340 
347  void draw_primitives_elements_instanced(CL_PrimitivesType type, int count, unsigned short *indices, int instance_count);
348 
355  void draw_primitives_elements_instanced(CL_PrimitivesType type, int count, unsigned char *indices, int instance_count);
356 
364  void draw_primitives_elements(CL_PrimitivesType type, int count, CL_ElementArrayBuffer &element_array, CL_VertexAttributeDataType indices_type, void *offset = 0);
365 
374  void draw_primitives_elements_instanced(CL_PrimitivesType type, int count, CL_ElementArrayBuffer &element_array, CL_VertexAttributeDataType indices_type, void *offset, int instance_count);
375 
377  void reset_primitives_array();
378 
382  void draw_pixels(float x, float y, const CL_PixelBuffer &pixel_buffer, const CL_Rect &src_rect, const CL_Colorf &color = CL_Colorf::white);
383 
395  void draw_pixels(float x, float y, float zoom_x, float zoom_y, const CL_PixelBuffer &pixel_buffer, const CL_Rect &src_rect, const CL_Colorf &color = CL_Colorf::white);
396 
398  void clear(const CL_Colorf &color = CL_Colorf::black);
399 
403  void clear_stencil(int value = 0);
404 
408  void clear_depth(float value = 0);
409 
411  void set_cliprect(const CL_Rect &rect);
412 
414 
417  void push_cliprect(const CL_Rect &rect);
418 
420  void push_cliprect();
421 
423  void pop_cliprect();
424 
426  void reset_cliprect();
427 
429  void set_map_mode(CL_MapMode mode);
430 
432  void set_viewport(const CL_Rectf &viewport);
433 
435  void set_projection(const CL_Mat4f &matrix);
436 
438  void set_modelview(const CL_Mat4f &matrix);
439 
441  void mult_modelview(const CL_Mat4f &matrix);
442 
444  void push_modelview();
445 
447 
449  void set_translate(float x, float y, float z = 0.0);
450 
452 
456  void mult_translate(float x, float y, float z = 0.0);
457 
459 
464  void push_translate(float x, float y, float z = 0.0);
465 
467  void set_rotate(const CL_Angle &angle, float x = 0.0, float y = 0.0, float z = 1.0, bool normalize = true);
468 
470  void mult_rotate(const CL_Angle &angle, float x = 0.0, float y = 0.0, float z = 1.0, bool normalize = true);
471 
473  void push_rotate(const CL_Angle &angle, float x = 0.0, float y = 0.0, float z = 1.0);
474 
476  void set_scale(float x, float y, float z = 1.0);
477 
479  void mult_scale(float x, float y, float z = 1.0);
480 
482  void push_scale(float x, float y, float z = 1.0);
483 
485  void pop_modelview();
486 
488  void flush_batcher();
489 
494  void set_batcher(CL_RenderBatcher *batcher);
495 
499 public:
501  CL_Signal_v0 &sig_gc_destruction_imminent();
502 
506 private:
507  CL_SharedPtr<CL_GraphicContext_Impl> impl;
508 
509  friend class CL_PrimitivesArray;
510  friend class CL_Sprite_Impl;
511  friend class CL_Image;
512  friend class CL_GlyphCache;
513  friend class CL_Draw;
515 };
516 
517 #ifndef cl_pixelcenter_constant
518 #define cl_pixelcenter_constant 0.375f
519 #endif
520