drawer.h 4.67 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 29 30 31 32 33
#ifndef _CGOGN_DRAWER_H_
#define _CGOGN_DRAWER_H_

#include <vector>
#include <GL/glew.h>
#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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

	/**
	 * as glBegin, but need a newList call before
	 * @param mode: POINTS, LINES, LINE_LOOP, TRIANGLES, QUADS, POLYGON, etc..
	 */
	void begin(GLenum mode);

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

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

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

134 135 136 137 138 139 140 141 142
	/**
	 * use as glLineWidth
	 */
	void lineWidth(float lw);

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

Sylvain Thery's avatar
Sylvain Thery committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
	/**
	 * 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
160 161 162 163
	/**
	 * rendering in svg struct
	 */
	void toSVG(Utils::SVG::SVGOut& svg);
164 165
};

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
166
} // namespace Utils
167

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
168
} // namespace CGoGN
169

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