drawer.h 5.31 KB
Newer Older
1 2 3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library 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 Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
21 22 23
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
24

25 26 27 28
#ifndef _CGOGN_DRAWER_H_
#define _CGOGN_DRAWER_H_

#include <vector>
Thery Sylvain's avatar
Thery Sylvain committed
29
#include "Utils/gl_def.h"
30
#include "Geometry/vector_gen.h"
31
#include "Utils/Shaders/shaderColorPerVertex.h"
32
#include "Utils/Shaders/shaderBoldColorLines.h"
33 34

namespace CGoGN { namespace Utils { class VBO; } }
Sylvain Thery's avatar
Sylvain Thery committed
35
namespace CGoGN { namespace Utils { namespace SVG { class SVGOut ; } } }
36

Sylvain Thery's avatar
Sylvain Thery committed
37 38
#include "Utils/dll.h"

39 40
namespace CGoGN
{
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
41

42 43
namespace Utils
{
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
44

45 46 47 48 49 50 51
/**
 * A class that allow easy drawing, allmost as easy as
 * display lists in old school OpenGL 1.1
 * Allow only position and color
 * Drawing (callList) efficient after data has been finalized (endList)
 *
 */
Sylvain Thery's avatar
Sylvain Thery committed
52
class CGoGN_UTILS_API Drawer
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
{
	struct PrimParam
	{
		unsigned int begin;
		GLenum mode;
		float width;
		unsigned int nb;
		PrimParam(unsigned int b, GLenum m, float w): begin(b),mode(m),width(w),nb(0) {}
	};

protected:
	Utils::VBO* m_vboPos;
	Utils::VBO* m_vboCol;
	std::vector<Geom::Vec3f> m_dataPos;
	std::vector<Geom::Vec3f> m_dataCol;
	std::vector<PrimParam> m_begins;
69

70
	float m_currentWidth;
71
	float m_currentSize;
72 73
	GLenum m_compile;
	Utils::ShaderColorPerVertex* m_shader;
74
	Utils::ShaderBoldColorLines* m_shader2;
75 76 77 78 79 80 81 82 83 84 85 86 87 88

public:

	/**
	 * constructor, init all buffers (data and OpenGL) and shader
	 * @Warning need OpenGL context
	 */
	Drawer();

	/**
	 * release buffers and shader
	 */
	~Drawer();

89 90 91 92 93
//	Utils::ShaderColorPerVertex* getShader();
	std::vector<Utils::GLSLShader*> getShaders();

	void updateMatrices(const glm::mat4& projection, const glm::mat4& modelview);

94

95 96
	/**
	 * init the data structure
97
	 * @param comp say if compile only, or compile and execute (GL_COMPILE / GL_COMPILE_AND_EXECUTE)
98
	 */
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
99
	void newList(GLenum comp = GL_COMPILE);
100 101 102 103

	/**
	 * as glBegin, but need a newList call before
	 * @param mode: POINTS, LINES, LINE_LOOP, TRIANGLES, QUADS, POLYGON, etc..
104
	 * @return index of subdrawing possible call
105
	 */
106
	int begin(GLenum mode);
107 108 109 110 111 112 113 114 115 116 117 118 119 120

	/**
	 * as glEnd
	 */
	void end();

	/**
	 * finalize the data initialization
	 * drawn is done if newList called with GL_COMPILE_AND_EXECUTE
	 */
	void endList();

	/**
	 * use as glVertex
Sylvain Thery's avatar
Sylvain Thery committed
121
	 * @return index of position for update
122
	 */
Sylvain Thery's avatar
Sylvain Thery committed
123
	unsigned int vertex(const Geom::Vec3f& v);
124 125 126

	/**
	 * use as glVertex
Sylvain Thery's avatar
Sylvain Thery committed
127
	 * @return index of position for update
128
	 */
Sylvain Thery's avatar
Sylvain Thery committed
129
	unsigned int vertex3f(float x, float y, float z);
130 131 132 133 134 135 136 137 138 139 140 141 142 143

	/**
	 * use as glColor
	 */
	void color(const Geom::Vec3f& col);

	/**
	 * use as glColor3f
	 */
	void color3f(float r, float g, float b);

	/**
	 * use as a glCallList
	 */
Sylvain Thery's avatar
Sylvain Thery committed
144
	void callList(float opacity = 1.0f);
145

146 147 148 149 150 151 152 153
	/**
	 * call a sub-list (index return by begin (0,1,...)
	 */
	void callSubList(int index, float opacity = 1.0f);

	/**
	 * call a set of sub-lists
	 */
154
//	void callSubLists(std::vector<int> indices, float opacity);
155

156 157 158
	/**
	 * call a set of sub-lists
	 */
159
//	void callSubLists(int first, int nb, float opacity);
160 161


162 163 164 165 166 167 168 169 170
	/**
	 * use as glLineWidth
	 */
	void lineWidth(float lw);

	/**
	 * usr as glPointSize
	 */
	void pointSize(float ps);
Sylvain Thery's avatar
Sylvain Thery committed
171

Sylvain Thery's avatar
Sylvain Thery committed
172 173 174
	/**
	 * update position of VBO of drawer
	 * @param first index of vertex to update
175
	 * @param nb number of vertices to update
Sylvain Thery's avatar
Sylvain Thery committed
176 177 178 179 180 181 182
	 * @param P ptr to table of vertices
	 */
	void updatePositions(unsigned int first, unsigned int nb, const Geom::Vec3f* P);

	/**
	 * update position of VBO of drawer
	 * @param first index of vertex to update
183
	 * @param nb number of vertices to update
Sylvain Thery's avatar
Sylvain Thery committed
184 185 186 187
	 * @param P ptr to table of vertices
	 */
	void updatePositions(unsigned int first, unsigned int nb, const float* P);

Sylvain Thery's avatar
Sylvain Thery committed
188 189 190 191
	/**
	 * rendering in svg struct
	 */
	void toSVG(Utils::SVG::SVGOut& svg);
192 193
};

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
194
} // namespace Utils
195

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
196
} // namespace CGoGN
197

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
198
#endif