My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#ifndef _WinGl_WinGl_h_
#define _WinGl_WinGl_h_

#ifndef GLEW_STATIC
#define GLEW_STATIC
#endif
#include <WinGl/glew.h>
#include <WinGl/wglew.h>

#include <GL/gl.h>
#include <GL/glu.h>

#define GUI_WINGL

#include <Painter/Painter.h>

NAMESPACE_UPP

#define IMAGECLASS WinGlImg
#define IMAGEFILE <WinGl/WinGl.iml>
#include <Draw/iml_header.h>
#include <WinGl/Shaders.h>
#include "Resources.brc"

typedef Rect_<float> RectF;
typedef Point_<float> PointF;

struct Fbo : Moveable<Fbo>
{
GLuint texId;
GLuint fbId;
GLuint rbId;
GLenum status;
int width;
int height;
bool ready;

bool Create(int width, int height, bool resize = false);
void Resize(int width, int height);
void Bind();
void Unbind();
void Clear();
void BlitToScreen();
void BlitTo(const Fbo& fbo);
String GetError();

Fbo() : width(0), height(0), ready(false)
{}
};

extern bool glEndSession;
extern HWND hWnd;
extern HWND glHwnd;
extern HDC hDC;
extern HGLRC hRC;
extern Shader alphaMagProg;
extern Shader blurProg;
extern Fbo screenFbo0;
extern Fbo screenFbo1;
extern bool glReady;
extern String error;
extern int glDrawMode;

#define DRAW_ON_TIMER 0
#define DRAW_ON_IDLE 1
#define DRAW_ON_EVENT 2

int CreateGlWindow(HINSTANCE hInstance);
int CreateGlContext();
void ActivateGlContext();
void DestroyGl();
void SerializeGl(Stream& s);
LRESULT CALLBACK glWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int64 GetHighTickCount();

struct FrameInfo {
int64 curr_tick_count;
float fps;
float frame_factor;
float frame_skip;
int64 frame_time;
FrameInfo() : fps(0.f), frame_factor(1.f), frame_skip(60.f), frame_time(0), curr_tick_count(0)
{}
};

extern FrameInfo frameInfo;

extern bool controlPanelActive;
extern bool consoleActive;
float GetFps();

#define CLIP_MODE 2
/*
0 - Scissor clip
1 - Plane clip
2 - Stencil clip
3 - Manual clip
*/

#include <WinGl/FontGl.h>
#include <WinGl/ResGl.h>

enum TransformState {
TS_BEFORE_CTRL_PAINT,
TS_AFTER_CTRL_PAINT,
TS_BEFORE_PAINT,
TS_AFTER_PAINT,
TS_BEFORE_SCREEN,
TS_AFTER_SCREEN
};

#define TEXEL_OFFSET 0.325f

class SystemDraw : public Draw {
public:
virtual dword GetInfo() const;
virtual Size GetPageSize() const;
bool CanSetSurface() { return false; }

void PlaneEquation(double eq[4], float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3);
void SetClipRect(const Rect& r);
void ScissorClip(const Rect& r);
void PlaneClip(const Rect& r);
void StencilClip(const Rect& r, int mode = 0, bool exlude = false);
void SetClip(const Rect& r, int mode = 0, bool exclude = false);

virtual void BeginOp();
virtual void EndOp();
virtual void OffsetOp(Point p);
virtual bool ClipOp(const Rect& r);
virtual bool ClipoffOp(const Rect& r);
virtual bool ExcludeClipOp(const Rect& r);
virtual bool IntersectClipOp(const Rect& r);
virtual bool IsPaintingOp(const Rect& r) const;
virtual Rect GetPaintRect() const;

virtual void DrawRectOp(int x, int y, int cx, int cy, Color color);
virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color);
virtual void DrawImageOp(float x0, float y0, float z0, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, const Image& img, const Rect& src, Color color);
virtual void DrawTextureOp(const RectF& r, int textureId, int width, int height, const RectF& src);
virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color);

virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count,
const int *counts, int count_count,
int width, Color color, Color doxor);
virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count,
const int *subpolygon_counts, int scc,
const int *disjunct_polygon_counts, int dpcc,
Color color, int width, Color outline,
uint64 pattern, Color doxor);
virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color);

virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor);
virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font,
Color ink, int n, const int *dx);

virtual Size GetNativeDpi() const;
virtual void BeginNative();
virtual void EndNative();

virtual int GetCloffLevel() const;

void Text(int x, int y, int angle, const wchar *text, Font font, Color ink,
int outlineStrength, Color outlineColor,
int glowStrength, Color glowColor,
int n, const int *dx);

void ImageColoring(bool b = true) { image_coloring = b; }

RectF UnProject(const RectF& r, float& depth);
void UnProject(float* vtx, float sx, float sy, float dx, float dy);
void UnProject(float& x, float& y, float &z);
void SetVtx(float* vtx, float sx, float sy, float dx, float dy);
void SetProjectionMode(int mode);
bool IsPerspectiveProjection() { return projection_mode == 1; }
bool IsOrthogonalProjection() { return projection_mode == 0; }

private:
static SystemDraw* systemDraw;
friend class FontInfo;
friend class Font;

OpenGLFont fi;

struct Cloff : Moveable<Cloff> {
bool clipping;
bool exclude;
Point org;
Rect drawing_clip;
};

struct MatrixStack : Moveable<MatrixStack>
{
double projection_matrix[16];
double modelview_matrix[16];
int projection_mode;
};

float current_color[4];
float vtx[8];
float crd[8];
double projection_matrix[16];
void SetVec(float* v, float sx, float sy, float dx, float dy);
void SetVec(float* v, int sx, int sy, int dx, int dy);

void SaveCurrentColor();
void RestoreLastColor();

public:
Rect drawing_clip;
Size drawing_size;
Point drawing_offset;
Rect clip;
float r, g, b, a;
float alpha;
float angle;
float scale;
static float blurStrength;
static float grayStrength;

private:
Array<Cloff> cloff;
Array<MatrixStack> mstack;
int ci;
int cn;
int cd;
int mi;
bool image_coloring;
int projection_mode;

void Reset();

protected:

SystemDraw();
void InitClip(const Rect& clip);
void Init();

public:
static SystemDraw& Get() { return *systemDraw; }
static void Flush() { /*glFlush();*/ }
Point GetOffset() const { return drawing_offset; }
SystemDraw(Size sz);
virtual ~SystemDraw();
void ViewPort(int width = -1, int height = -1);
void OrthogonalView(bool clear_modelview = true);
void PerspectiveView(bool clear_modelview = true);
void ApplyTransforms();
void Clear(bool ontransforms = false);
void PushContext();
void PopContext();
float GetAspect() { return drawing_size.cx / (float) drawing_size.cy; };
};

struct BackDraw__ : public SystemDraw {
BackDraw__() {}
};

class BackDraw : public BackDraw__ { // Dummy only, as we are running in GlobalBackBuffer mode
Size size;
Draw *painting;
Point painting_offset;
ImageBuffer ib;

public:
virtual bool IsPaintingOp(const Rect& r) const;

public:
void Put(SystemDraw& w, int x, int y) {}
void Put(SystemDraw& w, Point p) { Put(w, p.x, p.y); }

void Create(SystemDraw& w, int cx, int cy) {}
void Create(SystemDraw& w, Size sz) { Create(w, sz.cx, sz.cy); }
void Destroy() {}

void SetPaintingDraw(Draw& w, Point off) { painting = &w; painting_offset = off; }

BackDraw();
~BackDraw();
};

struct ImageDraw__ {
ImageBuffer image;
ImageBuffer alpha;

ImageDraw__(int cx, int cy) : image(cx, cy), alpha(cx, cy) {}
};

class ImageDraw : private ImageDraw__, public BufferPainter {
BufferPainter alpha_painter;
bool has_alpha;

Image Get(bool pm) const;

public:
Draw& Alpha();

operator Image() const { return Get(true); }

Image GetStraight() const { return Get(false); }

ImageDraw(Size sz);
ImageDraw(int cx, int cy);
};

void DrawDragRect(SystemDraw& w, const Rect& rect1, const Rect& rect2, const Rect& clip, int n, Color color, int type, int animation);

bool GlIsWaitingEvent();
bool GlProcessEvent(bool *quit);
void GlSleep(int ms);
bool GlReady();
bool GlEndSession();
void GlQuitSession();

class PrinterJob { // Dummy only...
NilDraw nil;
Vector<int> pages;

public:
Draw& GetDraw() { return nil; }
operator Draw&() { return GetDraw(); }
const Vector<int>& GetPages() const { return pages; }
int operator[](int i) const { return 0; }
int GetPageCount() const { return 0; }

bool Execute() { return false; }

PrinterJob& Landscape(bool b = true) { return *this; }
PrinterJob& MinMaxPage(int minpage, int maxpage) { return *this; }
PrinterJob& PageCount(int n) { return *this; }
PrinterJob& CurrentPage(int currentpage) { return *this; }
PrinterJob& Name(const char *_name) { return *this; }

PrinterJob(const char *name = NULL) {}
~PrinterJob() {}
};

class TopWindowFrame;
struct InfoPanel;
struct Console;
void GlLog(int line, const char* text, Color ink = White);
void GlLog(const char* text, Color ink = White);
void GlLogF(Color ink, const char* fmt, ...);
void GlLogF(const char* fmt, ...);

#define GUIPLATFORM_CTRL_TOP_DECLS Ctrl *owner_window;
#define GUIPLATFORM_CTRL_DECLS_INCLUDE <WinGl/Ctrl.h>
#define GUIPLATFORM_PASTECLIP_DECLS \
bool dnd; \
friend struct DnDLoop;
#define GUIPLATFORM_TOPWINDOW_DECLS_INCLUDE <WinGl/Top.h>
#define GUIPLATFORM_INCLUDE_AFTER <WinGl/After.h>

END_UPP_NAMESPACE

#endif

Change log

r4853 by unodgs on Apr 24, 2012   Diff
WinGL: Fixed timers, added support for
perspective view
Go to: 
Project members, sign in to write a code review

Older revisions

r4385 by unodgs on Jan 9, 2012   Diff
WinGL: Texture alignment fixes, added
grayscale to blur shader
r4365 by unodgs on Jan 6, 2012   Diff
WinGL: Added painting through fbo,
added blur shader, fixed children
clipping, optimized painting a bit
r4232 by unodgs on Dec 2, 2011   Diff
WinGL: Removed few #ifdef WINGL
All revisions of this file

File info

Size: 9888 bytes, 356 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting