mirror of https://github.com/mosra/magnum.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
532 lines
18 KiB
532 lines
18 KiB
|
16 years ago
|
/*
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
13 years ago
|
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
|
||
|
|
|
||
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
|
copy of this software and associated documentation files (the "Software"),
|
||
|
|
to deal in the Software without restriction, including without limitation
|
||
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
||
|
|
Software is furnished to do so, subject to the following conditions:
|
||
|
|
|
||
|
|
The above copyright notice and this permission notice shall be included
|
||
|
|
in all copies or substantial portions of the Software.
|
||
|
|
|
||
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||
|
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||
|
|
DEALINGS IN THE SOFTWARE.
|
||
|
16 years ago
|
*/
|
||
|
|
|
||
|
|
#include "Mesh.h"
|
||
|
14 years ago
|
|
||
|
|
#include <Utility/Debug.h>
|
||
|
|
|
||
|
16 years ago
|
#include "Buffer.h"
|
||
|
14 years ago
|
#include "Context.h"
|
||
|
|
#include "Extensions.h"
|
||
|
13 years ago
|
#include "Implementation/DebugState.h"
|
||
|
13 years ago
|
#include "Implementation/BufferState.h"
|
||
|
14 years ago
|
#include "Implementation/MeshState.h"
|
||
|
|
#include "Implementation/State.h"
|
||
|
16 years ago
|
|
||
|
|
namespace Magnum {
|
||
|
|
|
||
|
14 years ago
|
Mesh::CreateImplementation Mesh::createImplementation = &Mesh::createImplementationDefault;
|
||
|
|
Mesh::DestroyImplementation Mesh::destroyImplementation = &Mesh::destroyImplementationDefault;
|
||
|
14 years ago
|
Mesh::AttributePointerImplementation Mesh::attributePointerImplementation = &Mesh::attributePointerImplementationDefault;
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
14 years ago
|
Mesh::AttributeIPointerImplementation Mesh::attributeIPointerImplementation = &Mesh::attributePointerImplementationDefault;
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
14 years ago
|
Mesh::AttributeLPointerImplementation Mesh::attributeLPointerImplementation = &Mesh::attributePointerImplementationDefault;
|
||
|
14 years ago
|
#endif
|
||
|
|
#endif
|
||
|
13 years ago
|
Mesh::BindIndexBufferImplementation Mesh::bindIndexBufferImplementation = &Mesh::bindIndexBufferImplementationDefault;
|
||
|
14 years ago
|
Mesh::BindImplementation Mesh::bindImplementation = &Mesh::bindImplementationDefault;
|
||
|
|
Mesh::UnbindImplementation Mesh::unbindImplementation = &Mesh::unbindImplementationDefault;
|
||
|
14 years ago
|
|
||
|
13 years ago
|
Int Mesh::maxVertexAttributes() { return AbstractShaderProgram::maxVertexAttributes(); }
|
||
|
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
|
Int Mesh::maxElementsIndices() {
|
||
|
|
GLint& value = Context::current()->state().mesh->maxElementsIndices;
|
||
|
|
|
||
|
|
/* Get the value, if not already cached */
|
||
|
|
if(value == 0)
|
||
|
|
glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &value);
|
||
|
|
|
||
|
|
return value;
|
||
|
|
}
|
||
|
|
|
||
|
|
Int Mesh::maxElementsVertices() {
|
||
|
|
GLint& value = Context::current()->state().mesh->maxElementsVertices;
|
||
|
|
|
||
|
|
/* Get the value, if not already cached */
|
||
|
|
if(value == 0)
|
||
|
|
glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &value);
|
||
|
|
|
||
|
|
return value;
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
13 years ago
|
std::size_t Mesh::indexSize(IndexType type) {
|
||
|
|
switch(type) {
|
||
|
|
case IndexType::UnsignedByte: return 1;
|
||
|
|
case IndexType::UnsignedShort: return 2;
|
||
|
|
case IndexType::UnsignedInt: return 4;
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
CORRADE_ASSERT_UNREACHABLE();
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
Mesh::Mesh(MeshPrimitive primitive): _primitive(primitive), _vertexCount(0), _indexCount(0)
|
||
|
13 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
13 years ago
|
, _indexStart(0), _indexEnd(0)
|
||
|
13 years ago
|
#endif
|
||
|
13 years ago
|
, _indexOffset(0), _indexType(IndexType::UnsignedInt), _indexBuffer(nullptr)
|
||
|
13 years ago
|
{
|
||
|
13 years ago
|
(this->*createImplementation)();
|
||
|
|
}
|
||
|
|
|
||
|
14 years ago
|
Mesh::~Mesh() {
|
||
|
13 years ago
|
/* Moved out, nothing to do */
|
||
|
|
if(!_id) return;
|
||
|
|
|
||
|
14 years ago
|
/* Remove current vao from the state */
|
||
|
13 years ago
|
GLuint& current = Context::current()->state().mesh->currentVAO;
|
||
|
13 years ago
|
if(current == _id) current = 0;
|
||
|
14 years ago
|
|
||
|
|
(this->*destroyImplementation)();
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
Mesh::Mesh(Mesh&& other) noexcept: _id(other._id), _primitive(other._primitive), _vertexCount(other._vertexCount), _indexCount(other._indexCount)
|
||
|
13 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
13 years ago
|
, _indexStart(other._indexStart), _indexEnd(other._indexEnd)
|
||
|
13 years ago
|
#endif
|
||
|
13 years ago
|
, _indexOffset(other._indexOffset), _indexType(other._indexType), _indexBuffer(other._indexBuffer), _attributes(std::move(other._attributes))
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
13 years ago
|
, _integerAttributes(std::move(other._integerAttributes))
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
, _longAttributes(std::move(other._longAttributes))
|
||
|
14 years ago
|
#endif
|
||
|
|
#endif
|
||
|
|
{
|
||
|
13 years ago
|
other._id = 0;
|
||
|
16 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
Mesh& Mesh::operator=(Mesh&& other) noexcept {
|
||
|
|
std::swap(_id, other._id);
|
||
|
|
std::swap(_primitive, other._primitive);
|
||
|
|
std::swap(_vertexCount, other._vertexCount);
|
||
|
|
std::swap(_indexCount, other._indexCount);
|
||
|
13 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
13 years ago
|
std::swap(_indexStart, other._indexStart);
|
||
|
|
std::swap(_indexEnd, other._indexEnd);
|
||
|
13 years ago
|
#endif
|
||
|
13 years ago
|
std::swap(_indexOffset, other._indexOffset);
|
||
|
|
std::swap(_indexType, other._indexType);
|
||
|
|
std::swap(_indexBuffer, other._indexBuffer);
|
||
|
|
std::swap(_attributes, other._attributes);
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
13 years ago
|
std::swap(_integerAttributes, other._integerAttributes);
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
std::swap(_longAttributes, other._longAttributes);
|
||
|
14 years ago
|
#endif
|
||
|
|
#endif
|
||
|
14 years ago
|
|
||
|
14 years ago
|
return *this;
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
|
std::string Mesh::label() const {
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
return Context::current()->state().debug->getLabelImplementation(GL_VERTEX_ARRAY, _id);
|
||
|
|
#else
|
||
|
|
return Context::current()->state().debug->getLabelImplementation(GL_VERTEX_ARRAY_KHR, _id);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
Mesh& Mesh::setLabel(const std::string& label) {
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
Context::current()->state().debug->labelImplementation(GL_VERTEX_ARRAY, _id, label);
|
||
|
|
#else
|
||
|
|
Context::current()->state().debug->labelImplementation(GL_VERTEX_ARRAY_KHR, _id, label);
|
||
|
|
#endif
|
||
|
|
return *this;
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
Mesh& Mesh::setIndexBuffer(Buffer& buffer, GLintptr offset, IndexType type, UnsignedInt start, UnsignedInt end) {
|
||
|
13 years ago
|
#if defined(CORRADE_TARGET_NACL) || defined(CORRADE_TARGET_EMSCRIPTEN)
|
||
|
13 years ago
|
CORRADE_ASSERT(buffer.targetHint() == Buffer::Target::ElementArray,
|
||
|
13 years ago
|
"Mesh::setIndexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::ElementArray << "but got" << buffer.targetHint(), *this);
|
||
|
13 years ago
|
#endif
|
||
|
|
|
||
|
13 years ago
|
_indexOffset = offset;
|
||
|
|
_indexType = type;
|
||
|
13 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
13 years ago
|
_indexStart = start;
|
||
|
|
_indexEnd = end;
|
||
|
13 years ago
|
#else
|
||
|
|
static_cast<void>(start);
|
||
|
|
static_cast<void>(end);
|
||
|
|
#endif
|
||
|
13 years ago
|
(this->*bindIndexBufferImplementation)(buffer);
|
||
|
13 years ago
|
return *this;
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
|
void Mesh::drawInternal(Int firstVertex, Int vertexCount, GLintptr indexOffset, Int indexCount, Int indexStart, Int indexEnd)
|
||
|
|
#else
|
||
|
|
void Mesh::drawInternal(Int firstVertex, Int vertexCount, GLintptr indexOffset, Int indexCount)
|
||
|
|
#endif
|
||
|
|
{
|
||
|
13 years ago
|
/* Nothing to draw */
|
||
|
13 years ago
|
if(!vertexCount && !indexCount) return;
|
||
|
14 years ago
|
|
||
|
13 years ago
|
(this->*bindImplementation)();
|
||
|
|
|
||
|
|
/* Non-indexed mesh */
|
||
|
13 years ago
|
if(!indexCount)
|
||
|
13 years ago
|
glDrawArrays(GLenum(_primitive), firstVertex, vertexCount);
|
||
|
13 years ago
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
|
/* Indexed mesh with specified range */
|
||
|
13 years ago
|
else if(indexEnd)
|
||
|
13 years ago
|
glDrawRangeElements(GLenum(_primitive), indexStart, indexEnd, indexCount, GLenum(_indexType), reinterpret_cast<GLvoid*>(indexOffset));
|
||
|
13 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
13 years ago
|
/* Indexed mesh without specified range */
|
||
|
|
else
|
||
|
13 years ago
|
glDrawElements(GLenum(_primitive), indexCount, GLenum(_indexType), reinterpret_cast<GLvoid*>(indexOffset));
|
||
|
16 years ago
|
|
||
|
13 years ago
|
(this->*unbindImplementation)();
|
||
|
16 years ago
|
}
|
||
|
|
|
||
|
14 years ago
|
void Mesh::bindVAO(GLuint vao) {
|
||
|
13 years ago
|
/** @todo Re-enable when extension loader is available for ES */
|
||
|
13 years ago
|
GLuint& current = Context::current()->state().mesh->currentVAO;
|
||
|
13 years ago
|
if(current != vao) {
|
||
|
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
|
glBindVertexArray(current = vao);
|
||
|
|
#else
|
||
|
|
CORRADE_INTERNAL_ASSERT(false);
|
||
|
|
//glBindVertexArrayOES(current = vao);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
14 years ago
|
void Mesh::vertexAttribPointer(const Attribute& attribute) {
|
||
|
|
glEnableVertexAttribArray(attribute.location);
|
||
|
|
attribute.buffer->bind(Buffer::Target::Array);
|
||
|
|
glVertexAttribPointer(attribute.location, attribute.size, attribute.type, attribute.normalized, attribute.stride, reinterpret_cast<const GLvoid*>(attribute.offset));
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
14 years ago
|
void Mesh::vertexAttribPointer(const IntegerAttribute& attribute) {
|
||
|
14 years ago
|
glEnableVertexAttribArray(attribute.location);
|
||
|
|
attribute.buffer->bind(Buffer::Target::Array);
|
||
|
14 years ago
|
glVertexAttribIPointer(attribute.location, attribute.size, attribute.type, attribute.stride, reinterpret_cast<const GLvoid*>(attribute.offset));
|
||
|
|
}
|
||
|
14 years ago
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
14 years ago
|
void Mesh::vertexAttribPointer(const LongAttribute& attribute) {
|
||
|
|
glEnableVertexAttribArray(attribute.location);
|
||
|
|
attribute.buffer->bind(Buffer::Target::Array);
|
||
|
|
glVertexAttribLPointer(attribute.location, attribute.size, attribute.type, attribute.stride, reinterpret_cast<const GLvoid*>(attribute.offset));
|
||
|
14 years ago
|
}
|
||
|
14 years ago
|
#endif
|
||
|
14 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
13 years ago
|
void Mesh::initializeContextBasedFunctionality(Context& context) {
|
||
|
13 years ago
|
/** @todo Enable when some extension wrangler is available in ES 2.0 */
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
if(context.isExtensionSupported<Extensions::GL::APPLE::vertex_array_object>())
|
||
|
|
#elif defined(MAGNUM_TARGET_GLES2)
|
||
|
|
if(context.isExtensionSupported<Extensions::GL::OES::vertex_array_object>())
|
||
|
|
#else
|
||
|
|
static_cast<void>(context);
|
||
|
|
#endif
|
||
|
|
{
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
14 years ago
|
Debug() << "Mesh: using" << Extensions::GL::APPLE::vertex_array_object::string() << "features";
|
||
|
13 years ago
|
#elif defined(MAGNUM_TARGET_GLES2)
|
||
|
|
Debug() << "Mesh: using" << Extensions::GL::OES::vertex_array_object::string() << "features";
|
||
|
|
#endif
|
||
|
14 years ago
|
|
||
|
|
createImplementation = &Mesh::createImplementationVAO;
|
||
|
|
destroyImplementation = &Mesh::destroyImplementationVAO;
|
||
|
14 years ago
|
|
||
|
13 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
if(context.isExtensionSupported<Extensions::GL::EXT::direct_state_access>()) {
|
||
|
14 years ago
|
Debug() << "Mesh: using" << Extensions::GL::EXT::direct_state_access::string() << "features";
|
||
|
14 years ago
|
|
||
|
|
attributePointerImplementation = &Mesh::attributePointerImplementationDSA;
|
||
|
|
attributeIPointerImplementation = &Mesh::attributePointerImplementationDSA;
|
||
|
|
attributeLPointerImplementation = &Mesh::attributePointerImplementationDSA;
|
||
|
13 years ago
|
} else
|
||
|
|
#endif
|
||
|
|
{
|
||
|
14 years ago
|
attributePointerImplementation = &Mesh::attributePointerImplementationVAO;
|
||
|
13 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
14 years ago
|
attributeIPointerImplementation = &Mesh::attributePointerImplementationVAO;
|
||
|
13 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
14 years ago
|
attributeLPointerImplementation = &Mesh::attributePointerImplementationVAO;
|
||
|
13 years ago
|
#endif
|
||
|
|
#endif
|
||
|
14 years ago
|
}
|
||
|
14 years ago
|
|
||
|
13 years ago
|
bindIndexBufferImplementation = &Mesh::bindIndexBufferImplementationVAO;
|
||
|
14 years ago
|
bindImplementation = &Mesh::bindImplementationVAO;
|
||
|
|
unbindImplementation = &Mesh::unbindImplementationVAO;
|
||
|
16 years ago
|
}
|
||
|
|
}
|
||
|
14 years ago
|
|
||
|
13 years ago
|
void Mesh::createImplementationDefault() { _id = 0; }
|
||
|
14 years ago
|
|
||
|
|
void Mesh::createImplementationVAO() {
|
||
|
14 years ago
|
/** @todo Get some extension wrangler instead to avoid linker errors to glGenVertexArrays() on ES2 */
|
||
|
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
13 years ago
|
glGenVertexArrays(1, &_id);
|
||
|
14 years ago
|
#endif
|
||
|
14 years ago
|
}
|
||
|
16 years ago
|
|
||
|
14 years ago
|
void Mesh::destroyImplementationDefault() {}
|
||
|
14 years ago
|
|
||
|
14 years ago
|
void Mesh::destroyImplementationVAO() {
|
||
|
14 years ago
|
/** @todo Get some extension wrangler instead to avoid linker errors to glDeleteVertexArrays() on ES2 */
|
||
|
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
13 years ago
|
glDeleteVertexArrays(1, &_id);
|
||
|
14 years ago
|
#endif
|
||
|
16 years ago
|
}
|
||
|
14 years ago
|
|
||
|
13 years ago
|
void Mesh::attributePointerImplementationDefault(const Attribute& attribute) {
|
||
|
13 years ago
|
#if defined(CORRADE_TARGET_NACL) || defined(CORRADE_TARGET_EMSCRIPTEN)
|
||
|
13 years ago
|
CORRADE_ASSERT(attribute.buffer->targetHint() == Buffer::Target::Array,
|
||
|
|
"Mesh::addVertexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::Array << "but got" << attribute.buffer->targetHint(), );
|
||
|
|
#endif
|
||
|
|
|
||
|
13 years ago
|
_attributes.push_back(attribute);
|
||
|
13 years ago
|
}
|
||
|
14 years ago
|
|
||
|
14 years ago
|
void Mesh::attributePointerImplementationVAO(const Attribute& attribute) {
|
||
|
13 years ago
|
#if defined(CORRADE_TARGET_NACL) || defined(CORRADE_TARGET_EMSCRIPTEN)
|
||
|
13 years ago
|
CORRADE_ASSERT(attribute.buffer->targetHint() == Buffer::Target::Array,
|
||
|
|
"Mesh::addVertexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::Array << "but got" << attribute.buffer->targetHint(), );
|
||
|
|
#endif
|
||
|
|
|
||
|
13 years ago
|
bindVAO(_id);
|
||
|
14 years ago
|
vertexAttribPointer(attribute);
|
||
|
|
}
|
||
|
14 years ago
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
14 years ago
|
void Mesh::attributePointerImplementationDSA(const Attribute& attribute) {
|
||
|
13 years ago
|
glEnableVertexArrayAttribEXT(_id, attribute.location);
|
||
|
|
glVertexArrayVertexAttribOffsetEXT(_id, attribute.buffer->id(), attribute.location, attribute.size, attribute.type, attribute.normalized, attribute.stride, attribute.offset);
|
||
|
14 years ago
|
}
|
||
|
14 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
13 years ago
|
void Mesh::attributePointerImplementationDefault(const IntegerAttribute& attribute) {
|
||
|
13 years ago
|
_integerAttributes.push_back(attribute);
|
||
|
13 years ago
|
}
|
||
|
14 years ago
|
|
||
|
|
void Mesh::attributePointerImplementationVAO(const IntegerAttribute& attribute) {
|
||
|
13 years ago
|
bindVAO(_id);
|
||
|
14 years ago
|
vertexAttribPointer(attribute);
|
||
|
|
}
|
||
|
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
14 years ago
|
void Mesh::attributePointerImplementationDSA(const IntegerAttribute& attribute) {
|
||
|
13 years ago
|
glEnableVertexArrayAttribEXT(_id, attribute.location);
|
||
|
|
glVertexArrayVertexAttribIOffsetEXT(_id, attribute.buffer->id(), attribute.location, attribute.size, attribute.type, attribute.stride, attribute.offset);
|
||
|
14 years ago
|
}
|
||
|
14 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
void Mesh::attributePointerImplementationDefault(const LongAttribute& attribute) {
|
||
|
13 years ago
|
_longAttributes.push_back(attribute);
|
||
|
13 years ago
|
}
|
||
|
14 years ago
|
|
||
|
|
void Mesh::attributePointerImplementationVAO(const LongAttribute& attribute) {
|
||
|
13 years ago
|
bindVAO(_id);
|
||
|
14 years ago
|
vertexAttribPointer(attribute);
|
||
|
|
}
|
||
|
|
|
||
|
|
void Mesh::attributePointerImplementationDSA(const LongAttribute& attribute) {
|
||
|
13 years ago
|
glEnableVertexArrayAttribEXT(_id, attribute.location);
|
||
|
|
glVertexArrayVertexAttribLOffsetEXT(_id, attribute.buffer->id(), attribute.location, attribute.size, attribute.type, attribute.stride, attribute.offset);
|
||
|
14 years ago
|
}
|
||
|
14 years ago
|
#endif
|
||
|
14 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
13 years ago
|
void Mesh::bindIndexBufferImplementationDefault(Buffer& buffer) {
|
||
|
13 years ago
|
_indexBuffer = &buffer;
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
void Mesh::bindIndexBufferImplementationVAO(Buffer& buffer) {
|
||
|
13 years ago
|
bindVAO(_id);
|
||
|
13 years ago
|
|
||
|
|
/* Reset ElementArray binding to force explicit glBindBuffer call later */
|
||
|
|
/** @todo Do this cleaner way */
|
||
|
13 years ago
|
Context::current()->state().buffer->bindings[Implementation::BufferState::indexForTarget(Buffer::Target::ElementArray)] = 0;
|
||
|
13 years ago
|
|
||
|
13 years ago
|
buffer.bind(Buffer::Target::ElementArray);
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
14 years ago
|
void Mesh::bindImplementationDefault() {
|
||
|
13 years ago
|
/* Specify vertex attributes */
|
||
|
13 years ago
|
for(const Attribute& attribute: _attributes)
|
||
|
14 years ago
|
vertexAttribPointer(attribute);
|
||
|
14 years ago
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
13 years ago
|
for(const IntegerAttribute& attribute: _integerAttributes)
|
||
|
14 years ago
|
vertexAttribPointer(attribute);
|
||
|
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
for(const LongAttribute& attribute: _longAttributes)
|
||
|
14 years ago
|
vertexAttribPointer(attribute);
|
||
|
|
#endif
|
||
|
14 years ago
|
#endif
|
||
|
13 years ago
|
|
||
|
|
/* Bind index buffer, if the mesh is indexed */
|
||
|
13 years ago
|
if(_indexCount) _indexBuffer->bind(Buffer::Target::ElementArray);
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
|
void Mesh::bindImplementationVAO() {
|
||
|
13 years ago
|
bindVAO(_id);
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
|
void Mesh::unbindImplementationDefault() {
|
||
|
13 years ago
|
for(const Attribute& attribute: _attributes)
|
||
|
14 years ago
|
glDisableVertexAttribArray(attribute.location);
|
||
|
14 years ago
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
13 years ago
|
for(const IntegerAttribute& attribute: _integerAttributes)
|
||
|
14 years ago
|
glDisableVertexAttribArray(attribute.location);
|
||
|
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
for(const LongAttribute& attribute: _longAttributes)
|
||
|
14 years ago
|
glDisableVertexAttribArray(attribute.location);
|
||
|
|
#endif
|
||
|
14 years ago
|
#endif
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
14 years ago
|
void Mesh::unbindImplementationVAO() {}
|
||
|
16 years ago
|
|
||
|
14 years ago
|
#ifndef DOXYGEN_GENERATING_OUTPUT
|
||
|
13 years ago
|
Debug operator<<(Debug debug, MeshPrimitive value) {
|
||
|
14 years ago
|
switch(value) {
|
||
|
13 years ago
|
#define _c(value) case MeshPrimitive::value: return debug << "MeshPrimitive::" #value;
|
||
|
14 years ago
|
_c(Points)
|
||
|
|
_c(LineStrip)
|
||
|
|
_c(LineLoop)
|
||
|
13 years ago
|
_c(Lines)
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
_c(LineStripAdjacency)
|
||
|
|
_c(LinesAdjacency)
|
||
|
|
#endif
|
||
|
14 years ago
|
_c(TriangleStrip)
|
||
|
|
_c(TriangleFan)
|
||
|
13 years ago
|
_c(Triangles)
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
_c(TriangleStripAdjacency)
|
||
|
|
_c(TrianglesAdjacency)
|
||
|
|
_c(Patches)
|
||
|
|
#endif
|
||
|
14 years ago
|
#undef _c
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
return debug << "MeshPrimitive::(invalid)";
|
||
|
14 years ago
|
}
|
||
|
13 years ago
|
|
||
|
|
Debug operator<<(Debug debug, Mesh::IndexType value) {
|
||
|
|
switch(value) {
|
||
|
|
#define _c(value) case Mesh::IndexType::value: return debug << "Mesh::IndexType::" #value;
|
||
|
|
_c(UnsignedByte)
|
||
|
|
_c(UnsignedShort)
|
||
|
|
_c(UnsignedInt)
|
||
|
|
#undef _c
|
||
|
|
}
|
||
|
|
|
||
|
|
return debug << "Mesh::IndexType::(invalid)";
|
||
|
|
}
|
||
|
14 years ago
|
#endif
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
namespace Corrade { namespace Utility {
|
||
|
|
|
||
|
13 years ago
|
std::string ConfigurationValue<Magnum::MeshPrimitive>::toString(Magnum::MeshPrimitive value, ConfigurationValueFlags) {
|
||
|
14 years ago
|
switch(value) {
|
||
|
13 years ago
|
#define _c(value) case Magnum::MeshPrimitive::value: return #value;
|
||
|
14 years ago
|
_c(Points)
|
||
|
|
_c(LineStrip)
|
||
|
|
_c(LineLoop)
|
||
|
13 years ago
|
_c(Lines)
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
_c(LineStripAdjacency)
|
||
|
|
_c(LinesAdjacency)
|
||
|
|
#endif
|
||
|
14 years ago
|
_c(TriangleStrip)
|
||
|
|
_c(TriangleFan)
|
||
|
13 years ago
|
_c(Triangles)
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
_c(TriangleStripAdjacency)
|
||
|
|
_c(TrianglesAdjacency)
|
||
|
|
_c(Patches)
|
||
|
|
#endif
|
||
|
14 years ago
|
#undef _c
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
return {};
|
||
|
16 years ago
|
}
|
||
|
14 years ago
|
|
||
|
13 years ago
|
Magnum::MeshPrimitive ConfigurationValue<Magnum::MeshPrimitive>::fromString(const std::string& stringValue, ConfigurationValueFlags) {
|
||
|
|
#define _c(value) if(stringValue == #value) return Magnum::MeshPrimitive::value;
|
||
|
14 years ago
|
_c(LineStrip)
|
||
|
|
_c(LineLoop)
|
||
|
13 years ago
|
_c(Lines)
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
_c(LineStripAdjacency)
|
||
|
|
_c(LinesAdjacency)
|
||
|
|
#endif
|
||
|
14 years ago
|
_c(TriangleStrip)
|
||
|
|
_c(TriangleFan)
|
||
|
13 years ago
|
_c(Triangles)
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
_c(TriangleStripAdjacency)
|
||
|
|
_c(TrianglesAdjacency)
|
||
|
|
_c(Patches)
|
||
|
|
#endif
|
||
|
14 years ago
|
#undef _c
|
||
|
|
|
||
|
13 years ago
|
return Magnum::MeshPrimitive::Points;
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
std::string ConfigurationValue<Magnum::Mesh::IndexType>::toString(Magnum::Mesh::IndexType value, ConfigurationValueFlags) {
|
||
|
|
switch(value) {
|
||
|
|
#define _c(value) case Magnum::Mesh::IndexType::value: return #value;
|
||
|
|
_c(UnsignedByte)
|
||
|
|
_c(UnsignedShort)
|
||
|
|
_c(UnsignedInt)
|
||
|
|
#undef _c
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
return {};
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
|
Magnum::Mesh::IndexType ConfigurationValue<Magnum::Mesh::IndexType>::fromString(const std::string& stringValue, ConfigurationValueFlags) {
|
||
|
|
#define _c(value) if(stringValue == #value) return Magnum::Mesh::IndexType::value;
|
||
|
|
_c(UnsignedByte)
|
||
|
|
_c(UnsignedShort)
|
||
|
|
_c(UnsignedInt)
|
||
|
|
#undef _c
|
||
|
|
|
||
|
|
return Magnum::Mesh::IndexType::UnsignedInt;
|
||
|
|
}
|
||
|
|
|
||
|
14 years ago
|
}}
|