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
|
#include <CGAL/Three/Point_container.h>
#include <CGAL/Three/Three.h>
typedef Viewer_interface VI;
using namespace CGAL::Three;
struct Point_d{
Point_d()
:
plane(QVector4D())
{
f_matrix=QMatrix4x4();
}
QVector4D plane;
QMatrix4x4 f_matrix;
bool is_surface;
};
Point_container::Point_container(int program, bool indexed)
:Primitive_container(program, indexed),
d(new Point_d())
{
std::vector<Vbo*> vbos(NbOfVbos, nullptr);
setVbos(vbos);
}
Point_container::~Point_container()
{
delete d;
}
void Point_container::initGL(Viewer_interface *viewer)
{
viewer->makeCurrent();
if(viewer->isSharing())
{
if(!getVao(viewer))
setVao(viewer, new Vao(getVao(Three::mainViewer()),
viewer->getShaderProgram(getProgram())));
}
else
{
if(!getVao(viewer))
setVao(viewer, new Vao(viewer->getShaderProgram(getProgram())));
if(isDataIndexed())
{
if(!getVbo(Vertices))
setVbo(Vertices,
new Vbo("vertex",
Vbo::GEOMETRY));
if(!getVbo(Indices))
setVbo(Indices,
new Vbo("indices",
Vbo::GEOMETRY,
QOpenGLBuffer::IndexBuffer));
getVao(viewer)->addVbo(getVbo(Vertices));
getVao(viewer)->addVbo(getVbo(Indices));
}
else
{
if(!getVbo(Vertices))
setVbo(Vertices,
new Vbo("vertex",
Vbo::GEOMETRY));
if(!getVbo(Colors))
setVbo(Colors,
new Vbo("colors",
Vbo::COLORS));
if(viewer->getShaderProgram(getProgram())->property("hasNormals").toBool())
{
if(!getVbo(Normals))
setVbo(Normals,
new Vbo("normals",
Vbo::NORMALS));
getVao(viewer)->addVbo(getVbo(Normals));
}
getVao(viewer)->addVbo(getVbo(Vertices));
getVao(viewer)->addVbo(getVbo(Colors));
}
}
setGLInit(viewer, true);
}
void Point_container::draw(Viewer_interface *viewer,
bool is_color_uniform)
{
bindUniformValues(viewer);
if(isDataIndexed())
{
getVao(viewer)->bind();
if(is_color_uniform)
getVao(viewer)->program->setAttributeValue("colors", getColor());
if(getVao(viewer)->program->property("hasFMatrix").toBool())
getVao(viewer)->program->setUniformValue("f_matrix", getFrameMatrix());
getVbo(Indices)->bind();
viewer->glDrawElements(GL_POINTS, static_cast<GLuint>(getIdxSize()),
GL_UNSIGNED_INT, nullptr);
getVbo(Indices)->release();
getVao(viewer)->release();
}
else
{
getVao(viewer)->bind();
if(is_color_uniform)
getVao(viewer)->program->setAttributeValue("colors", getColor());
if(getVao(viewer)->program->property("hasFMatrix").toBool())
getVao(viewer)->program->setUniformValue("f_matrix", getFrameMatrix());
viewer->glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(getFlatDataSize()/getTupleSize()));
getVao(viewer)->release();
}
}
QVector4D Point_container::getPlane() const { return d->plane; }
QMatrix4x4 Point_container::getFrameMatrix() const { return d->f_matrix; }
void Point_container::setFrameMatrix(const QMatrix4x4& m) { d->f_matrix = m; }
void Point_container::setPlane(const QVector4D& p) { d->plane = p; }
void Point_container::setIsSurface (const bool b) { d->is_surface = b; }
|