https://github.com/ialhashim/topo-blend
Revision 39b13612ebd645a65eda854771b517371f2f858a authored by ennetws on 13 March 2015, 18:17:18 UTC, committed by ennetws on 13 March 2015, 18:17:18 UTC
1 parent c702819
Raw File
Tip revision: 39b13612ebd645a65eda854771b517371f2f858a authored by ennetws on 13 March 2015, 18:17:18 UTC
Create README.md
Tip revision: 39b1361
GlSplatRenderer.cpp
#include "GlSplatRenderer.h"

GlSplatRenderer::GlSplatRenderer(double radius, const Eigen::Vector4d & color)
{
	Q_INIT_RESOURCE(shaders);

    mRadius = qMax(0.02,radius);
    for(int i = 0; i < 4; i++) mColor[i] = color[i];

	VertexVBOID = 0;
	VertexCount = 0;
}

void GlSplatRenderer::draw()
{
	if(!VertexCount) return;

    beginVisibilityPass();
    drawpoints();
    beginAttributePass();
    drawpoints();
    finalize();
}

void GlSplatRenderer::drawpoints()
{
	glColor4dv(mColor);

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);

	glBindBuffer(GL_ARRAY_BUFFER, VertexVBOID);
	glMultiTexCoord1f(GL_TEXTURE2, mRadius);
	glNormalPointer(GL_FLOAT, sizeof(GLVertex), (void*)offsetof(GLVertex, nx));
	glVertexPointer(3, GL_FLOAT, sizeof(GLVertex), (void*)offsetof(GLVertex, x));
	glDrawArrays(GL_POINTS, 0, VertexCount);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);
}

void GlSplatRenderer::update( const std::vector<GLVertex> & splats )
{
	// Clean up previous
	if(VertexCount) glDeleteBuffers(1, &VertexVBOID);

	glGenBuffers(1, &VertexVBOID);
	glBindBuffer(GL_ARRAY_BUFFER, VertexVBOID);
	glBufferData(GL_ARRAY_BUFFER, sizeof(GLVertex) * splats.size(), &splats[0].x, GL_STATIC_DRAW);

	VertexCount = splats.size();
}
back to top