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 "../../Core/System/sharedptr.h"
00039 #include "primitives_array.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
00045 class CL_Size;
00046 class CL_BufferControl;
00047 class CL_PolygonRasterizer;
00048 class CL_Pen;
00049 class CL_BlendMode;
00050 class CL_Texture;
00051 class CL_FrameBuffer;
00052 class CL_PixelBuffer;
00053 class CL_PixelBufferRef;
00054 class CL_PrimitivesArray;
00055 class CL_Font;
00056 class CL_FontMetrics;
00057 class CL_GraphicContextProvider;
00058 class CL_GraphicContext_Impl;
00059 class CL_ProgramObject;
00060 class CL_ElementArrayBuffer;
00061 class CL_Angle;
00062 class CL_RenderBatcher;
00063 class CL_FontProvider_Freetype;
00064
00068 enum CL_PrimitivesType
00069 {
00070 cl_points,
00071 cl_line_strip,
00072 cl_line_loop,
00073 cl_lines,
00074 cl_triangle_strip,
00075 cl_triangle_fan,
00076 cl_triangles,
00077 cl_quad_strip,
00078 cl_quads,
00079 cl_polygon
00080 };
00081
00085 enum CL_MapMode
00086 {
00087 cl_map_2d_upper_left,
00088 cl_map_2d_lower_left,
00089 cl_user_projection
00090 };
00091
00095 enum CL_StandardProgram
00096 {
00097 cl_program_color_only,
00098 cl_program_single_texture,
00099 cl_program_sprite
00100 };
00101
00105 class CL_API_DISPLAY CL_GraphicContext
00106 {
00109
00110 public:
00112 CL_GraphicContext();
00113
00117 CL_GraphicContext(CL_GraphicContextProvider *provider);
00118
00119 ~CL_GraphicContext();
00120
00124 public:
00126 CL_Texture get_texture(int index);
00127
00129 CL_BlendMode get_blend_mode();
00130
00132 CL_BufferControl get_buffer_control();
00133
00135 CL_PolygonRasterizer get_polygon_rasterizer();
00136
00138 CL_Pen get_pen();
00139
00141 int get_width() const;
00142
00144 int get_height() const;
00145
00147 CL_Size get_size() const;
00148
00150 CL_Rect get_cliprect() const;
00151
00153 const CL_Mat4f &get_modelview() const;
00154
00156
00158 CL_Size get_max_texture_size() const;
00159
00161 CL_GraphicContextProvider *get_provider();
00162
00163 const CL_GraphicContextProvider * const get_provider() const;
00164
00168 public:
00170
00174 CL_GraphicContext create_worker_gc();
00175
00177 CL_PixelBuffer get_pixeldata(const CL_Rect& rect = CL_Rect(0,0,0,0)) const;
00178
00180 void set_frame_buffer(const CL_FrameBuffer &frame_buffer);
00181
00183 void reset_frame_buffer();
00184
00186 void set_texture(int unit_index, const CL_Texture &texture);
00187
00189 void reset_texture(int unit_index);
00190
00192 void set_program_object(CL_StandardProgram standard_program);
00193
00195 void set_program_object(const CL_ProgramObject &program);
00196
00198 void reset_program_object();
00199
00201 void set_blend_mode(const CL_BlendMode &blend_mode);
00202
00204 void reset_blend_mode();
00205
00207 void set_buffer_control(const CL_BufferControl &buffer_control);
00208
00210 void reset_buffer_control();
00211
00213 void set_pen(const CL_Pen &pen);
00214
00216 void reset_pen();
00217
00219 void set_polygon_rasterizer(const CL_PolygonRasterizer &raster);
00220
00222 void reset_polygon_rasterizer();
00223
00225 void draw_primitives(CL_PrimitivesType type, int num_vertices, const CL_PrimitivesArray &array);
00226
00228 void set_primitives_array(const CL_PrimitivesArray &array);
00229
00231 void draw_primitives_array(CL_PrimitivesType type, int num_vertices);
00232
00238 void draw_primitives_array(CL_PrimitivesType type, int offset, int num_vertices);
00239
00245 void draw_primitives_elements(CL_PrimitivesType type, int count, unsigned int *indices);
00246
00252 void draw_primitives_elements(CL_PrimitivesType type, int count, unsigned short *indices);
00253
00259 void draw_primitives_elements(CL_PrimitivesType type, int count, unsigned char *indices);
00260
00268 void draw_primitives_elements(CL_PrimitivesType type, int count, CL_ElementArrayBuffer &element_array, CL_VertexAttributeDataType indices_type, void *offset = 0);
00269
00271 void reset_primitives_array();
00272
00274 void draw_pixels(float x, float y, const CL_PixelBufferRef &pixel_buffer, const CL_Colorf &color = CL_Colorf::white);
00275
00284 void draw_pixels(float x, float y, float zoom_x, float zoom_y, const CL_PixelBufferRef &pixel_buffer, const CL_Colorf &color = CL_Colorf::white);
00285
00287 void clear(const CL_Colorf &color = CL_Colorf::black);
00288
00292 void clear_stencil(int value = 0);
00293
00297 void clear_depth(float value = 0);
00298
00300 void set_cliprect(const CL_Rect &rect);
00301
00303
00306 void push_cliprect(const CL_Rect &rect);
00307
00309 void push_cliprect();
00310
00312 void pop_cliprect();
00313
00315 void reset_cliprect();
00316
00318 void set_map_mode(CL_MapMode mode);
00319
00321 void set_viewport(const CL_Rectf &viewport);
00322
00324 void set_projection(const CL_Mat4f &matrix);
00325
00327 void set_modelview(const CL_Mat4f &matrix);
00328
00330 void mult_modelview(const CL_Mat4f &matrix);
00331
00333 void push_modelview();
00334
00336
00338 void set_translate(float x, float y, float z = 0.0);
00339
00341
00345 void mult_translate(float x, float y, float z = 0.0);
00346
00348
00353 void push_translate(float x, float y, float z = 0.0);
00354
00356 void set_rotate(const CL_Angle &angle, float x = 0.0, float y = 0.0, float z = 1.0, bool normalize = true);
00357
00359 void mult_rotate(const CL_Angle &angle, float x = 0.0, float y = 0.0, float z = 1.0, bool normalize = true);
00360
00362 void push_rotate(const CL_Angle &angle, float x = 0.0, float y = 0.0, float z = 1.0);
00363
00365 void set_scale(float x, float y, float z = 1.0);
00366
00368 void mult_scale(float x, float y, float z = 1.0);
00369
00371 void push_scale(float x, float y, float z = 1.0);
00372
00374 void pop_modelview();
00375
00377 void flush_batcher();
00378
00383 void set_batcher(CL_RenderBatcher *batcher);
00384
00388 public:
00390 CL_Signal_v0 &sig_gc_destruction_imminent();
00391
00395 private:
00396 CL_SharedPtr<CL_GraphicContext_Impl> impl;
00397
00398 friend class CL_PrimitivesArray;
00399 friend class CL_Sprite_Impl;
00400 friend class CL_Image;
00401 friend class CL_GlyphCache;
00402 friend class CL_Draw;
00404 };
00405
00406 #ifndef cl_pixelcenter_constant
00407 #define cl_pixelcenter_constant 0.375f
00408 #endif
00409