File: rfx_glpass.h

package info (click to toggle)
meshlab 1.3.2+dfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 21,096 kB
  • ctags: 33,630
  • sloc: cpp: 224,813; ansic: 8,170; xml: 119; makefile: 80
file content (130 lines) | stat: -rw-r--r-- 4,591 bytes parent folder | download | duplicates (5)
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
/****************************************************************************
* MeshLab                                                           o o     *
* A versatile mesh processing toolbox                             o     o   *
*                                                                _   O  _   *
* Copyright(C) 2005-2008                                           \/)\/    *
* Visual Computing Lab                                            /\/|      *
* ISTI - Italian National Research Council                           |      *
*                                                                    \      *
* All rights reserved.                                                      *
*                                                                           *
* This program is free software; you can redistribute it and/or modify      *
* it under the terms of the GNU General Public License as published by      *
* the Free Software Foundation; either version 2 of the License, or         *
* (at your option) any later version.                                       *
*                                                                           *
* This program is distributed in the hope that it will be useful,           *
* but WITHOUT ANY WARRANTY; without even the implied warranty of            *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
* for more details.                                                         *
*                                                                           *
****************************************************************************/

#ifndef RFX_GLPASS_H_
#define RFX_GLPASS_H_

#include <cassert>
#include <QString>
#include <QList>
#include <GL/glew.h>
#include <QGLWidget>
#include <QMessageBox>
#include "rfx_uniform.h"

#include "rfx_specialattribute.h"

#include "rfx_state.h"

class RfxGLPass
{
public:
	RfxGLPass() : passIndex(-1) { useRenderTarget = false; shaderLinked = false; }
	RfxGLPass(int passidx) : passIndex(passidx) { useRenderTarget = false; shaderLinked = false; }
	virtual ~RfxGLPass();
	bool checkSpecialAttributeDataMask(MeshDocument*);
	void SetShaderSource(const QString &source, bool isFragment);
	const QString& GetVertexSource() { return vert; }
	const QString& GetFragmentSource() { return frag; }
	int GetPassIndex() { return passIndex; }
	void SetPassIndex(int passidx) { passIndex = passidx; }
	const QString& GetPassName() { return passName; }
	void SetPassName(const QString &n) { passName = n; }
	void AddGLState(RfxState *s) { rfxStates.append(s); }
	void AddUniform(RfxUniform *u) { shaderUniforms.append(u); }

	/*
		Appends a new Special Attribute to the pass.
		@param s the attribute to be appended.
	*/
	void AddSpecialAttribute(RfxSpecialAttribute *s){ shaderSpecialAttributes.append(s); }

	void SetRenderToTexture(bool t) { useRenderTarget = t; }
	bool wantsRenderTarget() { return useRenderTarget; }
	void LinkRenderTarget(RfxRenderTarget *_rt) { rt = _rt; }
	RfxRenderTarget* GetRenderTarget() { assert(useRenderTarget); return rt; }

	QListIterator<RfxUniform*> UniformsIterator()
	{
		return QListIterator<RfxUniform*>(shaderUniforms);
	}
	QListIterator<RfxState*> StatesIterator()
	{
		return QListIterator<RfxState*>(rfxStates);
	}
	
	/*
		Returns the list of special attribute contained in the pass.
		@return the list of special attribute
	*/
	QList<RfxSpecialAttribute*>* AttributesList()
	{
		return &shaderSpecialAttributes;
	}

	/*
		Returns true if the pass has at least a specialAttribute, false otherwise.
		@return true if the pass contains at least a special attribute, false otherwise.
	*/
	bool hasSpecialAttribute(){
		return !this->shaderSpecialAttributes.isEmpty();
	}

	RfxUniform* getUniform(int uniIdx) { return shaderUniforms.at(uniIdx); }
	RfxUniform* getUniform(const QString& uniIdx);
	
	/*
		Returns the shader program.
		@return the shader program.
	*/
	GLuint* getProgram() { 
		return &shaderProgram; 
	}

	void CompileAndLink();
	void Start();
	const QString GetCompilationLog() { return compileLog; }

private:
	QString vert;
	QString frag;
	QString compileLog;

	QString passName;
	int passIndex;
	bool useRenderTarget;
	RfxRenderTarget *rt;

	GLuint shaderProgram;
	bool shaderLinked;

	QList<RfxState*> rfxStates;
	QList<RfxUniform*> shaderUniforms;

	/* The list of special attribute the pass contains */
	QList<RfxSpecialAttribute*> shaderSpecialAttributes;

	void FillInfoLog(GLhandleARB);
};

#endif /* RFX_GLPASS_H_ */