summaryrefslogtreecommitdiff
path: root/graphics/asymptote/beziercurve.cc
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-30 03:00:43 +0000
committerNorbert Preining <norbert@preining.info>2019-09-30 03:00:43 +0000
commitbbbe8128e7ae9d816a221377dbf5ff3969bb203b (patch)
tree0283a521760b879b30e61872f14f235645745675 /graphics/asymptote/beziercurve.cc
parent14ce8b68fe7df49e8a8891bb94c63b9a846da232 (diff)
CTAN sync 201909300300
Diffstat (limited to 'graphics/asymptote/beziercurve.cc')
-rw-r--r--graphics/asymptote/beziercurve.cc153
1 files changed, 23 insertions, 130 deletions
diff --git a/graphics/asymptote/beziercurve.cc b/graphics/asymptote/beziercurve.cc
index ccf3267e6e..2b33d552a3 100644
--- a/graphics/asymptote/beziercurve.cc
+++ b/graphics/asymptote/beziercurve.cc
@@ -10,28 +10,30 @@
namespace camp {
-#ifdef HAVE_GL
+#ifdef HAVE_LIBGL
-std::vector<vertexData1> BezierCurve::vertexbuffer;
-std::vector<GLuint> BezierCurve::indices;
-
-std::vector<pixelData> Pixel::vertexbuffer;
-
-GLuint BezierCurve::vertsBufferIndex;
-GLuint BezierCurve::elemBufferIndex;
-
-void BezierCurve::init(double res, const triple& Min, const triple& Max)
+void BezierCurve::init(double res)
{
this->res=res;
res2=res*res;
- this->Min=Min;
- this->Max=Max;
-
- const size_t nbuffer=10000;
- vertexbuffer.reserve(nbuffer);
- indices.reserve(nbuffer);
+
+ MaterialIndex=materialIndex;
}
+void BezierCurve::render(const triple *p, bool straight)
+{
+ GLuint i0=data.vertex1(p[0]);
+ GLuint i3=data.vertex1(p[3]);
+
+ if(straight) {
+ std::vector<GLuint> &q=data.indices;
+ q.push_back(i0);
+ q.push_back(i3);
+ } else
+ render(p,i0,i3);
+ append();
+}
+
// Use a uniform partition to draw a Bezier patch.
// p is an array of 4 triples representing the control points.
// Ii are the vertices indices.
@@ -41,11 +43,12 @@ void BezierCurve::render(const triple *p, GLuint I0, GLuint I1)
triple p1=p[1];
triple p2=p[2];
triple p3=p[3];
- if(Distance1(p0,p1,p2,p3) < res2) { // Segment is flat
+ if(Straightness(p0,p1,p2,p3) < res2) { // Segment is flat
triple P[]={p0,p3};
if(!offscreen(2,P)) {
- indices.push_back(I0);
- indices.push_back(I1);
+ std::vector<GLuint> &q=data.indices;
+ q.push_back(I0);
+ q.push_back(I1);
}
} else { // Segment is not flat
if(offscreen(4,p)) return;
@@ -59,123 +62,13 @@ void BezierCurve::render(const triple *p, GLuint I0, GLuint I1)
triple s0[]={p0,m0,m3,m5};
triple s1[]={m5,m4,m2,p3};
- GLuint i0=vertex(m5);
+ GLuint i0=data.vertex1(m5);
render(s0,I0,i0);
render(s1,i0,I1);
}
}
-void BezierCurve::render(const triple *p, bool straight)
-{
- GLuint i0=vertex(p[0]);
- GLuint i3=vertex(p[3]);
-
- if(straight) {
- indices.push_back(i0);
- indices.push_back(i3);
- } else
- render(p,i0,i3);
-}
-
-void BezierCurve::draw()
-{
- if(indices.size() == 0)
- return;
-
- const size_t size=sizeof(GLfloat);
- static const size_t bytestride=sizeof(vertexData1);
-
- GLuint vao;
- glGenVertexArrays(1,&vao);
- glBindVertexArray(vao);
- createBuffers();
-
- glBindBuffer(GL_ARRAY_BUFFER,vertsBufferIndex);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,elemBufferIndex);
-
- camp::setUniforms(noNormalShader);
-
- const GLint posAttrib=glGetAttribLocation(noNormalShader, "position");
- const GLint materialAttrib=glGetAttribLocation(noNormalShader,"material");
-
- 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);
-
- deleteUniforms();
-
- glBindBuffer(GL_ARRAY_BUFFER,0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
-
- glBindVertexArray(0);
- glDeleteVertexArrays(1,&vao);
-
- glDeleteBuffers(1,&vertsBufferIndex);
- glDeleteBuffers(1,&elemBufferIndex);
-}
-
-void Pixel::queue(const triple& p, double width)
-{
- vertex(p,width);
-}
-
-void Pixel::draw()
-{
- if(vertexbuffer.size() == 0)
- return;
-
- const size_t size=sizeof(GLfloat);
- static const size_t bytestride=sizeof(pixelData);
-
- GLuint vbo;
- glGenBuffers(1,&vbo);
-
- GLuint vao;
- glGenVertexArrays(1,&vao);
- glBindVertexArray(vao);
-
- glBindBuffer(GL_ARRAY_BUFFER,vbo);
- glBufferData(GL_ARRAY_BUFFER,bytestride*vertexbuffer.size(),
- vertexbuffer.data(),GL_STATIC_DRAW);
-
- camp::setUniforms(pixelShader);
-
- const GLint posAttrib=glGetAttribLocation(pixelShader, "position");
- const GLint materialAttrib=glGetAttribLocation(pixelShader,"material");
- const GLint widthAttrib=glGetAttribLocation(pixelShader,"width");
-
- glVertexAttribPointer(posAttrib,3,GL_FLOAT,GL_FALSE,bytestride,(void*)(0));
- glEnableVertexAttribArray(posAttrib);
-
- glVertexAttribIPointer(materialAttrib,1,GL_INT,bytestride,(void *) (3*size));
- glEnableVertexAttribArray(materialAttrib);
-
- glVertexAttribPointer(widthAttrib,1,GL_FLOAT,GL_FALSE,bytestride,(void *) (4*size));
- glEnableVertexAttribArray(widthAttrib);
-
- glDrawArrays(GL_POINTS,0,vertexbuffer.size());
-
- glDisableVertexAttribArray(posAttrib);
- glDisableVertexAttribArray(materialAttrib);
- glDisableVertexAttribArray(widthAttrib);
-
- deleteUniforms();
-
- glBindBuffer(GL_ARRAY_BUFFER,0);
-
- glBindVertexArray(0);
- glDeleteVertexArrays(1,&vao);
-}
-
#endif
} //namespace camp