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.
189 lines
7.9 KiB
189 lines
7.9 KiB
|
12 years ago
|
/*
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
8 years ago
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
|
||
|
12 years ago
|
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.
|
||
|
|
*/
|
||
|
|
|
||
|
|
#include "MeshState.h"
|
||
|
|
|
||
|
8 years ago
|
#include "Magnum/GL/Context.h"
|
||
|
|
#include "Magnum/GL/Extensions.h"
|
||
|
|
#include "Magnum/GL/MeshView.h"
|
||
|
12 years ago
|
|
||
|
12 years ago
|
#include "State.h"
|
||
|
|
|
||
|
12 years ago
|
namespace Magnum { namespace Implementation {
|
||
|
|
|
||
|
9 years ago
|
MeshState::MeshState(Context& context, ContextState& contextState, std::vector<std::string>& extensions): currentVAO(0)
|
||
|
12 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
12 years ago
|
, maxElementIndex{0}, maxElementsIndices{0}, maxElementsVertices{0}
|
||
|
12 years ago
|
#endif
|
||
|
|
{
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
12 years ago
|
if(context.isExtensionSupported<Extensions::GL::ARB::vertex_array_object>())
|
||
|
12 years ago
|
#elif defined(MAGNUM_TARGET_GLES2)
|
||
|
|
if(context.isExtensionSupported<Extensions::GL::OES::vertex_array_object>())
|
||
|
|
#else
|
||
|
|
static_cast<void>(context);
|
||
|
|
static_cast<void>(extensions);
|
||
|
|
#endif
|
||
|
|
{
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
9 years ago
|
extensions.emplace_back(Extensions::GL::ARB::vertex_array_object::string());
|
||
|
12 years ago
|
#elif defined(MAGNUM_TARGET_GLES2)
|
||
|
|
extensions.push_back(Extensions::GL::OES::vertex_array_object::string());
|
||
|
|
#endif
|
||
|
|
|
||
|
|
createImplementation = &Mesh::createImplementationVAO;
|
||
|
|
destroyImplementation = &Mesh::destroyImplementationVAO;
|
||
|
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
if(context.isExtensionSupported<Extensions::GL::EXT::direct_state_access>()) {
|
||
|
9 years ago
|
extensions.emplace_back(Extensions::GL::EXT::direct_state_access::string());
|
||
|
12 years ago
|
|
||
|
12 years ago
|
attributePointerImplementation = &Mesh::attributePointerImplementationDSAEXT;
|
||
|
12 years ago
|
} else
|
||
|
|
#endif
|
||
|
|
{
|
||
|
|
attributePointerImplementation = &Mesh::attributePointerImplementationVAO;
|
||
|
|
}
|
||
|
|
|
||
|
|
bindIndexBufferImplementation = &Mesh::bindIndexBufferImplementationVAO;
|
||
|
8 years ago
|
bindVAOImplementation = &Mesh::bindVAOImplementationVAO;
|
||
|
12 years ago
|
bindImplementation = &Mesh::bindImplementationVAO;
|
||
|
|
unbindImplementation = &Mesh::unbindImplementationVAO;
|
||
|
|
}
|
||
|
|
#if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES2)
|
||
|
|
else {
|
||
|
|
createImplementation = &Mesh::createImplementationDefault;
|
||
|
|
destroyImplementation = &Mesh::destroyImplementationDefault;
|
||
|
|
attributePointerImplementation = &Mesh::attributePointerImplementationDefault;
|
||
|
|
bindIndexBufferImplementation = &Mesh::bindIndexBufferImplementationDefault;
|
||
|
8 years ago
|
bindVAOImplementation = &Mesh::bindVAOImplementationDefault;
|
||
|
12 years ago
|
bindImplementation = &Mesh::bindImplementationDefault;
|
||
|
|
unbindImplementation = &Mesh::unbindImplementationDefault;
|
||
|
|
}
|
||
|
|
#endif
|
||
|
12 years ago
|
|
||
|
12 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
/* DSA create implementation (other cases handled above) */
|
||
|
|
if(context.isExtensionSupported<Extensions::GL::ARB::direct_state_access>()) {
|
||
|
9 years ago
|
extensions.emplace_back(Extensions::GL::ARB::direct_state_access::string());
|
||
|
12 years ago
|
createImplementation = &Mesh::createImplementationVAODSA;
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
12 years ago
|
#ifdef MAGNUM_TARGET_GLES
|
||
|
11 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
12 years ago
|
/* Multi draw implementation on ES */
|
||
|
|
if(context.isExtensionSupported<Extensions::GL::EXT::multi_draw_arrays>()) {
|
||
|
|
extensions.push_back(Extensions::GL::EXT::multi_draw_arrays::string());
|
||
|
|
|
||
|
|
multiDrawImplementation = &MeshView::multiDrawImplementationDefault;
|
||
|
|
} else multiDrawImplementation = &MeshView::multiDrawImplementationFallback;
|
||
|
11 years ago
|
#else
|
||
|
|
multiDrawImplementation = &MeshView::multiDrawImplementationFallback;
|
||
|
|
#endif
|
||
|
12 years ago
|
#endif
|
||
|
|
|
||
|
12 years ago
|
#ifdef MAGNUM_TARGET_GLES2
|
||
|
|
/* Instanced draw ímplementation on ES2 */
|
||
|
|
if(context.isExtensionSupported<Extensions::GL::ANGLE::instanced_arrays>()) {
|
||
|
|
extensions.push_back(Extensions::GL::ANGLE::instanced_arrays::string());
|
||
|
|
|
||
|
|
drawArraysInstancedImplementation = &Mesh::drawArraysInstancedImplementationANGLE;
|
||
|
|
drawElementsInstancedImplementation = &Mesh::drawElementsInstancedImplementationANGLE;
|
||
|
11 years ago
|
}
|
||
|
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
|
else if(context.isExtensionSupported<Extensions::GL::EXT::draw_instanced>()) {
|
||
|
12 years ago
|
extensions.push_back(Extensions::GL::EXT::draw_instanced::string());
|
||
|
|
|
||
|
|
drawArraysInstancedImplementation = &Mesh::drawArraysInstancedImplementationEXT;
|
||
|
|
drawElementsInstancedImplementation = &Mesh::drawElementsInstancedImplementationEXT;
|
||
|
|
|
||
|
|
} else if(context.isExtensionSupported<Extensions::GL::NV::draw_instanced>()) {
|
||
|
|
extensions.push_back(Extensions::GL::NV::draw_instanced::string());
|
||
|
|
|
||
|
|
drawArraysInstancedImplementation = &Mesh::drawArraysInstancedImplementationNV;
|
||
|
|
drawElementsInstancedImplementation = &Mesh::drawElementsInstancedImplementationNV;
|
||
|
11 years ago
|
}
|
||
|
|
#endif
|
||
|
|
else {
|
||
|
12 years ago
|
drawArraysInstancedImplementation = nullptr;
|
||
|
|
drawElementsInstancedImplementation = nullptr;
|
||
|
|
}
|
||
|
12 years ago
|
#endif
|
||
|
12 years ago
|
|
||
|
12 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
/* Partial EXT_DSA implementation of vertex attrib divisor */
|
||
|
|
if(context.isExtensionSupported<Extensions::GL::EXT::direct_state_access>()) {
|
||
|
|
if(glVertexArrayVertexAttribDivisorEXT)
|
||
|
|
vertexAttribDivisorImplementation = &Mesh::vertexAttribDivisorImplementationDSAEXT;
|
||
|
|
else vertexAttribDivisorImplementation = &Mesh::vertexAttribDivisorImplementationVAO;
|
||
|
|
} else vertexAttribDivisorImplementation = nullptr;
|
||
|
|
#elif defined(MAGNUM_TARGET_GLES2)
|
||
|
12 years ago
|
/* Instanced arrays implementation on ES2 */
|
||
|
|
if(context.isExtensionSupported<Extensions::GL::ANGLE::instanced_arrays>()) {
|
||
|
|
/* Extension added above */
|
||
|
|
|
||
|
|
vertexAttribDivisorImplementation = &Mesh::vertexAttribDivisorImplementationANGLE;
|
||
|
11 years ago
|
}
|
||
|
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
|
else if(context.isExtensionSupported<Extensions::GL::EXT::instanced_arrays>()) {
|
||
|
12 years ago
|
extensions.push_back(Extensions::GL::EXT::instanced_arrays::string());
|
||
|
|
|
||
|
|
vertexAttribDivisorImplementation = &Mesh::vertexAttribDivisorImplementationEXT;
|
||
|
|
|
||
|
|
} else if(context.isExtensionSupported<Extensions::GL::NV::instanced_arrays>()) {
|
||
|
|
extensions.push_back(Extensions::GL::NV::instanced_arrays::string());
|
||
|
|
|
||
|
|
vertexAttribDivisorImplementation = &Mesh::vertexAttribDivisorImplementationNV;
|
||
|
11 years ago
|
}
|
||
|
|
#endif
|
||
|
|
else vertexAttribDivisorImplementation = nullptr;
|
||
|
12 years ago
|
#endif
|
||
|
9 years ago
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
/* If we are on core profile and ARB_VAO was explicitly disabled by the
|
||
|
|
user, we need to bind a default VAO so we are still able to draw things */
|
||
|
|
if(context.isExtensionDisabled<Extensions::GL::ARB::vertex_array_object>() && context.isCoreProfileInternal(contextState)) {
|
||
|
|
glGenVertexArrays(1, &defaultVAO);
|
||
|
|
glBindVertexArray(defaultVAO);
|
||
|
|
}
|
||
|
|
#else
|
||
|
|
static_cast<void>(contextState);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
MeshState::~MeshState() {
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
/* If the default VAO was created, we need to delete it to avoid leaks */
|
||
|
|
if(defaultVAO) glDeleteVertexArrays(1, &defaultVAO);
|
||
|
|
#endif
|
||
|
12 years ago
|
}
|
||
|
|
|
||
|
12 years ago
|
void MeshState::reset() {
|
||
|
|
currentVAO = State::DisengagedBinding;
|
||
|
|
}
|
||
|
|
|
||
|
12 years ago
|
}}
|