OSDN Git Service

first
[psychlops/cpp.git] / psychlops / platform / win32gl / psychlops_g_API_win32gl.h
1 #ifndef HEADER_PSYCHLOPS_GRAPHIC_API_WIN32\r
2 #define HEADER_PSYCHLOPS_GRAPHIC_API_WIN32\r
3
4 #include <vector>\r
5 #include <string>
6 \r
7 #include <windows.h>\r
8 #include <gl/gl.h>\r
9 \r
10 \r
11 #include "../../core/graphic/psychlops_g_image.h"\r
12 #include "../../core/graphic/psychlops_g_font.h"\r
13 #include "../gl/psychlops_g_cache.h"\r
14 \r
15 \r
16 namespace Psychlops {\r
17 \r
18         class Canvas;\r
19         class DebugTweakTool;\r
20         class APICanvasProperties {\r
21                 friend class Canvas;\r
22                 friend class DebugTweakTool;\r
23                 public:\r
24                 enum WINDOW_TYPE { FULLSCREEN, WINDOW };\r
25 \r
26         protected:\r
27                 static WNDCLASSEX wcx;
28                 static bool wcx_setted;
29                 static void setWindowClass();
30 \r
31         public:\r
32 \r
33                 HDC the_display_;                               //      Handle for Device Context\r
34                 HWND the_window_;                       //      Handle for Window\r
35                 HGLRC the_GL_context_;                  //      Handle for OpenGL Context\r
36                 DEVMODE mode_, original_mode_;
37                 int vleft, vright, vtop, vbottom;\r
38 \r
39                 bool has_instance_;
40                 bool vsync_available_;\r
41                 WINDOW_TYPE window_type;\r
42                 BOOL err;\r
43 \r
44         public:
45                 Canvas *outer;\r
46                 int width_, height_, colordepth_;\r
47                 double refreshrate_;\r
48 \r
49         public:\r
50                 APICanvasProperties();\r
51                 virtual ~APICanvasProperties();
52                 void getDisplayMertix(const Display& d);\r
53                 void generateCanvasInstance(const Display& d);\r
54                 void generateCanvasInstance(int d_width, int d_height, int d_colordepth, double d_refreshrate, const Display& d);\r
55                 void generateCanvasInstance(DEVMODE &d_mode, const Display& d);\r
56                 void destroyCanvasInstance();\r
57         protected:\r
58                 void attachOpenGLContext(HWND *hWnd, HDC *hDC, HGLRC *hRC, int d_colordepth);\r
59                 void detachOpenGLContext(HWND hWnd, HDC hDC, HGLRC hRC);\r
60
61         ////    Gamma Table Section
62         public:\r
63                 void flip();\r
64         /*\r
65                 // OLD\r
66                 void cacheLetters(Letters &letter);
67                 void uncacheLetters(Letters &letter);
68                 void drawLetters(
69                         Letters &letters, const double x, const double y,
70                         const double r, const double g, const double b, const double a,
71                         const int horiz_align, const double max_width);\r
72 \r
73                 // NEW\r
74         protected:\r
75                 class TextCacheAllocation\r
76                 {\r
77                         public:\r
78                         bool dirty_;\r
79                         Image img;\r
80                         TextCacheAllocation();\r
81                         ~TextCacheAllocation();\r
82                         void dirty();\r
83                         void uncache();\r
84                 };\r
85                 std::map<Letters*, TextCacheAllocation *> text_cache;\r
86                 bool isCached(Letters &letters);\r
87                 */\r
88         protected:\r
89                 Utilities::TextCacheManager text_cache;\r
90         public:\r
91                 void draw(\r
92                         Letters &letters, const double x, const double y,\r
93                         const double r, const double g, const double b, const double a,\r
94                         const int horiz_align, const int vertical_align, const double max_width);\r
95                 //void draw(Letters &letters);\r
96                 void cache(Letters &letters);\r
97                 void uncache(Letters &letters);\r
98                 void uncacheAllLetters();\r
99                 void cacheText(Letters &drawee, Utilities::CacheOnImage &alloc);\r
100 \r
101
102         ////    Gamma Table Section
103         public:
104                 enum { RAMP_STEPS_ = 256 };
105                 struct GAMMA_RAMP_TABLE {
106                         WORD r[RAMP_STEPS_];
107                         WORD g[RAMP_STEPS_];
108                         WORD b[RAMP_STEPS_];
109                 };
110                 GAMMA_RAMP_TABLE savedGammaRamp_;
111                 LPVOID savedGammaRamp_ptr_;
112                 int calibration_mode_;
113
114                 double limit(double v);
115                 void setGammaValue(const double gamma_r, const double gamma_g, const double gamma_b);
116                 void setGammaTable(const std::vector<double> &table_r, const std::vector<double> &table_g, const std::vector<double> &table_b);
117                 void setGammaTable(LPVOID table);
118                 void saveGammaValue();
119                 int getGammaMode();
120                 void destroyGammaSettings();
121                 /*      Psychlops is not event-message based application,\r
122                         thus we omit "main loop" recieving mesasges from Windows OS or other applications.\r
123                         PsychlopsAPP recieves messages through Canvas::flip(),\r
124                         or recieve on main loop and "virtual main" function runs on another thread.     */\r
125                 Point left_top();\r
126 \r
127                 void shift(int x, int y);\r
128         };\r
129
130         class APICanvasPropertiesFullscreen : public APICanvasProperties {
131         public:
132                 APICanvasPropertiesFullscreen(const Display &target);
133                 APICanvasPropertiesFullscreen(int d_width, int d_height, int d_colordepth, double d_refreshrate, const Display &target);
134         };
135
136         class APICanvasPropertiesWindow : public APICanvasProperties {
137         public:
138                 APICanvasPropertiesWindow(int d_width, int d_height, const Display& d);
139                 APICanvasPropertiesWindow(int d_left, int d_top, int d_width, int d_height);
140                 virtual ~APICanvasPropertiesWindow();
141                 void generate(int d_left, int d_top, int d_width, int d_height);
142         };
143
144 \r
145         class Image;
146         namespace Devices { class CanvasBits; }
147         class APIImageCache {
148                 friend class Canvas;
149                 friend class Image;
150                 friend class Devices::CanvasBits;
151                 public:
152                 GLuint VRAMoffset, tex_width, tex_height;
153                 APIImageCache();
154                 unsigned int getTexIndex();
155         };\r
156         class APIImageProperties {\r
157                 friend class Canvas;
158                 friend class Image;\r
159                 friend class Devices::CanvasBits;
160                 private:\r
161 //              static int max_reg, rights_[10+1], bottoms_[10+1];\r
162
163                 const Image *outer_;
164                 static const int PixCompGL_[3];
165                 static const int PixPrecGL_[2];
166 \r
167                 public:\r
168 //              static bool regist(int maxwidth, int maxheight, int width, int height, int &left, int &top);\r
169                 APIImageProperties();\r
170                 APIImageProperties(Image *outer);
171                 virtual ~APIImageProperties();
172                 void attach();\r
173                 void detach();\r
174                 void drawText(int x, int y, const char* str, int strlength);\r
175         };
176 \r
177         class APIFontProperties {
178                 protected:
179                 bool cached;
180                 GLuint cache_id, length;\r
181                 double base_width, base_height;
182                 GLushort *lists;
183                 static const GLushort lists100[100];
184
185                 public:
186                 APIFontProperties();
187                 virtual ~APIFontProperties();
188                 void uncache();
189                 void uncache(const HDC &ctx);
190                 void cache(const HDC &ctx, Letters &letters);\r
191                 void culcVirtualMetrix(Letters &letters);
192                 void draw(const HDC &ctx,
193                         const Letters &letters, const double x, const double y,
194                         const double r, const double g, const double b, const double a,
195                         const int horiz_align, const double max_width) const;
196
197         };\r
198 \r
199 \r
200
201 }       /*      <- namespace Psycholops         */
202 \r
203 #endif\r
204 \r