OSDN Git Service

first
[psychlops/cpp.git] / psychlops / platform / osx / psychlops_g_API_Lion.h
1 /*
2  *  psychlops_g_canvas_API_OSX.h
3  *  Psychlops Standard Library (MacOSX)
4  *
5  *  Last Modified 2005/12/24 by Kenchi HOSOKAWA
6  *  (C) 2005 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO
7  */
8
9 #ifndef HEADER_PSYCHLOPS_GRAPHIC_API_OSX
10 #define HEADER_PSYCHLOPS_GRAPHIC_API_OSX
11
12 #include <vector>
13
14 #include <ApplicationServices/ApplicationServices.h>
15 #include <CoreServices/CoreServices.h>
16 #include <OpenGL/OpenGL.h>
17 #include <OpenGL/gl.h>
18 #include <AGL/agl.h>
19
20 #include <mach/mach.h>
21 #include <mach/mach_time.h>
22
23 #include "../../core/graphic/psychlops_g_font.h"
24 #include "../../core/graphic/psychlops_g_image.h"
25
26
27 namespace Psychlops {
28         
29         class Canvas;
30         class Display;
31         class APICanvasProperties;
32         class APIImageProperties;
33         class APIFontProperties;
34         class DebugTweakTool;
35         
36         
37         struct WindowMetrix {
38         public:
39                 int width, height, colordepth;
40                 double refreshrate;
41         };
42         
43         class APICanvasProperties {
44         public:
45                 bool vsync_available_;
46                 Canvas *outer;
47         protected:
48                 bool has_instance_;
49                 OSStatus err;
50                 CGDirectDisplayID target_display_;
51                 //              CGDisplayErr disperr;
52                 CFDictionaryRef current_mode_, original_mode_;
53                 CGGammaValue
54                 savedRedMin_, savedRedMax_, savedRedGamma_,
55                 savedGreenMin_, savedGreenMax_, savedGreenGamma_,
56                 savedBlueMin_, savedBlueMax_, savedBlueGamma_;
57                 int gamma_mode_;
58                 CGContextRef quartz_context_;
59                 
60         public:
61                 int width_, height_, colordepth_;
62                 double refreshrate_;
63                 
64         public:
65                 APICanvasProperties();
66                 virtual ~APICanvasProperties();
67                 virtual void flip() = 0;
68                 
69                 WindowMetrix getDisplayMetrix(CGDirectDisplayID target);
70                 void setGammaValue(const double gamma_r, const double gamma_g, const double gamma_b);
71                 void setGammaTable(const std::vector<double> &table_r, const std::vector<double> &table_g, const std::vector<double> &table_b);
72                 void setGammaTable(const CGGammaValue * const table_r, const CGGammaValue * const table_g, const CGGammaValue * const table_b, const int num_steps);
73                 void saveGammaValue();
74                 void destroyGammaSettings();
75                 
76                 //void cacheLetters(Letters &letter);
77                 //void uncacheLetters(Letters &letter);
78                 void cache(Letters &letter);
79                 void uncache(Letters &letter);
80                 void drawLetters(
81                                                  Letters &letters, const double x, const double y,
82                                                  const Color & col,
83                                                  //                     const double r, const double g, const double b, const double a,
84                                                  const int horiz_align, const int vertical_align, const double max_width);
85                 virtual Point left_top() = 0;
86         };
87         
88         class APICanvasPropertiesFullscreen : public APICanvasProperties {
89         private:
90                 CGLContextObj cgl_context_;
91                 CGOpenGLDisplayMask dispOpenGLDisplayMask;
92                 Point lefttop;
93         public:
94                 APICanvasPropertiesFullscreen(const Display &target);
95                 APICanvasPropertiesFullscreen(int d_width, int d_height, int d_colordepth, double d_refreshrate, const Display &target);
96                 virtual ~APICanvasPropertiesFullscreen();
97                 void generateCanvasInstance(const Display &target);
98                 void generateCanvasInstance(int d_width, int d_height, int d_colordepth, double d_refreshrate, const Display &target);
99                 void generateCanvasInstance(CFDictionaryRef d_mode, CGDirectDisplayID target);
100                 void destroyCanvasInstance();
101                 virtual void flip();
102                 virtual void waitRefresh();
103                 virtual Point left_top();
104         };
105         
106         class APICanvasPropertiesWindow : public APICanvasProperties {
107                 friend class DebugTweakTool;
108         private:
109                 void *api_objc_;
110                 WindowRef window_;
111                 AGLContext agl_context_;
112                 Point lefttop;
113         public:
114                 APICanvasPropertiesWindow();
115                 APICanvasPropertiesWindow(int d_width, int d_height, const Display& d);
116                 APICanvasPropertiesWindow(int d_left, int d_top, int d_width, int d_height);
117                 virtual ~APICanvasPropertiesWindow();
118                 void generateCanvasInstance(int d_left, int d_top, int d_width, int d_height);
119                 void destroyCanvasInstance();
120                 virtual void flip();
121                 virtual Point left_top();
122         };
123         
124         
125         class Image;
126         class APIImageCache {
127                 friend class Canvas;
128                 friend class Image;
129                 friend class APIFontProperties;
130         public:
131                 GLuint VRAMoffset, tex_width, tex_height;
132                 unsigned int getTexIndex();
133         };
134         class Devices::CanvasBits;
135         class APIImageProperties {
136                 friend class Canvas;
137                 friend class Image;
138                 friend class APIFontProperties;
139                 friend class Devices::CanvasBits;
140         private:
141                 //              static int max_reg, rights_[10+1], bottoms_[10+1];
142                 
143                 const Image *outer_;
144                 CGContextRef pic_;
145                 CGColorSpaceRef colorSpace;
146                 static const int PixCompGL_[3];
147                 static const int PixPrecGL_[2];
148                 
149         public:
150                 //              static bool regist(int maxwidth, int maxheight, int width, int height, int &left, int &top);
151                 APIImageProperties();
152                 APIImageProperties(Image *outer_);
153                 ~APIImageProperties();
154                 void attach();
155                 void detach();
156                 /*              void drawLetters(
157                  Letters &letters, const double x, const double y,
158                  const double r, const double g, const double b, const double a,
159                  const int horiz_align, const double max_width);*/
160         };
161         
162         
163         class APIFontProperties {
164         protected:
165                 bool cached, layout_defined;
166                 UniChar* theUnicodeText;
167                 ATSUStyle theStyle;
168                 ATSUTextLayout theLayout;
169                 Image cache_img;
170                 int cache_w, cache_h, cache_baseX, cache_baseY;
171                 
172         public:
173                 APIFontProperties();
174                 virtual ~APIFontProperties();
175                 void cache(const CGContextRef &ctx, Letters &letters, DrawableWithCache &target);
176                 void uncache(const CGContextRef &ctx, Letters &letters);
177                 void draw(const CGContextRef &ctx, const Letters &letters, const double x, const double y, const Color &col, const int horiz_align, const double max_width, DrawableWithCache &target);
178                 void setLayout(Letters &letters);
179                 void cache_on_context(const CGContextRef &ctx);
180                 void draw_on_context(const CGContextRef &ctx, const float posX, const float posY, const double r,  const double g,  const double b, const double a);
181                 void cache_on_image(Letters &letters, DrawableWithCache &target);
182                 void draw_cached_image(const double posX, const double posY, const Color &col, DrawableWithCache &target);
183         };
184         
185 }       /*      <- namespace Psycholops         */
186
187
188 #endif
189