Quellcode durchsuchen

gpu: add support for triangle strips and fans, and change the DrawElement

calls so that they take a number of vertices or indexes, not elements.
legacy
Sam Hocevar sam vor 12 Jahren
Ursprung
Commit
ad00a34984
10 geänderte Dateien mit 65 neuen und 16 gelöschten Zeilen
  1. +1
    -1
      src/easymesh/easymesh.cpp
  2. +46
    -6
      src/gpu/vertexbuffer.cpp
  3. +9
    -0
      src/gpu/vertexbuffer.h
  4. +1
    -1
      src/gradient.cpp
  5. +1
    -1
      src/scene.cpp
  6. +1
    -1
      tutorial/01_triangle.cpp
  7. +1
    -1
      tutorial/02_cube.cpp
  8. +1
    -1
      tutorial/03_noise.cpp
  9. +3
    -3
      tutorial/08_fbo.cpp
  10. +1
    -1
      tutorial/11_fractal.cpp

+ 1
- 1
src/easymesh/easymesh.cpp Datei anzeigen

@@ -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();
}


+ 46
- 6
src/gpu/vertexbuffer.cpp Datei anzeigen

@@ -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! */


+ 9
- 0
src/gpu/vertexbuffer.h Datei anzeigen

@@ -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(),


+ 1
- 1
src/gradient.cpp Datei anzeigen

@@ -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()


+ 1
- 1
src/scene.cpp Datei anzeigen

@@ -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();
}


+ 1
- 1
tutorial/01_triangle.cpp Datei anzeigen

@@ -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();
}



+ 1
- 1
tutorial/02_cube.cpp Datei anzeigen

@@ -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();
}


+ 1
- 1
tutorial/03_noise.cpp Datei anzeigen

@@ -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();
}



+ 3
- 3
tutorial/08_fbo.cpp Datei anzeigen

@@ -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();
}


+ 1
- 1
tutorial/11_fractal.cpp Datei anzeigen

@@ -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();
}



Laden…
Abbrechen
Speichern