-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
glwidgets.h
349 lines (284 loc) · 10.6 KB
/
glwidgets.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
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
/* OpenBRF -- by marco tarini. Provided under GNU General Public License */
#ifndef GLWIDGETS_H
#define GLWIDGETS_H
#include <QOpenGLWidget>
#include <QOpenGLTexture>
#include <QOpenGLFunctions_2_0>
#include <QOpenGLFunctions_3_0>
#include <QtGui>
#include "brfData.h"
#include "iniData.h"
#include "ddsData.h"
class BrfData;
class QOpenGLShaderProgram;
// for picking
class GlCamera{
public:
static GlCamera currentCamera(int targetIndex);
GlCamera();
double mv[16],pr[16];
int vp[4];
int targetIndex; // index of mesh target
bool isInViewport(int x, int y) const;
bool getCurrent();
vcg::Point3f unproject(int x, int y) const;
};
//typedef std::map< std::string, std::string > MapSS;
struct ViewportData{
std::vector<int> items;
int bestLod = 100;
};
class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions_3_0
{
Q_OBJECT
QSize minimumSizeHint() const;
QSize sizeHint() const;
public:
GLWidget(QWidget *parent, IniData& i);
~GLWidget();
BrfData* data;
BrfData* reference; // for things that needs to be present to see other things...
// e.g. skeletons for animations
BrfData* hitBoxes; // extra data for skeletons
IniData &inidata;
int selected;
int subsel; // subpiece selected
int selRefAnimation; // animation selected to view skinned mesh
int selRefSkin; // skinned mesh
int selRefSkel; // current skeleton
int selFrameN; // current selected frame of vertex ani
int lastSelected;
bool applyExtraMatrixToAll;
float extraMatrix[16]; // matric for temp transforms
void clearExtraMatrix();
void selectNone();
void setEditingRef(bool mode);
TokenEnum displaying;
typedef struct {
int type; // 0 = no err; 1 = cannot find material; 2 = cannot find mesh file; 3 = cannot decrypt mesh file
QString matName;
QString texName;
} MaterialError;
MaterialError lastMatErr;
void setMaterialError(int newErr);
QStringList supportedExtensionsList;
int32_t maxSupportedTexAnisoTaps = 0;
bool frameBuffersAreSupported = false;
void keyPressEvent( QKeyEvent * event );
void keyReleaseEvent( QKeyEvent * event );
private slots:
void onTimer();
public slots:
void setSelection(const QModelIndexList &, int k);
void setFloatingProbePos(float x, float y, float z);
void setSubSelected(int k);
void setRefAnimation(int i);
void setRefSkin(int i);
void setViewmode(int i);
void setViewmodeMult(int i);
int getViewmodeMult()const{return viewmodeMult;}
int getRefSkin() const;
void setRefSkeleton(int i);
int getRefSkeleton() const;
int getRefSkelAni() const;
void setWireframe(bool i);
void setLighting(bool i);
void setTexture(bool i);
void setNormalmap(bool i);
void setTransparency(bool i);
void setSpecularmap(bool i);
void setComparisonMesh(bool i);
void setFloor(bool i);
void setFloorForAni(bool i);
void setRuler(bool i);
void setFloatingProbe(bool i);
void setHitboxes(bool i);
void setRulerLength(int i);
void setPlay();
void setStop();
void setPause(int i=-1);
void setStepon();
void setStepback();
void setColorPerVert();
void setColorPerRig();
void setColorPerWhite();
void setFrameNumber(int);
void setDefaultBgColor(QColor bgColor, bool alsoCurrent);
void renderAoOnMeshes(float brightness, float fromAbove, bool perface, bool inAlpha, bool overwrite);
void renderTextureColorOnMeshes(bool overwrite);
void browseTexture();
int getFrameNumber() const;
void showMaterialDiffuseA();
void showMaterialDiffuseB();
void showMaterialBump();
void showMaterialEnviro();
void showMaterialSpecular();
void showAlphaTransparent();
void showAlphaPurple();
void showAlphaNo();
void setCommonBBoxOn();
void setCommonBBoxOff();
void setInferMaterialOn();
void setInferMaterialOff();
void setUseOpenGL2(bool mode);
public:
/* settings */
bool useWireframe, useLighting, useTexture , useTransparency, useNormalmap, useFloor, useFloorInAni, usePreviewTangents;
bool useRuler, useFloatingProbe, useSpecularmap, useHitboxes, useComparisonMesh;
bool autoComputeTangents;
bool ghostMode;
bool fixTexturesOnSight;
int colorMode, rulerLength;
enum{STOP, PAUSE, PLAY} runningState, defaultRunningState;
enum{DIFFUSEA, DIFFUSEB, BUMP, ENVIRO, SPECULAR } curMaterialTexture;
enum{TRANSALPHA, PURPLEALPHA, NOALPHA} showAlpha;
bool commonBBox;
bool inferMaterial;
bool useOpenGL2;
struct ssfb {
GLuint fbo, rb; GLsizei w, h; GLenum status;
} singleSampleFramebuffer = {};
float runningSpeed;
int relTime; // msec, zeroed at stop.
float floatingProbePulseColor;
signals:
void signalFrameNumber(int);
void notifyCheckboardChanged();
void setTextureData(DdsData d);
void displayInfo(QString st, int howlong);
void notifySelectedPoint(float x, float y, float z);
void signalSelection(std::vector<int> sel);
protected:
//MapSS *mapMT;
void paintGL();
void resizeGL(int width, int height);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *);
void mouseDoubleClickEvent(QMouseEvent *);
void mouseClickEvent(QMouseEvent *);
void wheelEvent(QWheelEvent *event);
// rendering of stuff
template<class BrfType> void renderSelected(const std::vector<BrfType>& p);
// unified rendering of BrfItems...
void renderBrfItem(const BrfMesh& p);
void renderBrfItem(const BrfAnimation& p);
void renderBrfItem(const BrfBody& p);
void renderBrfItem(const BrfSkeleton& p);
void renderBrfItem(const BrfTexture& p);
void renderBrfItem(const BrfMaterial& p);
void enableMaterial(const BrfMaterial& m);
void enableDefMaterial();
bool myBindTexture(const QString &fileName, DdsData &data);
// basic rendering of Brf Items & c:
void renderMesh(const BrfMesh& p, float frame);
void renderMeshSimple(const BrfMesh& p);
void renderSkinnedMesh(const BrfMesh& p, const BrfSkeleton& s, const BrfAnimation& a, float frame);
void renderSkeleton(const BrfSkeleton& p);
void renderAnimation(const BrfAnimation& p, const BrfSkeleton& s, float frame);
void renderBody(const BrfBody& p);
void renderBody(const BrfBody& p, const BrfSkeleton& s, bool ghost); // renders hitboxes p around sketons s
void renderBody(const BrfBody& p, const BrfSkeleton& s, const BrfAnimation& a, float frame, bool ghost);
void renderBone(const BrfAnimation& p, const BrfSkeleton& s, float frame, int i, int lvl); // recursive
void renderBone(const BrfSkeleton& p, int i, int lvl); // recursive
void renderBodyPart(const BrfBodyPart &b);
void renderBodyPart(const BrfBody &b, const BrfSkeleton& s, int i, int lvl); // recursive! (hitboxes)
void renderBodyPart(const BrfBody &b, const BrfSkeleton& s, const BrfAnimation& a, float frame, int i, int lvl); // recursive! (hitboxes)
void renderTexture(const char* name, bool addExtension = true);
void renderSphereWire();
void renderCylWire(float rad, float h);
void renderOcta(int brightness) ;
void renderFloor();
void renderFloorMaybe();
void renderRuler();
void mySetViewport(int viewportIndex);
int getViewportOf( int x, int y ) const;
void mySetViewport(int x,int y,int w,int h);
int nViewportCols, nViewportRows;
bool bboxReady;
//int nViewports;
//int maxSel; // index of the max selected
void distributeSelectedInViewports();
void maybeApplyRenderOrder();
void scaleAsLastBindedTexture();
void renderAoOnMeshesAllInViewportI(float brightness, float fromAbove, bool perface, bool inAlpha, bool overwrite, int I);
void glClearCheckBoard();
// rendering mode (just changes of openGL status):
void setShadowMode(bool on);
void setWireframeLightingMode(bool on, bool light, bool text);
void setTextureName(QString st, int origin, int texUnit);
static bool fixTextureFormat(QString st);
void setMaterialName(QString st);
void setMaterialNameOnlyDiffuse(QString st);
void setCheckboardTexture();
void setDummyRgbTexture();
void setDummySpecTexture();
void setDummyNormTexture();
void initOpenGL2();
bool openGL2ready;
void initDefaultTextures();
void initializeGL();
bool skeletalAnimation();
bool viewIs2D() const;
public:
QString texturePath[3];
QString locateOnDisk(QString nome, const char*ext, BrfMaterial::Location *loc);
void forgetChachedTextures();
QString getCurrentShaderDescriptor() const;
QString getCurrentShaderLog() const;
//enum{MAXSEL=10000};
//bool selGroup[MAXSEL];
//int selViewport[MAXSEL]; // for each selected item, in which viewport it is
std::vector< ViewportData > inViewport;
Box3f globalBox, selectedBox;
int readCustomShaders();
int lastSkelAniFrameUsed;
public:
bool picking;
int selPointIndex, selPointFace, selPointWedge; // selected mesh, face, wedge
private:
vcg::Point3f floatingProbe; // tmp
void renderFloatingProbe();
//int w, h; // screen size
QColor currBgColor, defaultBgColor; // bgcolors
QPoint lastPos; // mouse pos
bool mouseMoved;
float phi, theta, dist;
int tw, th; // texture size, when texture is shown
bool ta; // textures uses alpha, when texture is shown
bool nmgreen; // swy: tangent normalmap seems to be of the green type [RGBA/0X0Y] instead of blue [RGBA/XY__] (after analyzing the bitmap contents)
float cx, cy, zoom; // for texture display
vcg::Point3f avatP, avatV; // pos, vel of avatat
bool keys[5];
QTimer *timer;
bool animating;
bool bumpmapActivated, bumpmapUsingGreen;
bool shadowMode;
int viewmode;
int viewmodeMult;
QOpenGLTexture *dummyRgbTexture = NULL, *dummySpecTexture = NULL, *dummyNormTexture = NULL, *checkboardTexture = NULL;
float currViewmodeHelmet;
float currViewmodeInterior;
vcg::Point3f lastCenter;
float lastScale;
float closingUp;
QString renderedTexture;
// fragment programs
enum { NM_PLAIN = 0, NM_ALPHA, NM_IRON, NM_SHINE, SHADER_IRON, SHADER_MODES, SHADER_FIXEDFUNC , SHADER_CUSTOM };
//unsigned int
QOpenGLShaderProgram* shaderProgram[SHADER_MODES][SHADER_MODES];
bool shaderTried[SHADER_MODES][SHADER_MODES];
QString shaderLog[SHADER_MODES][SHADER_MODES];
int lastUsedShader;
int lastUsedShaderBumpgreen;
std::vector<GlCamera> camera;
//void newShaderProgram(QOpenGLShaderProgram& s, const QStirng prefix, const QStirng vs, const QStirng fs);
QOpenGLShaderProgram* initFramPrograms(int mode, bool green);
QMap<QString, QOpenGLShaderProgram*> customShaders;
QOpenGLShaderProgram* currentCustomShader;
int widthPix() const;
int heightPix() const;
void beginSingleSampledFramebufferUse(void);
void endSingleSampledFramebufferUse(void);
};
#endif // GLWIDGETS_H