drawer.h 5.02 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 31 32 33
#include "Geometry/vector_gen.h"

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

namespace CGoGN
{
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
38

39 40
namespace Utils
{
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
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
/**
 * 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)
 *
 */
class Drawer
{
	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;
	float m_currentWidth;
67
	float m_currentSize;
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
	GLenum m_compile;
	Utils::ShaderColorPerVertex* m_shader;

public:

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

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

	/**
	 * init the data structure
	 * @param com say if compile only, or compile and execute (GL_COMPILE/ GL_COMPILE_AND_EXECUTE)
	 */
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
88
	void newList(GLenum comp = GL_COMPILE);
89 90 91 92

	/**
	 * as glBegin, but need a newList call before
	 * @param mode: POINTS, LINES, LINE_LOOP, TRIANGLES, QUADS, POLYGON, etc..
93
	 * @return index of subdrawing possible call
94
	 */
95
	int begin(GLenum mode);
96 97 98 99 100 101 102 103 104 105 106 107 108 109

	/**
	 * 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
110
	 * @return index of position for update
111
	 */
Sylvain Thery's avatar
Sylvain Thery committed
112
	unsigned int vertex(const Geom::Vec3f& v);
113 114 115

	/**
	 * use as glVertex
Sylvain Thery's avatar
Sylvain Thery committed
116
	 * @return index of position for update
117
	 */
Sylvain Thery's avatar
Sylvain Thery committed
118
	unsigned int vertex3f(float x, float y, float z);
119 120 121 122 123 124 125 126 127 128 129 130 131 132

	/**
	 * 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
133
	void callList(float opacity = 1.0f);
134

135 136 137 138 139 140 141 142 143 144
	/**
	 * call a sub-list (index return by begin (0,1,...)
	 */
	void callSubList(int index, float opacity = 1.0f);

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

145 146 147 148 149 150
	/**
	 * call a set of sub-lists
	 */
	void callSubLists(int first, int nb, float opacity);


151 152 153 154 155 156 157 158 159
	/**
	 * use as glLineWidth
	 */
	void lineWidth(float lw);

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

Sylvain Thery's avatar
Sylvain Thery committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
	/**
	 * update position of VBO of drawer
	 * @param first index of vertex to update
	 * @param nb number of vertex tp update
	 * @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
	 * @param nb number of vertex tp update
	 * @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
177 178 179 180
	/**
	 * rendering in svg struct
	 */
	void toSVG(Utils::SVG::SVGOut& svg);
181 182
};

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
183
} // namespace Utils
184

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
185
} // namespace CGoGN
186

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