summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/beziercurve.cc
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/utils/asymptote/beziercurve.cc')
-rw-r--r--Build/source/utils/asymptote/beziercurve.cc91
1 files changed, 84 insertions, 7 deletions
diff --git a/Build/source/utils/asymptote/beziercurve.cc b/Build/source/utils/asymptote/beziercurve.cc
index 3861bae48b5..cf9f00acfce 100644
--- a/Build/source/utils/asymptote/beziercurve.cc
+++ b/Build/source/utils/asymptote/beziercurve.cc
@@ -5,15 +5,22 @@
* Render a Bezier curve.
*****/
+#include "bezierpatch.h"
#include "beziercurve.h"
namespace camp {
#ifdef HAVE_GL
-std::vector<GLfloat> BezierCurve::buffer;
+extern GLint noColorShader;
+extern void setUniforms(GLint shader);
+
+std::vector<vertexData1> BezierCurve::vertexbuffer;
std::vector<GLuint> BezierCurve::indices;
+GLuint BezierCurve::vertsBufferIndex;
+GLuint BezierCurve::elemBufferIndex;
+
void BezierCurve::init(double res, const triple& Min, const triple& Max)
{
this->res=res;
@@ -22,7 +29,7 @@ void BezierCurve::init(double res, const triple& Min, const triple& Max)
this->Max=Max;
const size_t nbuffer=10000;
- buffer.reserve(nbuffer);
+ vertexbuffer.reserve(nbuffer);
indices.reserve(nbuffer);
}
@@ -74,15 +81,85 @@ void BezierCurve::render(const triple *p, bool straight)
void BezierCurve::draw()
{
- size_t stride=3*sizeof(GLfloat);
+ const size_t size=sizeof(GLfloat);
+ static const size_t bytestride=sizeof(vertexData1);
+
+ GLuint vao;
+ glGenVertexArrays(1,&vao);
+ glBindVertexArray(vao);
+
+ createBuffers();
+
+ camp::setUniforms(noColorShader);
+
+ const GLint posAttrib=glGetAttribLocation(noColorShader, "position");
+ const GLint materialAttrib=glGetAttribLocation(noColorShader,"material");
+
+ glBindBuffer(GL_ARRAY_BUFFER,vertsBufferIndex);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,elemBufferIndex);
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3,GL_FLOAT,stride,&buffer[0]);
- glDrawElements(GL_LINES,indices.size(),GL_UNSIGNED_INT,&indices[0]);
- glDisableClientState(GL_VERTEX_ARRAY);
+ glVertexAttribPointer(posAttrib,3,GL_FLOAT,GL_FALSE,bytestride,(void *) 0);
+ glEnableVertexAttribArray(posAttrib);
+
+ glVertexAttribIPointer(materialAttrib,1,GL_INT,bytestride,(void *) (3*size));
+ glEnableVertexAttribArray(materialAttrib);
+
+ glFlush(); // Workaround broken MSWindows drivers for Intel GPU
+ glDrawElements(GL_LINES,indices.size(),GL_UNSIGNED_INT,(void*)(0));
+
+ glDisableVertexAttribArray(posAttrib);
+ glDisableVertexAttribArray(materialAttrib);
+
+ glBindBuffer(GL_ARRAY_BUFFER,0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
+ glUseProgram(0);
+
+ glBindVertexArray(0);
+ glDeleteVertexArrays(1,&vao);
+
clear();
}
+void Pixel::draw(const triple& p)
+{
+ vertexData1 point(p);
+
+ const size_t size=sizeof(GLfloat);
+ static const size_t bytestride=sizeof(vertexData1);
+
+ GLuint vbo;
+ glGenBuffers(1,&vbo);
+
+ GLuint vao;
+ glGenVertexArrays(1,&vao);
+ glBindVertexArray(vao);
+
+ camp::setUniforms(noColorShader);
+
+ const GLint posAttrib=glGetAttribLocation(noColorShader, "position");
+ const GLint materialAttrib=glGetAttribLocation(noColorShader,"material");
+
+ glBindBuffer(GL_ARRAY_BUFFER,vbo);
+ glBufferData(GL_ARRAY_BUFFER,bytestride,&point,GL_STATIC_DRAW);
+
+ glVertexAttribPointer(posAttrib,3,GL_FLOAT,GL_FALSE,0,(void*)(0));
+ glEnableVertexAttribArray(posAttrib);
+
+ glVertexAttribIPointer(materialAttrib,1,GL_INT,bytestride,(void *) (3*size));
+ glEnableVertexAttribArray(materialAttrib);
+
+ glDrawArrays(GL_POINTS,0,1);
+
+ glDisableVertexAttribArray(posAttrib);
+ glDisableVertexAttribArray(materialAttrib);
+
+ glBindBuffer(GL_ARRAY_BUFFER,0);
+ glUseProgram(0);
+
+ glBindVertexArray(0);
+ glDeleteVertexArrays(1,&vao);
+}
+
#endif
} //namespace camp