diff --git a/src/easymesh/easymesh.cpp b/src/easymesh/easymesh.cpp index 7583dd4d..ac0ee4d0 100644 --- a/src/easymesh/easymesh.cpp +++ b/src/easymesh/easymesh.cpp @@ -125,7 +125,7 @@ void EasyMesh::Render(mat4 const &model, float damage) m_gpu.ibo->Bind(); m_gpu.vdecl->DrawIndexedElements(MeshPrimitive::Triangles, 0, 0, m_gpu.vertexcount, - 0, m_gpu.indexcount / 3); + 0, m_gpu.indexcount); m_gpu.ibo->Unbind(); m_gpu.vdecl->Unbind(); } diff --git a/src/gpu/vertexbuffer.cpp b/src/gpu/vertexbuffer.cpp index d27d7426..0a629dc3 100644 --- a/src/gpu/vertexbuffer.cpp +++ b/src/gpu/vertexbuffer.cpp @@ -135,11 +135,23 @@ void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count) switch (type) { case MeshPrimitive::Triangles: - if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, skip, count))) + if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, + skip, count))) + Abort(); + break; + case MeshPrimitive::TriangleStrips: + if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, + skip, count))) + Abort(); + break; + case MeshPrimitive::TriangleFans: + if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLEFAN, + skip, count))) Abort(); break; case MeshPrimitive::Points: - if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_POINTLIST, skip, count))) + if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_POINTLIST, + skip, count))) Abort(); break; } @@ -157,7 +169,13 @@ void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count) switch (type) { case MeshPrimitive::Triangles: - glDrawArrays(GL_TRIANGLES, skip * 3, count * 3); + glDrawArrays(GL_TRIANGLES, skip, count); + break; + case MeshPrimitive::TriangleStrips: + glDrawArrays(GL_TRIANGLE_STRIP, skip, count); + break; + case MeshPrimitive::TriangleFans: + glDrawArrays(GL_TRIANGLE_FAN, skip, count); break; case MeshPrimitive::Points: glDrawArrays(GL_POINTS, skip, count); @@ -185,11 +203,23 @@ void VertexDeclaration::DrawIndexedElements(MeshPrimitive type, int vbase, switch (type) { case MeshPrimitive::Triangles: - if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, vbase, vskip, vcount, skip, count))) + if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, + vbase, vskip, vcount, skip, count))) + Abort(); + break; + case MeshPrimitive::TriangleStrips: + if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, + vbase, vskip, vcount, skip, count))) + Abort(); + break; + case MeshPrimitive::TriangleFans: + if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLEFAN, + vbase, vskip, vcount, skip, count))) Abort(); break; case MeshPrimitive::Points: - if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_POINTLIST, vbase, vskip, vcount, skip, count))) + if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_POINTLIST, + vbase, vskip, vcount, skip, count))) Abort(); break; } @@ -209,7 +239,17 @@ void VertexDeclaration::DrawIndexedElements(MeshPrimitive type, int vbase, case MeshPrimitive::Triangles: /* FIXME: ignores most of the arguments! */ (void)vbase; (void)vskip; (void)vcount; (void)skip; - glDrawElements(GL_TRIANGLES, count * 3, GL_UNSIGNED_SHORT, 0); + glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, 0); + break; + case MeshPrimitive::TriangleStrips: + /* FIXME: ignores most of the arguments! */ + (void)vbase; (void)vskip; (void)vcount; (void)skip; + glDrawElements(GL_TRIANGLE_STRIP, count, GL_UNSIGNED_SHORT, 0); + break; + case MeshPrimitive::TriangleFans: + /* FIXME: ignores most of the arguments! */ + (void)vbase; (void)vskip; (void)vcount; (void)skip; + glDrawElements(GL_TRIANGLE_FAN, count, GL_UNSIGNED_SHORT, 0); break; case MeshPrimitive::Points: /* FIXME: ignores most of the arguments! */ diff --git a/src/gpu/vertexbuffer.h b/src/gpu/vertexbuffer.h index c6376fad..dfe01266 100644 --- a/src/gpu/vertexbuffer.h +++ b/src/gpu/vertexbuffer.h @@ -72,6 +72,8 @@ struct MeshPrimitive enum Value { Triangles, + TriangleStrips, + TriangleFans, Points, } m_value; @@ -184,9 +186,16 @@ public: ~VertexDeclaration(); void Bind(); + + /* Draw elements. See MeshPrimitive for a list of all available + * types. Both skip and count are numbers of vertices, not primitives. */ void DrawElements(MeshPrimitive type, int skip, int count); + + /* Draw elements. See MeshPrimitive for a list of all available + * types. Both skip and count are numbers of indices, not primitives. */ void DrawIndexedElements(MeshPrimitive type, int vbase, int vskip, int vcount, int skip, int count); + void Unbind(); void SetStream(VertexBuffer *vb, ShaderAttrib attr1, ShaderAttrib attr2 = ShaderAttrib(), diff --git a/src/gradient.cpp b/src/gradient.cpp index d077bc0c..02e77ae2 100644 --- a/src/gradient.cpp +++ b/src/gradient.cpp @@ -117,7 +117,7 @@ void Gradient::TickDraw(float seconds) data->m_vdecl->SetStream(data->m_cbo, attr_col); /* Draw arrays */ - data->m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2); + data->m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); } Gradient::~Gradient() diff --git a/src/scene.cpp b/src/scene.cpp index 1d588389..636ef285 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -255,7 +255,7 @@ void Scene::Render() // XXX: rename to Blit() data->m_vdecl->SetStream(vb2, attr_tex); /* Draw arrays */ - data->m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, (n - i) * 2); + data->m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, (n - i) * 6); data->m_vdecl->Unbind(); data->tiles[i].tileset->Unbind(); } diff --git a/tutorial/01_triangle.cpp b/tutorial/01_triangle.cpp index 056a7a8e..8b430ccc 100644 --- a/tutorial/01_triangle.cpp +++ b/tutorial/01_triangle.cpp @@ -59,7 +59,7 @@ public: m_shader->Bind(); m_vdecl->SetStream(m_vbo, m_coord); m_vdecl->Bind(); - m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 1); + m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 3); m_vdecl->Unbind(); } diff --git a/tutorial/02_cube.cpp b/tutorial/02_cube.cpp index c1ec8cd0..59a57db8 100644 --- a/tutorial/02_cube.cpp +++ b/tutorial/02_cube.cpp @@ -112,7 +112,7 @@ public: m_vdecl->Bind(); m_ibo->Bind(); m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, 0, 0, - m_mesh.Count(), 0, m_indices.Count()); + m_mesh.Count(), 0, m_indices.Count() * 3); m_ibo->Unbind(); m_vdecl->Unbind(); } diff --git a/tutorial/03_noise.cpp b/tutorial/03_noise.cpp index 2117fa9f..149f5af2 100644 --- a/tutorial/03_noise.cpp +++ b/tutorial/03_noise.cpp @@ -68,7 +68,7 @@ public: m_shader->SetUniform(m_time_uni, m_time); m_vdecl->SetStream(m_vbo, m_coord); m_vdecl->Bind(); - m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2); + m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); m_vdecl->Unbind(); } diff --git a/tutorial/08_fbo.cpp b/tutorial/08_fbo.cpp index f8a2f819..32fca04b 100644 --- a/tutorial/08_fbo.cpp +++ b/tutorial/08_fbo.cpp @@ -99,7 +99,7 @@ public: m_shader->SetUniform(m_uni_texture, m_fbo->GetTexture(), 0); m_vdecl->SetStream(m_vbo, m_coord); m_vdecl->Bind(); - m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2); + m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); m_vdecl->Unbind(); #endif @@ -108,7 +108,7 @@ public: m_shader->SetUniform(m_uni_color, m_color); m_vdecl->SetStream(m_vbo, m_coord); m_vdecl->Bind(); - m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2); + m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); m_vdecl->Unbind(); m_shader->Unbind(); m_fbo->Unbind(); @@ -118,7 +118,7 @@ public: m_shader->SetUniform(m_uni_texture, m_fbo->GetTexture(), 0); m_vdecl->SetStream(m_vbo, m_coord); m_vdecl->Bind(); - m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2); + m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); m_vdecl->Unbind(); m_shader->Unbind(); } diff --git a/tutorial/11_fractal.cpp b/tutorial/11_fractal.cpp index 35a7d897..b9afa71c 100644 --- a/tutorial/11_fractal.cpp +++ b/tutorial/11_fractal.cpp @@ -578,7 +578,7 @@ public: #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ #else #endif - m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2); + m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); m_vdecl->Unbind(); }