Browse Source

Removing IndexedMesh, part 4: merged draw algorithm.

Still source-compatible, next step is to merge the documentation and
remove IndexedMesh stub altogether.
pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
a8abbdb7d3
  1. 1
      src/CMakeLists.txt
  2. 2
      src/Context.cpp
  3. 61
      src/IndexedMesh.cpp
  4. 23
      src/IndexedMesh.h
  5. 24
      src/Mesh.cpp
  6. 13
      src/Mesh.h

1
src/CMakeLists.txt

@ -21,7 +21,6 @@ set(Magnum_SRCS
DefaultFramebuffer.cpp
Framebuffer.cpp
Image.cpp
IndexedMesh.cpp
Mesh.cpp
Query.cpp
Renderbuffer.cpp

2
src/Context.cpp

@ -29,7 +29,6 @@
#include "DefaultFramebuffer.h"
#include "Extensions.h"
#include "Framebuffer.h"
#include "IndexedMesh.h"
#include "Mesh.h"
#include "Renderbuffer.h"
@ -355,7 +354,6 @@ Context::Context() {
DebugMarker::initializeContextBasedFunctionality(this);
DefaultFramebuffer::initializeContextBasedFunctionality(this);
Framebuffer::initializeContextBasedFunctionality(this);
IndexedMesh::initializeContextBasedFunctionality(this);
Mesh::initializeContextBasedFunctionality(this);
Renderbuffer::initializeContextBasedFunctionality(this);
}

61
src/IndexedMesh.cpp

@ -1,61 +0,0 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
#include "IndexedMesh.h"
#include "Buffer.h"
#include "Context.h"
#include "Extensions.h"
namespace Magnum {
IndexedMesh::BindIndexedImplementation IndexedMesh::bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationDefault;
void IndexedMesh::draw() {
if(!_indexCount) return;
bind();
glDrawElements(static_cast<GLenum>(primitive()), _indexCount, static_cast<GLenum>(_indexType), nullptr);
unbind();
}
void IndexedMesh::bind() {
Mesh::bind();
(this->*bindIndexedImplementation)();
}
void IndexedMesh::initializeContextBasedFunctionality(Context* context) {
/** @todo VAOs are in ES 3.0 and as extension in ES 2.0, enable them when some extension wrangler is available */
#ifndef MAGNUM_TARGET_GLES
if(context->isExtensionSupported<Extensions::GL::APPLE::vertex_array_object>()) {
Debug() << "IndexedMesh: using" << Extensions::GL::APPLE::vertex_array_object::string() << "features";
bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationVAO;
}
#else
static_cast<void>(context);
#endif
}
void IndexedMesh::bindIndexedImplementationDefault() {
if(_indexBuffer) _indexBuffer->bind(Buffer::Target::ElementArray);
else Buffer::unbind(Buffer::Target::ElementArray);
}
void IndexedMesh::bindIndexedImplementationVAO() {}
}

23
src/IndexedMesh.h

@ -80,29 +80,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh {
* no vertex or index buffers.
*/
inline explicit IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive) {}
/**
* @brief Draw the mesh
*
* Expects an active shader with all uniforms set. See
* @ref AbstractShaderProgram-rendering-workflow "AbstractShaderProgram documentation"
* for more information.
* @see @fn_gl{EnableVertexAttribArray}, @fn_gl{BindBuffer},
* @fn_gl{VertexAttribPointer}, @fn_gl{DisableVertexAttribArray}
* or @fn_gl{BindVertexArray} (if @extension{APPLE,vertex_array_object}
* is available), @fn_gl{DrawElements}
*/
void draw() override;
private:
static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context);
void MAGNUM_LOCAL bind();
typedef void(IndexedMesh::*BindIndexedImplementation)();
void MAGNUM_LOCAL bindIndexedImplementationDefault();
void MAGNUM_LOCAL bindIndexedImplementationVAO();
static MAGNUM_LOCAL BindIndexedImplementation bindIndexedImplementation;
};
}

24
src/Mesh.cpp

@ -94,13 +94,18 @@ Mesh& Mesh::operator=(Mesh&& other) {
}
void Mesh::draw() {
if(!_vertexCount) return;
/* Nothing to draw */
if(!_vertexCount && !_indexCount) return;
bind();
(this->*bindImplementation)();
/* Non-indexed mesh */
if(!_indexCount) glDrawArrays(static_cast<GLenum>(_primitive), 0, _vertexCount);
glDrawArrays(static_cast<GLenum>(_primitive), 0, _vertexCount);
/* Indexed mesh */
else glDrawElements(static_cast<GLenum>(_primitive), _indexCount, static_cast<GLenum>(_indexType), nullptr);
unbind();
(this->*unbindImplementation)();
}
void Mesh::bindVAO(GLuint vao) {
@ -113,10 +118,6 @@ void Mesh::bindVAO(GLuint vao) {
#endif
}
void Mesh::bind() {
(this->*bindImplementation)();
}
void Mesh::vertexAttribPointer(const Attribute& attribute) {
glEnableVertexAttribArray(attribute.location);
attribute.buffer->bind(Buffer::Target::Array);
@ -247,6 +248,7 @@ void Mesh::bindIndexBufferImplementationVAO(Buffer* buffer) {
}
void Mesh::bindImplementationDefault() {
/* Specify vertex attributes */
for(const Attribute& attribute: attributes)
vertexAttribPointer(attribute);
@ -259,6 +261,12 @@ void Mesh::bindImplementationDefault() {
vertexAttribPointer(attribute);
#endif
#endif
/* Bind index buffer, if the mesh is indexed */
if(_indexCount) {
if(_indexBuffer) _indexBuffer->bind(Buffer::Target::ElementArray);
else Buffer::unbind(Buffer::Target::ElementArray);
}
}
void Mesh::bindImplementationVAO() {

13
src/Mesh.h

@ -119,7 +119,6 @@ more information.
@todo Redo in a way that allows glMultiDrawArrays, glDrawArraysInstanced etc.
*/
class MAGNUM_EXPORT Mesh {
friend class IndexedMesh;
friend class Context;
Mesh(const Mesh& other) = delete;
@ -396,7 +395,7 @@ class MAGNUM_EXPORT Mesh {
* @see @fn_gl{DeleteVertexArrays} (if
* @extension{APPLE,vertex_array_object} is available)
*/
virtual ~Mesh();
~Mesh();
/** @brief Move assignment */
Mesh& operator=(Mesh&& other);
@ -614,9 +613,9 @@ class MAGNUM_EXPORT Mesh {
* @see @fn_gl{EnableVertexAttribArray}, @fn_gl{BindBuffer},
* @fn_gl{VertexAttribPointer}, @fn_gl{DisableVertexAttribArray}
* or @fn_gl{BindVertexArray} (if @extension{APPLE,vertex_array_object}
* is available), @fn_gl{DrawArrays}
* is available), @fn_gl{DrawArrays} or @fn_gl{DrawElements}
*/
virtual void draw();
void draw();
private:
#ifndef DOXYGEN_GENERATING_OUTPUT
@ -732,12 +731,6 @@ class MAGNUM_EXPORT Mesh {
static void MAGNUM_LOCAL bindVAO(GLuint vao);
void MAGNUM_LOCAL bind();
inline void unbind() {
(this->*unbindImplementation)();
}
void MAGNUM_LOCAL vertexAttribPointer(const Attribute& attribute);
#ifndef MAGNUM_TARGET_GLES2
void MAGNUM_LOCAL vertexAttribPointer(const IntegerAttribute& attribute);

Loading…
Cancel
Save