00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00033
00034 #pragma once
00035
00036 #include "../api_display.h"
00037 #include "../2D/color.h"
00038 #include "../Image/texture_format.h"
00039 #include "../../Core/System/sharedptr.h"
00040 #include "../../Core/Math/mat4.h"
00041 #include "../../Core/IOData/virtual_directory.h"
00042 #include "../../Core/Math/rect.h"
00043 #include "../../Core/Signals/signal_v0.h"
00044 #include "primitives_array.h"
00045 #include "frame_buffer.h"
00046
00047 class CL_Size;
00048 class CL_BufferControl;
00049 class CL_PolygonRasterizer;
00050 class CL_Pen;
00051 class CL_BlendMode;
00052 class CL_Texture;
00053 class CL_FrameBuffer;
00054 class CL_PixelBuffer;
00055 class CL_PrimitivesArray;
00056 class CL_Font;
00057 class CL_FontMetrics;
00058 class CL_GraphicContextProvider;
00059 class CL_GraphicContext_Impl;
00060 class CL_ProgramObject;
00061 class CL_ElementArrayBuffer;
00062 class CL_Angle;
00063 class CL_RenderBatcher;
00064 class CL_FontProvider_Freetype;
00065
00069 enum CL_PrimitivesType
00070 {
00071 cl_points,
00072 cl_line_strip,
00073 cl_line_loop,
00074 cl_lines,
00075 cl_triangle_strip,
00076 cl_triangle_fan,
00077 cl_triangles
00078 };
00079
00083 enum CL_MapMode
00084 {
00085 cl_map_2d_upper_left,
00086 cl_map_2d_lower_left,
00087 cl_user_projection
00088 };
00089
00095 enum CL_StandardProgram
00096 {
00097 cl_program_color_only,
00098 cl_program_single_texture,
00099 cl_program_sprite
00100 };
00101
00107 enum CL_ProgramMatrixFlags
00108 {
00109 cl_program_matrix_none = 0,
00110 cl_program_matrix_modelview = 0x1,
00111 cl_program_matrix_projection = 0x2,
00112 cl_program_matrix_modelview_projection = 0x4,
00113 cl_program_matrix_normal = 0x8,
00114
00115 cl_program_matrix_all_standard = cl_program_matrix_modelview | cl_program_matrix_projection | cl_program_matrix_modelview_projection | cl_program_matrix_normal
00116
00117 };
00118
00122 class CL_API_DISPLAY CL_GraphicContext
00123 {
00126
00127 public:
00129 CL_GraphicContext();
00130
00134 CL_GraphicContext(CL_GraphicContextProvider *provider);
00135
00136 ~CL_GraphicContext();
00137
00141 public:
00143 bool is_null() const { return !impl; }
00144
00146 void throw_if_null() const;
00147
00152 CL_Texture get_texture(int index) const;
00153
00157 std::vector<CL_Texture> get_textures() const;
00158
00162 CL_BlendMode get_blend_mode() const;
00163
00167 CL_BufferControl get_buffer_control() const;
00168
00172 CL_PolygonRasterizer get_polygon_rasterizer() const;
00173
00177 CL_FrameBuffer get_write_frame_buffer() const;
00178
00182 CL_FrameBuffer get_read_frame_buffer() const;
00183
00187 CL_Pen get_pen() const;
00188
00190 int get_width() const;
00191
00193 int get_height() const;
00194
00196 CL_Size get_size() const;
00197
00199 CL_Rect get_cliprect() const;
00200
00202 const CL_Mat4f &get_modelview() const;
00203
00205
00207 CL_Size get_max_texture_size() const;
00208
00210 CL_GraphicContextProvider *get_provider();
00211
00212 const CL_GraphicContextProvider * const get_provider() const;
00213
00217 public:
00219 CL_PixelBuffer get_pixeldata(const CL_Rect& rect, CL_TextureFormat pixel_format = cl_abgr8, bool clamp = true) const;
00220
00222 CL_PixelBuffer get_pixeldata(CL_TextureFormat pixel_format = cl_abgr8, bool clamp = true) const;
00223
00225 void set_frame_buffer(const CL_FrameBuffer &write_buffer);
00226 void set_frame_buffer(const CL_FrameBuffer &write_buffer, const CL_FrameBuffer &read_buffer);
00227
00229 void reset_frame_buffer();
00230
00235 void set_texture(int unit_index, const CL_Texture &texture);
00236
00242 void set_textures(std::vector<CL_Texture> &textures);
00243
00247 void reset_texture(int unit_index);
00248
00250 void reset_textures();
00251
00253 void set_program_object(CL_StandardProgram standard_program);
00254
00259 void set_program_object(const CL_ProgramObject &program, int program_matrix_flags = cl_program_matrix_all_standard);
00260
00262 void reset_program_object();
00263
00265 void set_blend_mode(const CL_BlendMode &blend_mode);
00266
00268 void reset_blend_mode();
00269
00271 void set_buffer_control(const CL_BufferControl &buffer_control);
00272
00274 void reset_buffer_control();
00275
00277 void set_pen(const CL_Pen &pen);
00278
00280 void reset_pen();
00281
00283 void set_polygon_rasterizer(const CL_PolygonRasterizer &raster);
00284
00286 void reset_polygon_rasterizer();
00287
00289 void draw_primitives(CL_PrimitivesType type, int num_vertices, const CL_PrimitivesArray &array);
00290
00292 void set_primitives_array(const CL_PrimitivesArray &array);
00293
00295 void draw_primitives_array(CL_PrimitivesType type, int num_vertices);
00296
00302 void draw_primitives_array(CL_PrimitivesType type, int offset, int num_vertices);
00303
00310 void draw_primitives_array_instanced(CL_PrimitivesType type, int offset, int num_vertices, int instance_count);
00311
00317 void draw_primitives_elements(CL_PrimitivesType type, int count, unsigned int *indices);
00318
00324 void draw_primitives_elements(CL_PrimitivesType type, int count, unsigned short *indices);
00325
00331 void draw_primitives_elements(CL_PrimitivesType type, int count, unsigned char *indices);
00332
00339 void draw_primitives_elements_instanced(CL_PrimitivesType type, int count, unsigned int *indices, int instance_count);
00340
00347 void draw_primitives_elements_instanced(CL_PrimitivesType type, int count, unsigned short *indices, int instance_count);
00348
00355 void draw_primitives_elements_instanced(CL_PrimitivesType type, int count, unsigned char *indices, int instance_count);
00356
00364 void draw_primitives_elements(CL_PrimitivesType type, int count, CL_ElementArrayBuffer &element_array, CL_VertexAttributeDataType indices_type, void *offset = 0);
00365
00374 void draw_primitives_elements_instanced(CL_PrimitivesType type, int count, CL_ElementArrayBuffer &element_array, CL_VertexAttributeDataType indices_type, void *offset, int instance_count);
00375
00377 void reset_primitives_array();
00378
00382 void draw_pixels(float x, float y, const CL_PixelBuffer &pixel_buffer, const CL_Rect &src_rect, const CL_Colorf &color = CL_Colorf::white);
00383
00395 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);
00396
00398 void clear(const CL_Colorf &color = CL_Colorf::black);
00399
00403 void clear_stencil(int value = 0);
00404
00408 void clear_depth(float value = 0);
00409
00411 void set_cliprect(const CL_Rect &rect);
00412
00414
00417 void push_cliprect(const CL_Rect &rect);
00418
00420 void push_cliprect();
00421
00423 void pop_cliprect();
00424
00426 void reset_cliprect();
00427
00429 void set_map_mode(CL_MapMode mode);
00430
00432 void set_viewport(const CL_Rectf &viewport);
00433
00435 void set_projection(const CL_Mat4f &matrix);
00436
00438 void set_modelview(const CL_Mat4f &matrix);
00439
00441 void mult_modelview(const CL_Mat4f &matrix);
00442
00444 void push_modelview();
00445
00447
00449 void set_translate(float x, float y, float z = 0.0);
00450
00452
00456 void mult_translate(float x, float y, float z = 0.0);
00457
00459
00464 void push_translate(float x, float y, float z = 0.0);
00465
00467 void set_rotate(const CL_Angle &angle, float x = 0.0, float y = 0.0, float z = 1.0, bool normalize = true);
00468
00470 void mult_rotate(const CL_Angle &angle, float x = 0.0, float y = 0.0, float z = 1.0, bool normalize = true);
00471
00473 void push_rotate(const CL_Angle &angle, float x = 0.0, float y = 0.0, float z = 1.0);
00474
00476 void set_scale(float x, float y, float z = 1.0);
00477
00479 void mult_scale(float x, float y, float z = 1.0);
00480
00482 void push_scale(float x, float y, float z = 1.0);
00483
00485 void pop_modelview();
00486
00488 void flush_batcher();
00489
00494 void set_batcher(CL_RenderBatcher *batcher);
00495
00499 public:
00501 CL_Signal_v0 &sig_gc_destruction_imminent();
00502
00506 private:
00507 CL_SharedPtr<CL_GraphicContext_Impl> impl;
00508
00509 friend class CL_PrimitivesArray;
00510 friend class CL_Sprite_Impl;
00511 friend class CL_Image;
00512 friend class CL_GlyphCache;
00513 friend class CL_Draw;
00515 };
00516
00517 #ifndef cl_pixelcenter_constant
00518 #define cl_pixelcenter_constant 0.375f
00519 #endif
00520