forked from QianMo/GPU-Gems-Book-Source-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pug.h
149 lines (115 loc) · 4.87 KB
/
pug.h
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
/*********************************************************************NVMH3****
Copyright NVIDIA Corporation 2004
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
*AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
NVIDIA OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR
CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR
LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
****************************************************************************/
#ifndef PUG_H
#define PUG_H
#include <windows.h>
#include <GL/gl.h>
#include <GL/wglext.h>
#include <Cg/cg.h>
class PUGProgram;
enum PUGTarget
{
PUG_FRONT,
PUG_BACK,
PUG_NUM_TARGETS
};
struct PUGBuffer
{
PUGBuffer() { }
PUGBuffer(int w, int h, int nc, HDC dc, HPBUFFERARB pbuf, HGLRC rc,
GLuint th, GLuint ib, bool db=false);
GLuint texHandle, imageBuffer;
int width, height, nComponents;
bool bound[2];
// PBUFFER data
HPBUFFERARB hpbuffer; // pbuffer handle
HDC hpbufferDC; // pbuffer device context
HGLRC hpbufferRC; // pbuffer render context
// double-buffered PBUFFER data
bool doublebuffered;
PUGTarget currentDrawBuffer;
};
struct PUGRect {
PUGRect() { }
PUGRect(int xx0, int xx1, int yy0, int yy1) {
x00 = x01 = xx0;
x10 = x11 = xx1;
y00 = y10 = yy0;
y01 = y11 = yy1;
}
PUGRect(int xx00, int xx10, int xx01, int xx11,
int yy00, int yy10, int yy01, int yy11) {
x00 = xx00; x10 = xx10; x01 = xx01; x11 = xx11;
y00 = yy00; y10 = yy10; y01 = yy01; y11 = yy11;
}
int x00, x01, x10, x11;
int y00, y01, y10, y11;
};
extern bool pugInit(const char* includePath = "./", CGcontext cgcontext = 0, bool createOGLContext = true);
extern bool pugCleanup();
extern PUGProgram *pugLoadProgram(const char *filename,
const char *entrypoint,
const char **args = NULL);
extern PUGProgram *pugLoadReductionProgram(const char *filename,
const char *reduceop,
int samples = 2,
int components = 1,
const char **args = NULL);
extern bool pugBindFloat(PUGProgram *prog, const char *param,
float v0, float v1 = 0, float v2 = 0, float v3 = 0);
extern bool pugBindStream(PUGProgram *prog, const char *param,
PUGBuffer *buf, PUGTarget target = PUG_FRONT);
extern bool pugBindDomain(PUGProgram *prog, const char *param,
const PUGRect &domain);
extern bool pugRunProgram(PUGProgram *prog, const PUGRect &writeRect,
const PUGRect &readRect);
extern bool pugReadMemory(float *out, PUGBuffer *buf);
extern bool pugReadMemory(float *out, PUGBuffer *buf, PUGRect rect);
extern PUGRect pugTransposeRect(PUGRect &rect);
// over all of current output buffer
extern bool pugRunProgram(PUGProgram *prog, PUGBuffer *output);
extern bool pugRunProgram(PUGProgram *prog, PUGBuffer *output, const PUGRect domain);
extern bool pugRunProgram(PUGProgram *prog, PUGBuffer *output, const PUGRect domain,
PUGTarget target);
enum PUGBufferMode {
PUG_READ,
PUG_WRITE,
PUG_READWRITE
};
extern PUGBuffer* pugAllocateBuffer(int width, int height, PUGBufferMode mode,
int components = 1,
bool doublebuffer = false);
extern void pugDeleteBuffer(PUGBuffer* buf);
extern bool pugInitBuffer(PUGBuffer *buf, const float *data,
PUGTarget target = PUG_FRONT);
extern bool pugStartReadBack(PUGBuffer *);
extern float* pugGetBufferData(PUGBuffer *);
extern bool pugReleaseBufferData(PUGBuffer *);
extern bool pugReleaseBuffer(PUGBuffer *buf, PUGTarget target = PUG_FRONT);
extern bool pugBindTexture(PUGBuffer *buf, PUGTarget target = PUG_FRONT);
extern bool pugMakeWindowCurrent();
extern void pugWaitForThreads();
// Parallel Reductions
enum PUGDimension
{
PUG_DIMENSION_X,
PUG_DIMENSION_Y,
PUG_DIMENSION_COUNT
};
extern PUGBuffer* pugReduce1D(PUGProgram *prog, PUGBuffer *inbuf,
PUGBuffer *dblbuf, PUGDimension dim,
int nRows, int nCols);
extern PUGBuffer* pugReduce2D(PUGProgram *prog, PUGBuffer *inbuf,
PUGBuffer *dblbuf, int nRows, int nCols);
#endif // PUG_H