@ -0,0 +1,67 @@ |
|||||||
|
# |
||||||
|
# This file is part of Magnum. |
||||||
|
# |
||||||
|
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015 |
||||||
|
# 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. |
||||||
|
# |
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 2.8.9) |
||||||
|
project(MyApplication) |
||||||
|
|
||||||
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../../modules/") |
||||||
|
|
||||||
|
find_package(Magnum REQUIRED |
||||||
|
MeshTools |
||||||
|
Primitives |
||||||
|
Shaders |
||||||
|
Sdl2Application) |
||||||
|
|
||||||
|
if(CORRADE_TARGET_APPLE) |
||||||
|
find_package(Magnum REQUIRED WindowlessCglApplication) |
||||||
|
elseif(CORRADE_TARGET_UNIX) |
||||||
|
find_package(Magnum REQUIRED WindowlessGlxApplication) |
||||||
|
elseif(CORRADE_TARGET_WINDOWS) |
||||||
|
find_package(Magnum REQUIRED WindowlessWglApplication) |
||||||
|
else() |
||||||
|
message(FATAL_ERROR "No windowless application available on this platform") |
||||||
|
endif() |
||||||
|
|
||||||
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake |
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/configure.h) |
||||||
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CORRADE_CXX_FLAGS}") |
||||||
|
include_directories(${MAGNUM_INCLUDE_DIRS} |
||||||
|
${MAGNUM_APPLICATION_INCLUDE_DIRS} |
||||||
|
${MAGNUM_WINDOWLESSAPPLICATION_INCLUDE_DIRS}) |
||||||
|
|
||||||
|
add_executable(hello hello.cpp) |
||||||
|
target_link_libraries(hello |
||||||
|
${MAGNUM_LIBRARIES} |
||||||
|
${MAGNUM_APPLICATION_LIBRARIES}) |
||||||
|
|
||||||
|
add_executable(shaders shaders.cpp) |
||||||
|
target_link_libraries(shaders |
||||||
|
${MAGNUM_LIBRARIES} |
||||||
|
${MAGNUM_MESHTOOLS_LIBRARIES} |
||||||
|
${MAGNUM_PRIMITIVES_LIBRARIES} |
||||||
|
${MAGNUM_SHADERS_LIBRARIES} |
||||||
|
${MAGNUM_WINDOWLESSAPPLICATION_LIBRARIES}) |
||||||
@ -0,0 +1,47 @@ |
|||||||
|
Source files for images in Magnum documentation |
||||||
|
----------------------------------------------- |
||||||
|
|
||||||
|
Compile and install Magnum with `Sdl2Application`, windowless application for |
||||||
|
your platform and `magnum-distancefieldconverter` utility and any `PngImporter` |
||||||
|
and `PngImageConverter` plugins from Magnum Plugins. |
||||||
|
|
||||||
|
Create build dir, point CMake to this directory and compile the executables: |
||||||
|
|
||||||
|
mkdir build-doc |
||||||
|
cd build-doc |
||||||
|
cmake ../doc/generated |
||||||
|
cmake --build . |
||||||
|
|
||||||
|
### "Getting started" image |
||||||
|
|
||||||
|
Displayed by the `hello` executable. Run the app and take screenshot using |
||||||
|
KSnapshot (including decorations, 880x707). Similarly for the gray version. The |
||||||
|
resulting files should be resized to half the size and without alpha channel |
||||||
|
using imagemagick: |
||||||
|
|
||||||
|
```bash |
||||||
|
mogrify -flatten -background '#ffffff' -resize 440 getting-started.png |
||||||
|
mogrify -flatten -background '#ffffff' -resize 440 getting-started-blue.png |
||||||
|
``` |
||||||
|
|
||||||
|
The output printed by the application can be used to update the example output |
||||||
|
in `doc/getting-started.dox`. |
||||||
|
|
||||||
|
### Shader images |
||||||
|
|
||||||
|
Generated by the `shaders` executable. Must be run in this directory, the |
||||||
|
output is put into `doc/` directory. The executable requires two textures: |
||||||
|
|
||||||
|
- `vector.png`, generated as full-page PNG output at 90 DPI from `vector.svg`, |
||||||
|
converted to pure grayscale using imagemagick: |
||||||
|
|
||||||
|
```bash |
||||||
|
mogrify -flatten -background '#ffffff' -format grayscale vector.png |
||||||
|
``` |
||||||
|
|
||||||
|
- `vector-distancefield.png`, generated as full-page PNG output at 360 DPI |
||||||
|
(1024x1024) and then processed through `magnum-distancefieldconverter` |
||||||
|
|
||||||
|
```bash |
||||||
|
magnum-distancefieldconverter --importer PngImporter --converter PngImageConverter --output-size "64 64" --radius 16 vector-src.png vector-distancefield.png |
||||||
|
``` |
||||||
@ -0,0 +1,54 @@ |
|||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015 |
||||||
|
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 <Magnum/Color.h> |
||||||
|
#include <Magnum/DefaultFramebuffer.h> |
||||||
|
#include <Magnum/Context.h> |
||||||
|
#include <Magnum/Renderer.h> |
||||||
|
#include <Magnum/Version.h> |
||||||
|
#include <Magnum/Platform/Sdl2Application.h> |
||||||
|
|
||||||
|
using namespace Magnum; |
||||||
|
|
||||||
|
class Hello: public Platform::Application { |
||||||
|
public: |
||||||
|
explicit Hello(const Arguments& arguments); |
||||||
|
|
||||||
|
private: |
||||||
|
void drawEvent() override; |
||||||
|
}; |
||||||
|
|
||||||
|
Hello::Hello(const Arguments& arguments): Platform::Application(arguments) { |
||||||
|
Renderer::setClearColor(Color3::fromHSV(216.0_degf, 0.85f, 1.0f)); |
||||||
|
Debug() << "Hello! This application is running on" << Context::current()->version() |
||||||
|
<< "using" << Context::current()->rendererString(); |
||||||
|
} |
||||||
|
|
||||||
|
void Hello::drawEvent() { |
||||||
|
defaultFramebuffer.clear(FramebufferClear::Color); |
||||||
|
swapBuffers(); |
||||||
|
} |
||||||
|
|
||||||
|
MAGNUM_APPLICATION_MAIN(Hello) |
||||||
@ -0,0 +1,301 @@ |
|||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015 |
||||||
|
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 <Corrade/PluginManager/Manager.h> |
||||||
|
#include <Corrade/Utility/Directory.h> |
||||||
|
|
||||||
|
#ifdef CORRADE_TARGET_APPLE |
||||||
|
#include <Magnum/Platform/WindowlessCglApplication.h> |
||||||
|
#elif defined(CORRADE_TARGET_UNIX) |
||||||
|
#include <Magnum/Platform/WindowlessGlxApplication.h> |
||||||
|
#elif defined(CORRADE_TARGET_WINDOWS) |
||||||
|
#include <Magnum/Platform/WindowlessWglApplication.h> |
||||||
|
#else |
||||||
|
#error No windowless application available on this platform |
||||||
|
#endif |
||||||
|
|
||||||
|
#include <Magnum/Buffer.h> |
||||||
|
#include <Magnum/Framebuffer.h> |
||||||
|
#include <Magnum/Image.h> |
||||||
|
#include <Magnum/Mesh.h> |
||||||
|
#include <Magnum/Renderbuffer.h> |
||||||
|
#include <Magnum/RenderbufferFormat.h> |
||||||
|
#include <Magnum/MeshTools/Compile.h> |
||||||
|
#include <Magnum/MeshTools/Interleave.h> |
||||||
|
#include <Magnum/Primitives/Square.h> |
||||||
|
#include <Magnum/Primitives/Circle.h> |
||||||
|
#include <Magnum/Primitives/Icosphere.h> |
||||||
|
#include <Magnum/Primitives/UVSphere.h> |
||||||
|
#include <Magnum/Shaders/Flat.h> |
||||||
|
#include <Magnum/Shaders/MeshVisualizer.h> |
||||||
|
#include <Magnum/Shaders/Phong.h> |
||||||
|
#include <Magnum/Shaders/VertexColor.h> |
||||||
|
#include <Magnum/Shaders/Vector.h> |
||||||
|
#include <Magnum/Shaders/DistanceFieldVector.h> |
||||||
|
#include <Magnum/Trade/AbstractImageConverter.h> |
||||||
|
#include <Magnum/Trade/ImageData.h> |
||||||
|
#include <Magnum/Trade/MeshData2D.h> |
||||||
|
#include <Magnum/Trade/MeshData3D.h> |
||||||
|
#include <Magnum/Trade/AbstractImporter.h> |
||||||
|
#include <Magnum/Renderer.h> |
||||||
|
#include <Magnum/ColorFormat.h> |
||||||
|
#include <Magnum/Texture.h> |
||||||
|
#include <Magnum/TextureFormat.h> |
||||||
|
|
||||||
|
#include "configure.h" |
||||||
|
|
||||||
|
using namespace Magnum; |
||||||
|
|
||||||
|
struct ShaderVisualizer: Platform::WindowlessApplication { |
||||||
|
using Platform::WindowlessApplication::WindowlessApplication; |
||||||
|
|
||||||
|
int exec() override; |
||||||
|
|
||||||
|
std::string phong(); |
||||||
|
std::string meshVisualizer(); |
||||||
|
std::string flat(); |
||||||
|
std::string vertexColor(); |
||||||
|
|
||||||
|
std::string vector(); |
||||||
|
std::string distanceFieldVector(); |
||||||
|
|
||||||
|
std::unique_ptr<Trade::AbstractImporter> _importer; |
||||||
|
}; |
||||||
|
|
||||||
|
namespace { |
||||||
|
constexpr const Vector2i ImageSize{256}; |
||||||
|
} |
||||||
|
|
||||||
|
int ShaderVisualizer::exec() { |
||||||
|
PluginManager::Manager<Trade::AbstractImageConverter> converterManager{MAGNUM_PLUGINS_IMAGECONVERTER_DIR}; |
||||||
|
std::unique_ptr<Trade::AbstractImageConverter> converter = converterManager.loadAndInstantiate("PngImageConverter"); |
||||||
|
if(!converter) { |
||||||
|
Error() << "Cannot load image converter plugin"; |
||||||
|
std::exit(1); |
||||||
|
} |
||||||
|
|
||||||
|
PluginManager::Manager<Trade::AbstractImporter> importerManager{MAGNUM_PLUGINS_IMPORTER_DIR}; |
||||||
|
_importer = importerManager.loadAndInstantiate("PngImporter"); |
||||||
|
if(!_importer) { |
||||||
|
Error() << "Cannot load image importer plugin"; |
||||||
|
std::exit(1); |
||||||
|
} |
||||||
|
|
||||||
|
Renderbuffer multisampleColor, multisampleDepth; |
||||||
|
multisampleColor.setStorageMultisample(16, RenderbufferFormat::RGBA8, ImageSize); |
||||||
|
multisampleDepth.setStorageMultisample(16, RenderbufferFormat::DepthComponent24, ImageSize); |
||||||
|
|
||||||
|
Framebuffer multisampleFramebuffer{{{}, ImageSize}}; |
||||||
|
multisampleFramebuffer.attachRenderbuffer(Framebuffer::ColorAttachment{0}, multisampleColor) |
||||||
|
.attachRenderbuffer(Framebuffer::BufferAttachment::Depth, multisampleDepth) |
||||||
|
.bind(); |
||||||
|
CORRADE_INTERNAL_ASSERT(multisampleFramebuffer.checkStatus(FramebufferTarget::Draw) == Framebuffer::Status::Complete); |
||||||
|
|
||||||
|
Renderbuffer color; |
||||||
|
color.setStorage(RenderbufferFormat::RGBA8, ImageSize); |
||||||
|
Framebuffer framebuffer{{{}, ImageSize}}; |
||||||
|
framebuffer.attachRenderbuffer(Framebuffer::ColorAttachment{0}, color); |
||||||
|
|
||||||
|
Renderer::enable(Renderer::Feature::DepthTest); |
||||||
|
|
||||||
|
for(auto fun: {&ShaderVisualizer::phong, |
||||||
|
&ShaderVisualizer::meshVisualizer, |
||||||
|
&ShaderVisualizer::flat, |
||||||
|
&ShaderVisualizer::vertexColor, |
||||||
|
&ShaderVisualizer::vector, |
||||||
|
&ShaderVisualizer::distanceFieldVector}) { |
||||||
|
multisampleFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth); |
||||||
|
|
||||||
|
std::string filename = (this->*fun)(); |
||||||
|
|
||||||
|
AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), FramebufferBlit::Color); |
||||||
|
Image2D result = framebuffer.read(framebuffer.viewport(), {ColorFormat::RGBA, ColorType::UnsignedByte}); |
||||||
|
converter->exportToFile(result, Utility::Directory::join("../", "shaders-" + filename)); |
||||||
|
} |
||||||
|
|
||||||
|
_importer.reset(); |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
namespace { |
||||||
|
const auto Projection = Matrix4::perspectiveProjection(35.0_degf, 1.0f, 0.001f, 100.0f); |
||||||
|
const auto Transformation = Matrix4::translation(Vector3::zAxis(-5.0f)); |
||||||
|
const auto BaseColor = Color3::fromHSV(216.0_degf, 0.85f, 1.0f); |
||||||
|
const auto OutlineColor = Color3{0.95f}; |
||||||
|
} |
||||||
|
|
||||||
|
std::string ShaderVisualizer::phong() { |
||||||
|
std::unique_ptr<Buffer> vertices, indices; |
||||||
|
Mesh mesh; |
||||||
|
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::UVSphere::solid(16, 32), BufferUsage::StaticDraw); |
||||||
|
|
||||||
|
Shaders::Phong shader; |
||||||
|
shader.setAmbientColor(Color3(0.025f)) |
||||||
|
.setDiffuseColor(BaseColor) |
||||||
|
.setShininess(200.0f) |
||||||
|
.setLightPosition({5.0f, 5.0f, 7.0f}) |
||||||
|
.setProjectionMatrix(Projection) |
||||||
|
.setTransformationMatrix(Transformation) |
||||||
|
.setNormalMatrix(Transformation.rotationScaling()); |
||||||
|
|
||||||
|
mesh.draw(shader); |
||||||
|
|
||||||
|
return "phong.png"; |
||||||
|
} |
||||||
|
|
||||||
|
std::string ShaderVisualizer::meshVisualizer() { |
||||||
|
std::unique_ptr<Buffer> vertices, indices; |
||||||
|
Mesh mesh; |
||||||
|
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::Icosphere::solid(1), BufferUsage::StaticDraw); |
||||||
|
|
||||||
|
const Matrix4 projection = Projection*Transformation* |
||||||
|
Matrix4::rotationZ(13.7_degf)* |
||||||
|
Matrix4::rotationX(-12.6_degf); |
||||||
|
|
||||||
|
Shaders::MeshVisualizer shader{Shaders::MeshVisualizer::Flag::Wireframe}; |
||||||
|
shader.setColor(BaseColor) |
||||||
|
.setWireframeColor(OutlineColor) |
||||||
|
.setViewportSize(Vector2{ImageSize}) |
||||||
|
.setTransformationProjectionMatrix(projection); |
||||||
|
|
||||||
|
mesh.draw(shader); |
||||||
|
|
||||||
|
return "meshvisualizer.png"; |
||||||
|
} |
||||||
|
|
||||||
|
std::string ShaderVisualizer::flat() { |
||||||
|
std::unique_ptr<Buffer> vertices, indices; |
||||||
|
Mesh mesh; |
||||||
|
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::UVSphere::solid(16, 32), BufferUsage::StaticDraw); |
||||||
|
|
||||||
|
Shaders::Flat3D shader; |
||||||
|
shader.setColor(BaseColor) |
||||||
|
.setTransformationProjectionMatrix(Projection*Transformation); |
||||||
|
|
||||||
|
mesh.draw(shader); |
||||||
|
|
||||||
|
return "flat.png"; |
||||||
|
} |
||||||
|
|
||||||
|
std::string ShaderVisualizer::vertexColor() { |
||||||
|
Trade::MeshData3D sphere = Primitives::UVSphere::solid(32, 64); |
||||||
|
|
||||||
|
/* Color vertices nearest to given position */ |
||||||
|
auto target = Vector3{2.0f, 2.0f, 7.0f}.normalized(); |
||||||
|
std::vector<Color3> colors; |
||||||
|
colors.reserve(sphere.positions(0).size()); |
||||||
|
for(Vector3 position: sphere.positions(0)) |
||||||
|
colors.push_back(Color3::fromHSV(Math::lerp(240.0_degf, 420.0_degf, Math::max(1.0f - (position - target).length(), 0.0f)), 0.85f, 0.85f)); |
||||||
|
|
||||||
|
Buffer vertices, indices; |
||||||
|
vertices.setData(MeshTools::interleave(sphere.positions(0), colors), BufferUsage::StaticDraw); |
||||||
|
indices.setData(sphere.indices(), BufferUsage::StaticDraw); |
||||||
|
|
||||||
|
Mesh mesh; |
||||||
|
mesh.setPrimitive(MeshPrimitive::Triangles) |
||||||
|
.setCount(sphere.indices().size()) |
||||||
|
.addVertexBuffer(vertices, 0, Shaders::VertexColor3D::Position{}, Shaders::VertexColor3D::Color{}) |
||||||
|
.setIndexBuffer(indices, 0, Mesh::IndexType::UnsignedInt); |
||||||
|
|
||||||
|
Shaders::VertexColor3D shader; |
||||||
|
shader.setTransformationProjectionMatrix(Projection*Transformation); |
||||||
|
|
||||||
|
mesh.draw(shader); |
||||||
|
|
||||||
|
return "vertexcolor.png"; |
||||||
|
} |
||||||
|
|
||||||
|
std::string ShaderVisualizer::vector() { |
||||||
|
std::optional<Trade::ImageData2D> image; |
||||||
|
if(!_importer->openFile("vector.png") || !(image = _importer->image2D(0))) { |
||||||
|
Error() << "Cannot open vector.png"; |
||||||
|
return "vector.png"; |
||||||
|
} |
||||||
|
|
||||||
|
Texture2D texture; |
||||||
|
texture.setMinificationFilter(Sampler::Filter::Linear) |
||||||
|
.setMagnificationFilter(Sampler::Filter::Linear) |
||||||
|
.setWrapping(Sampler::Wrapping::ClampToEdge) |
||||||
|
.setStorage(1, TextureFormat::RGBA8, image->size()) |
||||||
|
.setSubImage(0, {}, *image); |
||||||
|
|
||||||
|
Mesh mesh; |
||||||
|
std::unique_ptr<Buffer> vertices; |
||||||
|
std::tie(mesh, vertices, std::ignore) = MeshTools::compile(Primitives::Square::solid(Primitives::Square::TextureCoords::Generate), BufferUsage::StaticDraw); |
||||||
|
|
||||||
|
Shaders::Vector2D shader; |
||||||
|
shader.setColor(BaseColor) |
||||||
|
.setVectorTexture(texture) |
||||||
|
.setTransformationProjectionMatrix({}); |
||||||
|
|
||||||
|
Renderer::enable(Renderer::Feature::Blending); |
||||||
|
Renderer::setBlendFunction(Renderer::BlendFunction::One, Renderer::BlendFunction::OneMinusSourceAlpha); |
||||||
|
Renderer::setBlendEquation(Renderer::BlendEquation::Add, Renderer::BlendEquation::Add); |
||||||
|
|
||||||
|
mesh.draw(shader); |
||||||
|
|
||||||
|
Renderer::disable(Renderer::Feature::Blending); |
||||||
|
|
||||||
|
return "vector.png"; |
||||||
|
} |
||||||
|
|
||||||
|
std::string ShaderVisualizer::distanceFieldVector() { |
||||||
|
std::optional<Trade::ImageData2D> image; |
||||||
|
if(!_importer->openFile("vector-distancefield.png") || !(image = _importer->image2D(0))) { |
||||||
|
Error() << "Cannot open vector-distancefield.png"; |
||||||
|
return "distancefieldvector.png"; |
||||||
|
} |
||||||
|
|
||||||
|
Texture2D texture; |
||||||
|
texture.setMinificationFilter(Sampler::Filter::Linear) |
||||||
|
.setMagnificationFilter(Sampler::Filter::Linear) |
||||||
|
.setWrapping(Sampler::Wrapping::ClampToEdge) |
||||||
|
.setStorage(1, TextureFormat::RGBA8, image->size()) |
||||||
|
.setSubImage(0, {}, *image); |
||||||
|
|
||||||
|
Mesh mesh; |
||||||
|
std::unique_ptr<Buffer> vertices; |
||||||
|
std::tie(mesh, vertices, std::ignore) = MeshTools::compile(Primitives::Square::solid(Primitives::Square::TextureCoords::Generate), BufferUsage::StaticDraw); |
||||||
|
|
||||||
|
Shaders::DistanceFieldVector2D shader; |
||||||
|
shader.setColor(BaseColor) |
||||||
|
.setOutlineColor(OutlineColor) |
||||||
|
.setOutlineRange(0.6f, 0.4f) |
||||||
|
.setVectorTexture(texture) |
||||||
|
.setTransformationProjectionMatrix({}); |
||||||
|
|
||||||
|
Renderer::enable(Renderer::Feature::Blending); |
||||||
|
Renderer::setBlendFunction(Renderer::BlendFunction::One, Renderer::BlendFunction::OneMinusSourceAlpha); |
||||||
|
Renderer::setBlendEquation(Renderer::BlendEquation::Add, Renderer::BlendEquation::Add); |
||||||
|
|
||||||
|
mesh.draw(shader); |
||||||
|
|
||||||
|
Renderer::disable(Renderer::Feature::Blending); |
||||||
|
|
||||||
|
return "distancefieldvector.png"; |
||||||
|
} |
||||||
|
|
||||||
|
MAGNUM_WINDOWLESSAPPLICATION_MAIN(ShaderVisualizer) |
||||||
|
After Width: | Height: | Size: 852 B |
|
After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 7.4 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 7.5 KiB After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 4.7 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 20 KiB |
@ -0,0 +1,136 @@ |
|||||||
|
/* |
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015 |
||||||
|
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. |
||||||
|
*/ |
||||||
|
|
||||||
|
namespace Magnum { |
||||||
|
/** @page shaders Builtin shaders |
||||||
|
@brief Overview and basic usage of builtin shaders. |
||||||
|
|
||||||
|
- Previous page: @ref plugins |
||||||
|
- Next page: @ref scenegraph |
||||||
|
|
||||||
|
@tableofcontents |
||||||
|
|
||||||
|
Magnum contains a set of general-purpose shaders for easy prototyping, UI |
||||||
|
rendering and data visualization/debugging in both 2D and 3D scenes. The |
||||||
|
following shaders are available, see documentation of each class for sample |
||||||
|
output and example setup: |
||||||
|
|
||||||
|
- @ref Shaders::Flat "Shaders::Flat*D" -- flat shading using single color or |
||||||
|
texture |
||||||
|
- @ref Shaders::Vector "Shaders::Vector*D" -- colored vector graphics |
||||||
|
- @ref Shaders::DistanceFieldVector "Shaders::DistanceFieldVector*D" -- |
||||||
|
colored and outlined vector graphics |
||||||
|
- @ref Shaders::VertexColor "Shaders::VertexColor*D" -- vertex-colored meshes |
||||||
|
- @ref Shaders::Phong -- Phong shading using colors or textures, 3D only |
||||||
|
- @ref Shaders::MeshVisualizer -- wireframe visualization, 3D only |
||||||
|
|
||||||
|
All the builtin shaders can be used on unextended OpenGL 2.1 and OpenGL ES 2.0 |
||||||
|
/ WebGL 1.0, but they try to use the most recent technology available to have |
||||||
|
them as efficient as possible on every configuration. |
||||||
|
|
||||||
|
@section shaders-usage Usage |
||||||
|
|
||||||
|
Shader usage is divided into two parts: configuring vertex attributes in the |
||||||
|
mesh and configuring the shader itself. |
||||||
|
|
||||||
|
Each shader expects some set of vertex attributes, thus when adding vertex |
||||||
|
buffer into the mesh, you need to specify which shader attributes are on which |
||||||
|
position in the buffer. See @ref Mesh::addVertexBuffer() for details and usage |
||||||
|
examples. Example mesh configuration for @ref Shaders::Phong shader: |
||||||
|
@code |
||||||
|
struct Vertex { |
||||||
|
Vector3 position; |
||||||
|
Vector3 normal; |
||||||
|
Vector2 textureCoordinates; |
||||||
|
}; |
||||||
|
Vertex data[] = { ... }; |
||||||
|
|
||||||
|
Buffer vertices; |
||||||
|
vertices.setData(data, BufferUsage::StaticDraw); |
||||||
|
|
||||||
|
Mesh mesh; |
||||||
|
mesh.addVertexBuffer(vertices, 0, |
||||||
|
Shaders::Phong::Position{}, |
||||||
|
Shaders::Phong::Normal{}, |
||||||
|
Shaders::Phong::TextureCoordinates{}); |
||||||
|
@endcode |
||||||
|
|
||||||
|
Each shader then has its own set of configuration functions. Some configuration |
||||||
|
is static, specified commonly as flags in constructor, directly affecting |
||||||
|
compiled shader code. Other configuration is specified through uniforms and |
||||||
|
various binding points, commonly exposed through various setters. Example |
||||||
|
configuration and rendering using @ref Shaders::Phong "Shaders::Phong": |
||||||
|
@code |
||||||
|
Matrix4 transformationMatrix, projectionMatrix; |
||||||
|
Texture2D diffuseTexture, specularTexture; |
||||||
|
|
||||||
|
Shaders::Phong shader{Shaders::Phong::DiffuseTexture}; |
||||||
|
shader.setDiffuseTexture(diffuseTexture) |
||||||
|
.setLightPosition({5.0f, 5.0f, 7.0f}) |
||||||
|
.setTransformationMatrix(transformationMatrix) |
||||||
|
.setNormalMatrix(transformationMatrix.rotation()) |
||||||
|
.setProjectionMatrix(projectionMatrix); |
||||||
|
|
||||||
|
mesh.draw(shader); |
||||||
|
@endcode |
||||||
|
|
||||||
|
@section shaders-generic Generic vertex attributes |
||||||
|
|
||||||
|
Many shaders share the same vertex attribute definitions, such as positions, |
||||||
|
normals, texture coordinates etc. It's thus possible to configure the mesh |
||||||
|
for *generic* shader and then render it with any compatible shader. Definition |
||||||
|
of generic attributes is available in @ref Shaders::Generic class. |
||||||
|
Configuration of the above mesh using generic attributes could then look like |
||||||
|
this: |
||||||
|
@code |
||||||
|
mesh.addVertexBuffer(vertices, 0, |
||||||
|
Shaders::Generic3D::Position{}, |
||||||
|
Shaders::Generic3D::Normal{}, |
||||||
|
Shaders::Generic3D::TextureCoordinates{}); |
||||||
|
@endcode |
||||||
|
Note that in this particular case both configurations are equivalent, because |
||||||
|
@ref Shaders::Phong also uses generic vertex attribute definitions. |
||||||
|
|
||||||
|
Then you can render the mesh using @ref Shaders::Phong shader like above, or |
||||||
|
use for example @ref Shaders::Flat3D or even @ref Shaders::MeshVisualizer with |
||||||
|
the same mesh reconfiguration. The unused attributes will be simply ignored. |
||||||
|
@code |
||||||
|
Shaders::MeshVisualizer visualizerShader{Shaders::MeshVisualizer::Wireframe}; |
||||||
|
visualizerShader.setColor(Color3::fromHSV(216.0_degf, 0.85f, 1.0f)) |
||||||
|
.setWireframeColor(Color3{0.95f}) |
||||||
|
.setViewportSize(defaultFramebuffer.viewport().size()) |
||||||
|
.setTransformationProjectionMatrix(projectionMatrix*transformationMatrix); |
||||||
|
|
||||||
|
mesh.draw(visualizerShader); |
||||||
|
@endcode |
||||||
|
|
||||||
|
The @ref MeshTools::compile() utility configures meshes using generic vertex |
||||||
|
attribute definitions to make them usable with any shader. |
||||||
|
|
||||||
|
- Previous page: @ref plugins |
||||||
|
- Next page: @ref scenegraph |
||||||
|
|
||||||
|
*/ |
||||||
|
} |
||||||
@ -0,0 +1,26 @@ |
|||||||
|
# |
||||||
|
# This file is part of Magnum. |
||||||
|
# |
||||||
|
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015 |
||||||
|
# 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(${CMAKE_CURRENT_LIST_DIR}/FindMagnum.cmake) |
||||||
@ -0,0 +1,158 @@ |
|||||||
|
<?xml version='1.0' encoding='UTF-8'?> |
||||||
|
<matrix-project> |
||||||
|
<actions/> |
||||||
|
<description></description> |
||||||
|
<logRotator class="hudson.tasks.LogRotator"> |
||||||
|
<daysToKeep>-1</daysToKeep> |
||||||
|
<numToKeep>10</numToKeep> |
||||||
|
<artifactDaysToKeep>-1</artifactDaysToKeep> |
||||||
|
<artifactNumToKeep>-1</artifactNumToKeep> |
||||||
|
</logRotator> |
||||||
|
<keepDependencies>false</keepDependencies> |
||||||
|
<properties/> |
||||||
|
<scm class="hudson.plugins.git.GitSCM" plugin="git@2.0"> |
||||||
|
<configVersion>2</configVersion> |
||||||
|
<userRemoteConfigs> |
||||||
|
<hudson.plugins.git.UserRemoteConfig> |
||||||
|
<url>git://github.com/mosra/magnum.git</url> |
||||||
|
</hudson.plugins.git.UserRemoteConfig> |
||||||
|
</userRemoteConfigs> |
||||||
|
<branches> |
||||||
|
<hudson.plugins.git.BranchSpec> |
||||||
|
<name>*/master</name> |
||||||
|
</hudson.plugins.git.BranchSpec> |
||||||
|
</branches> |
||||||
|
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations> |
||||||
|
<submoduleCfg class="list"/> |
||||||
|
<extensions> |
||||||
|
<hudson.plugins.git.extensions.impl.CloneOption> |
||||||
|
<shallow>true</shallow> |
||||||
|
<reference></reference> |
||||||
|
</hudson.plugins.git.extensions.impl.CloneOption> |
||||||
|
</extensions> |
||||||
|
</scm> |
||||||
|
<canRoam>true</canRoam> |
||||||
|
<disabled>false</disabled> |
||||||
|
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> |
||||||
|
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> |
||||||
|
<triggers/> |
||||||
|
<concurrentBuild>false</concurrentBuild> |
||||||
|
<customWorkspace>Magnum</customWorkspace> |
||||||
|
<axes> |
||||||
|
<hudson.matrix.TextAxis> |
||||||
|
<name>gl</name> |
||||||
|
<values> |
||||||
|
<string>desktop</string> |
||||||
|
<string>es2</string> |
||||||
|
<string>es2desktop</string> |
||||||
|
<string>es3</string> |
||||||
|
<string>es3desktop</string> |
||||||
|
</values> |
||||||
|
</hudson.matrix.TextAxis> |
||||||
|
<hudson.matrix.TextAxis> |
||||||
|
<name>compatibility</name> |
||||||
|
<values> |
||||||
|
<string></string> |
||||||
|
<string>deprecated</string> |
||||||
|
</values> |
||||||
|
</hudson.matrix.TextAxis> |
||||||
|
</axes> |
||||||
|
<builders> |
||||||
|
<hudson.tasks.Shell> |
||||||
|
<command> |
||||||
|
<![CDATA[ |
||||||
|
if [ "${compatibility}" = "deprecated" ] ; then |
||||||
|
deprecated_build_flag=ON |
||||||
|
else |
||||||
|
deprecated_build_flag=OFF |
||||||
|
fi |
||||||
|
|
||||||
|
if [ ${gl} = "desktop" ] ; then |
||||||
|
desktop_flag=ON |
||||||
|
es_flag=OFF |
||||||
|
windowless_flag=ON |
||||||
|
elif [ ${gl} = "es2" ] ; then |
||||||
|
gl_flags="-DTARGET_GLES=ON -DTARGET_GLES2=ON" |
||||||
|
desktop_flag=OFF |
||||||
|
es_flag=ON |
||||||
|
windowless_flag=OFF |
||||||
|
elif [ ${gl} = "es2desktop" ] ; then |
||||||
|
gl_flags="-DTARGET_GLES=ON -DTARGET_GLES2=ON -DTARGET_DESKTOP_GLES=ON" |
||||||
|
desktop_flag=OFF |
||||||
|
es_flag=OFF |
||||||
|
windowless_flag=ON |
||||||
|
elif [ ${gl} = "es3" ] ; then |
||||||
|
gl_flags="-DTARGET_GLES=ON -DTARGET_GLES2=OFF" |
||||||
|
desktop_flag=OFF |
||||||
|
es_flag=ON |
||||||
|
windowless_flag=OFF |
||||||
|
elif [ ${gl} = "es3desktop" ] ; then |
||||||
|
gl_flags="-DTARGET_GLES=ON -DTARGET_GLES2=OFF -DTARGET_DESKTOP_GLES=ON" |
||||||
|
desktop_flag=OFF |
||||||
|
es_flag=OFF |
||||||
|
windowless_flag=ON |
||||||
|
fi |
||||||
|
|
||||||
|
mkdir -p build-clang-analyzer-${compatibility}-${gl} |
||||||
|
cd build-clang-analyzer-${compatibility}-${gl} |
||||||
|
|
||||||
|
scan-build --use-c++=$(which clang++) cmake .. \ |
||||||
|
-DCMAKE_BUILD_TYPE=Debug \ |
||||||
|
-DCMAKE_FIND_ROOT_PATH=${JENKINS_HOME}/filesystem/clang-analyzer-${compatibility} \ |
||||||
|
-DCMAKE_INSTALL_PREFIX=${JENKINS_HOME}/filesystem/clang-analyzer-${compatibility}-${gl} \ |
||||||
|
-DCMAKE_INSTALL_RPATH="${JENKINS_HOME}/filesystem/clang-analyzer-${compatibility}/lib;${JENKINS_HOME}/filesystem/clang-analyzer-${compatibility}-${gl}/lib" \ |
||||||
|
-DCMAKE_CXX_FLAGS="-std=c++11 -stdlib=libc++" \ |
||||||
|
-DCMAKE_EXE_LINKER_FLAGS=-lc++abi \ |
||||||
|
-DBUILD_TESTS=ON \ |
||||||
|
-DBUILD_GL_TESTS=${windowless_flag} \ |
||||||
|
-DBUILD_DEPRECATED=${deprecated_build_flag} \ |
||||||
|
${gl_flags} \ |
||||||
|
-DWITH_AUDIO=ON \ |
||||||
|
-DWITH_GLUTAPPLICATION=ON \ |
||||||
|
-DWITH_GLXAPPLICATION=ON \ |
||||||
|
-DWITH_SDL2APPLICATION=ON \ |
||||||
|
-DWITH_XEGLAPPLICATION=ON \ |
||||||
|
-DWITH_EGLCONTEXT=ON \ |
||||||
|
-DWITH_GLXCONTEXT=ON \ |
||||||
|
-DWITH_MAGNUMFONT=ON \ |
||||||
|
-DWITH_MAGNUMFONTCONVERTER=${desktop_flag} \ |
||||||
|
-DWITH_OBJIMPORTER=ON \ |
||||||
|
-DWITH_TGAIMAGECONVERTER=ON \ |
||||||
|
-DWITH_TGAIMPORTER=ON \ |
||||||
|
-DWITH_WAVAUDIOIMPORTER=ON \ |
||||||
|
-DWITH_DISTANCEFIELDCONVERTER=${desktop_flag} \ |
||||||
|
-DWITH_FONTCONVERTER=${desktop_flag} \ |
||||||
|
-DWITH_MAGNUMINFO=${windowless_flag} |
||||||
|
|
||||||
|
make clean |
||||||
|
scan-build --use-c++=$(which clang++) make -j |
||||||
|
make install |
||||||
|
]]> |
||||||
|
</command> |
||||||
|
</hudson.tasks.Shell> |
||||||
|
</builders> |
||||||
|
<publishers> |
||||||
|
<hudson.plugins.textfinder.TextFinderPublisher plugin="text-finder@1.9"> |
||||||
|
<regexp>scan-build: \d+ bugs found</regexp> |
||||||
|
<succeedIfFound>false</succeedIfFound> |
||||||
|
<unstableIfFound>true</unstableIfFound> |
||||||
|
<alsoCheckConsoleOutput>true</alsoCheckConsoleOutput> |
||||||
|
</hudson.plugins.textfinder.TextFinderPublisher> |
||||||
|
</publishers> |
||||||
|
<buildWrappers/> |
||||||
|
<executionStrategy class="hudson.matrix.DefaultMatrixExecutionStrategyImpl"> |
||||||
|
<runSequentially>true</runSequentially> |
||||||
|
<touchStoneCombinationFilter> |
||||||
|
<![CDATA[ |
||||||
|
compatibility == "deprecated" && gl == "desktop" |
||||||
|
]]> |
||||||
|
</touchStoneCombinationFilter> |
||||||
|
<touchStoneResultCondition> |
||||||
|
<name>UNSTABLE</name> |
||||||
|
<ordinal>1</ordinal> |
||||||
|
<color>YELLOW</color> |
||||||
|
<completeBuild>true</completeBuild> |
||||||
|
</touchStoneResultCondition> |
||||||
|
</executionStrategy> |
||||||
|
<childCustomWorkspace>.</childCustomWorkspace> |
||||||
|
</matrix-project> |
||||||
@ -0,0 +1,103 @@ |
|||||||
|
<?xml version='1.0' encoding='UTF-8'?> |
||||||
|
<matrix-project> |
||||||
|
<actions/> |
||||||
|
<description></description> |
||||||
|
<logRotator class="hudson.tasks.LogRotator"> |
||||||
|
<daysToKeep>-1</daysToKeep> |
||||||
|
<numToKeep>10</numToKeep> |
||||||
|
<artifactDaysToKeep>-1</artifactDaysToKeep> |
||||||
|
<artifactNumToKeep>-1</artifactNumToKeep> |
||||||
|
</logRotator> |
||||||
|
<keepDependencies>false</keepDependencies> |
||||||
|
<properties/> |
||||||
|
<scm class="hudson.plugins.git.GitSCM" plugin="git@2.0"> |
||||||
|
<configVersion>2</configVersion> |
||||||
|
<userRemoteConfigs> |
||||||
|
<hudson.plugins.git.UserRemoteConfig> |
||||||
|
<url>git://github.com/mosra/magnum.git</url> |
||||||
|
</hudson.plugins.git.UserRemoteConfig> |
||||||
|
</userRemoteConfigs> |
||||||
|
<branches> |
||||||
|
<hudson.plugins.git.BranchSpec> |
||||||
|
<name>*/master</name> |
||||||
|
</hudson.plugins.git.BranchSpec> |
||||||
|
</branches> |
||||||
|
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations> |
||||||
|
<submoduleCfg class="list"/> |
||||||
|
<extensions> |
||||||
|
<hudson.plugins.git.extensions.impl.CloneOption> |
||||||
|
<shallow>true</shallow> |
||||||
|
<reference></reference> |
||||||
|
</hudson.plugins.git.extensions.impl.CloneOption> |
||||||
|
</extensions> |
||||||
|
</scm> |
||||||
|
<canRoam>true</canRoam> |
||||||
|
<disabled>false</disabled> |
||||||
|
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> |
||||||
|
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> |
||||||
|
<triggers/> |
||||||
|
<concurrentBuild>false</concurrentBuild> |
||||||
|
<customWorkspace>Magnum</customWorkspace> |
||||||
|
<axes> |
||||||
|
<hudson.matrix.TextAxis> |
||||||
|
<name>gl</name> |
||||||
|
<values> |
||||||
|
<string>desktop</string> |
||||||
|
<string>es2desktop</string> |
||||||
|
<string>es3desktop</string> |
||||||
|
</values> |
||||||
|
</hudson.matrix.TextAxis> |
||||||
|
<hudson.matrix.TextAxis> |
||||||
|
<name>compatibility</name> |
||||||
|
<values> |
||||||
|
<string></string> |
||||||
|
<string>deprecated</string> |
||||||
|
</values> |
||||||
|
</hudson.matrix.TextAxis> |
||||||
|
<hudson.matrix.TextAxis> |
||||||
|
<name>sanitizer</name> |
||||||
|
<values> |
||||||
|
<string>address</string> |
||||||
|
<!-- <string>memory</string> --> |
||||||
|
<!-- <string>undefined</string> --> |
||||||
|
</values> |
||||||
|
</hudson.matrix.TextAxis> |
||||||
|
</axes> |
||||||
|
<builders> |
||||||
|
<hudson.tasks.Shell> |
||||||
|
<command> |
||||||
|
<![CDATA[ |
||||||
|
cd build-clang-${sanitizer}sanitizer-${compatibility}-${gl} |
||||||
|
|
||||||
|
ninja |
||||||
|
|
||||||
|
ctest --output-on-failure -R GLTest -j5 || true |
||||||
|
]]> |
||||||
|
</command> |
||||||
|
</hudson.tasks.Shell> |
||||||
|
</builders> |
||||||
|
<publishers> |
||||||
|
<hudson.plugins.textfinder.TextFinderPublisher plugin="text-finder@1.9"> |
||||||
|
<regexp>Errors while running CTest</regexp> |
||||||
|
<succeedIfFound>false</succeedIfFound> |
||||||
|
<unstableIfFound>true</unstableIfFound> |
||||||
|
<alsoCheckConsoleOutput>true</alsoCheckConsoleOutput> |
||||||
|
</hudson.plugins.textfinder.TextFinderPublisher> |
||||||
|
</publishers> |
||||||
|
<buildWrappers/> |
||||||
|
<executionStrategy class="hudson.matrix.DefaultMatrixExecutionStrategyImpl"> |
||||||
|
<runSequentially>true</runSequentially> |
||||||
|
<touchStoneCombinationFilter> |
||||||
|
<![CDATA[ |
||||||
|
compatibility == "deprecated" && gl == "desktop" && sanitizer == "address" |
||||||
|
]]> |
||||||
|
</touchStoneCombinationFilter> |
||||||
|
<touchStoneResultCondition> |
||||||
|
<name>SUCCESS</name> |
||||||
|
<ordinal>0</ordinal> |
||||||
|
<color>BLUE</color> |
||||||
|
<completeBuild>true</completeBuild> |
||||||
|
</touchStoneResultCondition> |
||||||
|
</executionStrategy> |
||||||
|
<childCustomWorkspace>.</childCustomWorkspace> |
||||||
|
</matrix-project> |
||||||
@ -0,0 +1,176 @@ |
|||||||
|
<?xml version='1.0' encoding='UTF-8'?> |
||||||
|
<matrix-project> |
||||||
|
<actions/> |
||||||
|
<description></description> |
||||||
|
<logRotator class="hudson.tasks.LogRotator"> |
||||||
|
<daysToKeep>-1</daysToKeep> |
||||||
|
<numToKeep>10</numToKeep> |
||||||
|
<artifactDaysToKeep>-1</artifactDaysToKeep> |
||||||
|
<artifactNumToKeep>-1</artifactNumToKeep> |
||||||
|
</logRotator> |
||||||
|
<keepDependencies>false</keepDependencies> |
||||||
|
<properties/> |
||||||
|
<scm class="hudson.plugins.git.GitSCM" plugin="git@2.0"> |
||||||
|
<configVersion>2</configVersion> |
||||||
|
<userRemoteConfigs> |
||||||
|
<hudson.plugins.git.UserRemoteConfig> |
||||||
|
<url>git://github.com/mosra/magnum.git</url> |
||||||
|
</hudson.plugins.git.UserRemoteConfig> |
||||||
|
</userRemoteConfigs> |
||||||
|
<branches> |
||||||
|
<hudson.plugins.git.BranchSpec> |
||||||
|
<name>*/master</name> |
||||||
|
</hudson.plugins.git.BranchSpec> |
||||||
|
</branches> |
||||||
|
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations> |
||||||
|
<submoduleCfg class="list"/> |
||||||
|
<extensions> |
||||||
|
<hudson.plugins.git.extensions.impl.CloneOption> |
||||||
|
<shallow>true</shallow> |
||||||
|
<reference></reference> |
||||||
|
</hudson.plugins.git.extensions.impl.CloneOption> |
||||||
|
</extensions> |
||||||
|
</scm> |
||||||
|
<canRoam>true</canRoam> |
||||||
|
<disabled>false</disabled> |
||||||
|
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> |
||||||
|
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> |
||||||
|
<triggers/> |
||||||
|
<concurrentBuild>false</concurrentBuild> |
||||||
|
<customWorkspace>Magnum</customWorkspace> |
||||||
|
<axes> |
||||||
|
<hudson.matrix.TextAxis> |
||||||
|
<name>gl</name> |
||||||
|
<values> |
||||||
|
<string>desktop</string> |
||||||
|
<string>es2</string> |
||||||
|
<string>es2desktop</string> |
||||||
|
<string>es3</string> |
||||||
|
<string>es3desktop</string> |
||||||
|
</values> |
||||||
|
</hudson.matrix.TextAxis> |
||||||
|
<hudson.matrix.TextAxis> |
||||||
|
<name>compatibility</name> |
||||||
|
<values> |
||||||
|
<string></string> |
||||||
|
<string>deprecated</string> |
||||||
|
</values> |
||||||
|
</hudson.matrix.TextAxis> |
||||||
|
<hudson.matrix.TextAxis> |
||||||
|
<name>sanitizer</name> |
||||||
|
<values> |
||||||
|
<string>address</string> |
||||||
|
<!-- <string>memory</string> --> |
||||||
|
<!-- <string>undefined</string> --> |
||||||
|
</values> |
||||||
|
</hudson.matrix.TextAxis> |
||||||
|
</axes> |
||||||
|
<builders> |
||||||
|
<hudson.tasks.Shell> |
||||||
|
<command> |
||||||
|
<![CDATA[ |
||||||
|
if [ "${compatibility}" = "deprecated" ] ; then |
||||||
|
deprecated_build_flag=ON |
||||||
|
else |
||||||
|
deprecated_build_flag=OFF |
||||||
|
fi |
||||||
|
|
||||||
|
if [ ${gl} = "desktop" ] ; then |
||||||
|
desktop_flag=ON |
||||||
|
es_flag=OFF |
||||||
|
windowless_flag=ON |
||||||
|
elif [ ${gl} = "es2" ] ; then |
||||||
|
gl_flags="-DTARGET_GLES=ON -DTARGET_GLES2=ON" |
||||||
|
desktop_flag=OFF |
||||||
|
es_flag=ON |
||||||
|
windowless_flag=OFF |
||||||
|
elif [ ${gl} = "es2desktop" ] ; then |
||||||
|
gl_flags="-DTARGET_GLES=ON -DTARGET_GLES2=ON -DTARGET_DESKTOP_GLES=ON" |
||||||
|
desktop_flag=OFF |
||||||
|
es_flag=OFF |
||||||
|
windowless_flag=ON |
||||||
|
elif [ ${gl} = "es3" ] ; then |
||||||
|
gl_flags="-DTARGET_GLES=ON -DTARGET_GLES2=OFF" |
||||||
|
desktop_flag=OFF |
||||||
|
es_flag=ON |
||||||
|
windowless_flag=OFF |
||||||
|
elif [ ${gl} = "es3desktop" ] ; then |
||||||
|
gl_flags="-DTARGET_GLES=ON -DTARGET_GLES2=OFF -DTARGET_DESKTOP_GLES=ON" |
||||||
|
desktop_flag=OFF |
||||||
|
es_flag=OFF |
||||||
|
windowless_flag=ON |
||||||
|
fi |
||||||
|
|
||||||
|
mkdir -p build-clang-${sanitizer}sanitizer-${compatibility}-${gl} |
||||||
|
cd build-clang-${sanitizer}sanitizer-${compatibility}-${gl} |
||||||
|
|
||||||
|
cmake .. \ |
||||||
|
-DCMAKE_BUILD_TYPE=Debug \ |
||||||
|
-DCMAKE_FIND_ROOT_PATH=${JENKINS_HOME}/filesystem/clang-${sanitizer}sanitizer-${compatibility} \ |
||||||
|
-DCMAKE_INSTALL_PREFIX=${JENKINS_HOME}/filesystem/clang-${sanitizer}sanitizer-${compatibility}-${gl} \ |
||||||
|
-DCMAKE_INSTALL_RPATH="${JENKINS_HOME}/filesystem/clang-${sanitizer}sanitizer-${compatibility}/lib;${JENKINS_HOME}/filesystem/clang-${sanitizer}sanitizer-${compatibility}-${gl}/lib" \ |
||||||
|
-DCMAKE_CXX_COMPILER=clang++ \ |
||||||
|
-DCMAKE_CXX_FLAGS="-std=c++11 -fsanitize=${sanitizer}" \ |
||||||
|
-DBUILD_TESTS=ON \ |
||||||
|
-DBUILD_GL_TESTS=${windowless_flag} \ |
||||||
|
-DBUILD_DEPRECATED=${deprecated_build_flag} \ |
||||||
|
${gl_flags} \ |
||||||
|
-DWITH_AUDIO=ON \ |
||||||
|
-DWITH_GLUTAPPLICATION=ON \ |
||||||
|
-DWITH_GLXAPPLICATION=ON \ |
||||||
|
-DWITH_SDL2APPLICATION=ON \ |
||||||
|
-DWITH_XEGLAPPLICATION=ON \ |
||||||
|
-DWITH_EGLCONTEXT=ON \ |
||||||
|
-DWITH_GLXCONTEXT=ON \ |
||||||
|
-DWITH_MAGNUMFONT=ON \ |
||||||
|
-DWITH_MAGNUMFONTCONVERTER=${desktop_flag} \ |
||||||
|
-DWITH_OBJIMPORTER=ON \ |
||||||
|
-DWITH_TGAIMAGECONVERTER=ON \ |
||||||
|
-DWITH_TGAIMPORTER=ON \ |
||||||
|
-DWITH_WAVAUDIOIMPORTER=ON \ |
||||||
|
-DWITH_DISTANCEFIELDCONVERTER=${desktop_flag} \ |
||||||
|
-DWITH_FONTCONVERTER=${desktop_flag} \ |
||||||
|
-DWITH_MAGNUMINFO=${windowless_flag} \ |
||||||
|
-G Ninja |
||||||
|
|
||||||
|
ninja |
||||||
|
ctest --output-on-failure -E GLTest -j5 || true |
||||||
|
ninja install |
||||||
|
]]> |
||||||
|
</command> |
||||||
|
</hudson.tasks.Shell> |
||||||
|
</builders> |
||||||
|
<publishers> |
||||||
|
<hudson.tasks.BuildTrigger> |
||||||
|
<childProjects>Magnum-ClangSanitizer-GLTests</childProjects> |
||||||
|
<threshold> |
||||||
|
<name>SUCCESS</name> |
||||||
|
<ordinal>0</ordinal> |
||||||
|
<color>BLUE</color> |
||||||
|
<completeBuild>true</completeBuild> |
||||||
|
</threshold> |
||||||
|
</hudson.tasks.BuildTrigger> |
||||||
|
<hudson.plugins.textfinder.TextFinderPublisher plugin="text-finder@1.9"> |
||||||
|
<regexp>Errors while running CTest</regexp> |
||||||
|
<succeedIfFound>false</succeedIfFound> |
||||||
|
<unstableIfFound>true</unstableIfFound> |
||||||
|
<alsoCheckConsoleOutput>true</alsoCheckConsoleOutput> |
||||||
|
</hudson.plugins.textfinder.TextFinderPublisher> |
||||||
|
</publishers> |
||||||
|
<buildWrappers/> |
||||||
|
<executionStrategy class="hudson.matrix.DefaultMatrixExecutionStrategyImpl"> |
||||||
|
<runSequentially>true</runSequentially> |
||||||
|
<touchStoneCombinationFilter> |
||||||
|
<![CDATA[ |
||||||
|
compatibility == "deprecated" && gl == "desktop" && sanitizer == "address" |
||||||
|
]]> |
||||||
|
</touchStoneCombinationFilter> |
||||||
|
<touchStoneResultCondition> |
||||||
|
<name>UNSTABLE</name> |
||||||
|
<ordinal>1</ordinal> |
||||||
|
<color>YELLOW</color> |
||||||
|
<completeBuild>true</completeBuild> |
||||||
|
</touchStoneResultCondition> |
||||||
|
</executionStrategy> |
||||||
|
<childCustomWorkspace>.</childCustomWorkspace> |
||||||
|
</matrix-project> |
||||||
@ -0,0 +1,329 @@ |
|||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015 |
||||||
|
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 "Attribute.h" |
||||||
|
|
||||||
|
#include <Corrade/Utility/Assert.h> |
||||||
|
|
||||||
|
namespace Magnum { namespace Implementation { |
||||||
|
|
||||||
|
UnsignedInt FloatAttribute::size(GLint components, DataType dataType) { |
||||||
|
switch(dataType) { |
||||||
|
case DataType::UnsignedByte: |
||||||
|
case DataType::Byte: |
||||||
|
return components; |
||||||
|
case DataType::UnsignedShort: |
||||||
|
case DataType::Short: |
||||||
|
case DataType::HalfFloat: |
||||||
|
return 2*components; |
||||||
|
case DataType::UnsignedInt: |
||||||
|
case DataType::Int: |
||||||
|
case DataType::Float: |
||||||
|
return 4*components; |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
case DataType::Double: |
||||||
|
return 8*components; |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
CORRADE_ASSERT_UNREACHABLE(); |
||||||
|
} |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
UnsignedInt IntAttribute::size(GLint components, DataType dataType) { |
||||||
|
switch(dataType) { |
||||||
|
case DataType::UnsignedByte: |
||||||
|
case DataType::Byte: |
||||||
|
return components; |
||||||
|
case DataType::UnsignedShort: |
||||||
|
case DataType::Short: |
||||||
|
return 2*components; |
||||||
|
case DataType::UnsignedInt: |
||||||
|
case DataType::Int: |
||||||
|
return 4*components; |
||||||
|
} |
||||||
|
|
||||||
|
CORRADE_ASSERT_UNREACHABLE(); |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
UnsignedInt DoubleAttribute::size(GLint components, DataType dataType) { |
||||||
|
switch(dataType) { |
||||||
|
case DataType::Double: |
||||||
|
return 8*components; |
||||||
|
} |
||||||
|
|
||||||
|
CORRADE_ASSERT_UNREACHABLE(); |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
UnsignedInt Attribute<Math::Vector<3, Float>>::size(GLint components, DataType dataType) { |
||||||
|
switch(dataType) { |
||||||
|
case DataType::UnsignedByte: |
||||||
|
case DataType::Byte: |
||||||
|
return components; |
||||||
|
case DataType::UnsignedShort: |
||||||
|
case DataType::Short: |
||||||
|
case DataType::HalfFloat: |
||||||
|
return 2*components; |
||||||
|
case DataType::UnsignedInt: |
||||||
|
case DataType::Int: |
||||||
|
case DataType::Float: |
||||||
|
return 4*components; |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
case DataType::Double: |
||||||
|
return 8*components; |
||||||
|
case DataType::UnsignedInt10f11f11fRev: |
||||||
|
CORRADE_INTERNAL_ASSERT(components == 3); |
||||||
|
return 4; |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
CORRADE_ASSERT_UNREACHABLE(); |
||||||
|
} |
||||||
|
|
||||||
|
UnsignedInt Attribute<Math::Vector<4, Float>>::size(GLint components, DataType dataType) { |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
if(components == GL_BGRA) components = 4; |
||||||
|
#endif |
||||||
|
|
||||||
|
switch(dataType) { |
||||||
|
case DataType::UnsignedByte: |
||||||
|
case DataType::Byte: |
||||||
|
return components; |
||||||
|
case DataType::UnsignedShort: |
||||||
|
case DataType::Short: |
||||||
|
case DataType::HalfFloat: |
||||||
|
return 2*components; |
||||||
|
case DataType::UnsignedInt: |
||||||
|
case DataType::Int: |
||||||
|
case DataType::Float: |
||||||
|
return 4*components; |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
case DataType::Double: |
||||||
|
return 8*components; |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
case DataType::UnsignedInt2101010Rev: |
||||||
|
case DataType::Int2101010Rev: |
||||||
|
CORRADE_INTERNAL_ASSERT(components == 4); |
||||||
|
return 4; |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
CORRADE_ASSERT_UNREACHABLE(); |
||||||
|
} |
||||||
|
|
||||||
|
Debug operator<<(Debug debug, SizedAttribute<1, 1>::Components value) { |
||||||
|
switch(value) { |
||||||
|
case SizedAttribute<1, 1>::Components::One: |
||||||
|
return debug << "Attribute::Components::One"; |
||||||
|
} |
||||||
|
|
||||||
|
return debug << "Attribute::Components::(invalid)"; |
||||||
|
} |
||||||
|
|
||||||
|
Debug operator<<(Debug debug, SizedAttribute<1, 2>::Components value) { |
||||||
|
switch(value) { |
||||||
|
case SizedAttribute<1, 2>::Components::One: |
||||||
|
return debug << "Attribute::Components::One"; |
||||||
|
case SizedAttribute<1, 2>::Components::Two: |
||||||
|
return debug << "Attribute::Components::Two"; |
||||||
|
} |
||||||
|
|
||||||
|
return debug << "Attribute::Components::(invalid)"; |
||||||
|
} |
||||||
|
|
||||||
|
Debug operator<<(Debug debug, SizedAttribute<1, 3>::Components value) { |
||||||
|
switch(value) { |
||||||
|
case SizedAttribute<1, 3>::Components::One: |
||||||
|
return debug << "Attribute::Components::One"; |
||||||
|
case SizedAttribute<1, 3>::Components::Two: |
||||||
|
return debug << "Attribute::Components::Two"; |
||||||
|
case SizedAttribute<1, 3>::Components::Three: |
||||||
|
return debug << "Attribute::Components::Three"; |
||||||
|
} |
||||||
|
|
||||||
|
return debug << "Attribute::Components::(invalid)"; |
||||||
|
} |
||||||
|
|
||||||
|
Debug operator<<(Debug debug, SizedAttribute<1, 4>::Components value) { |
||||||
|
switch(value) { |
||||||
|
case SizedAttribute<1, 4>::Components::One: |
||||||
|
return debug << "Attribute::Components::One"; |
||||||
|
case SizedAttribute<1, 4>::Components::Two: |
||||||
|
return debug << "Attribute::Components::Two"; |
||||||
|
case SizedAttribute<1, 4>::Components::Three: |
||||||
|
return debug << "Attribute::Components::Three"; |
||||||
|
case SizedAttribute<1, 4>::Components::Four: |
||||||
|
return debug << "Attribute::Components::Four"; |
||||||
|
} |
||||||
|
|
||||||
|
return debug << "Attribute::Components::(invalid)"; |
||||||
|
} |
||||||
|
|
||||||
|
Debug operator<<(Debug debug, SizedMatrixAttribute<2>::Components value) { |
||||||
|
switch(value) { |
||||||
|
case SizedMatrixAttribute<2>::Components::Two: |
||||||
|
return debug << "Attribute::Components::Two"; |
||||||
|
} |
||||||
|
|
||||||
|
return debug << "Attribute::Components::(invalid)"; |
||||||
|
} |
||||||
|
|
||||||
|
Debug operator<<(Debug debug, SizedMatrixAttribute<3>::Components value) { |
||||||
|
switch(value) { |
||||||
|
case SizedMatrixAttribute<3>::Components::Three: |
||||||
|
return debug << "Attribute::Components::Three"; |
||||||
|
} |
||||||
|
|
||||||
|
return debug << "Attribute::Components::(invalid)"; |
||||||
|
} |
||||||
|
|
||||||
|
Debug operator<<(Debug debug, SizedMatrixAttribute<4>::Components value) { |
||||||
|
switch(value) { |
||||||
|
case SizedMatrixAttribute<4>::Components::Four: |
||||||
|
return debug << "Attribute::Components::Four"; |
||||||
|
} |
||||||
|
|
||||||
|
return debug << "Attribute::Components::(invalid)"; |
||||||
|
} |
||||||
|
|
||||||
|
Debug operator<<(Debug debug, Attribute<Math::Vector<4, Float>>::Components value) { |
||||||
|
switch(value) { |
||||||
|
case Attribute<Math::Vector<4, Float>>::Components::One: |
||||||
|
return debug << "Attribute::Components::One"; |
||||||
|
case Attribute<Math::Vector<4, Float>>::Components::Two: |
||||||
|
return debug << "Attribute::Components::Two"; |
||||||
|
case Attribute<Math::Vector<4, Float>>::Components::Three: |
||||||
|
return debug << "Attribute::Components::Three"; |
||||||
|
case Attribute<Math::Vector<4, Float>>::Components::Four: |
||||||
|
return debug << "Attribute::Components::Four"; |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
case Attribute<Math::Vector<4, Float>>::Components::BGRA: |
||||||
|
return debug << "Attribute::Components::BGRA"; |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
return debug << "Attribute::Components::(invalid)"; |
||||||
|
} |
||||||
|
|
||||||
|
Debug operator<<(Debug debug, FloatAttribute::DataType value) { |
||||||
|
switch(value) { |
||||||
|
#define _c(value) case FloatAttribute::DataType::value: return debug << "Attribute::DataType::" #value; |
||||||
|
_c(UnsignedByte) |
||||||
|
_c(Byte) |
||||||
|
_c(UnsignedShort) |
||||||
|
_c(Short) |
||||||
|
_c(UnsignedInt) |
||||||
|
_c(Int) |
||||||
|
_c(HalfFloat) |
||||||
|
_c(Float) |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
_c(Double) |
||||||
|
#endif |
||||||
|
#undef _c |
||||||
|
} |
||||||
|
|
||||||
|
return debug << "Attribute::DataType::(invalid)"; |
||||||
|
} |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
Debug operator<<(Debug debug, IntAttribute::DataType value) { |
||||||
|
switch(value) { |
||||||
|
#define _c(value) case IntAttribute::DataType::value: return debug << "Attribute::DataType::" #value; |
||||||
|
_c(UnsignedByte) |
||||||
|
_c(Byte) |
||||||
|
_c(UnsignedShort) |
||||||
|
_c(Short) |
||||||
|
_c(UnsignedInt) |
||||||
|
_c(Int) |
||||||
|
#undef _c |
||||||
|
} |
||||||
|
|
||||||
|
return debug << "Attribute::DataType::(invalid)"; |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
Debug operator<<(Debug debug, DoubleAttribute::DataType value) { |
||||||
|
switch(value) { |
||||||
|
#define _c(value) case DoubleAttribute::DataType::value: return debug << "Attribute::DataType::" #value; |
||||||
|
_c(Double) |
||||||
|
#undef _c |
||||||
|
} |
||||||
|
|
||||||
|
return debug << "Attribute::DataType::(invalid)"; |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
Debug operator<<(Debug debug, Attribute<Math::Vector<3, Float>>::DataType value) { |
||||||
|
switch(value) { |
||||||
|
#define _c(value) case Attribute<Math::Vector<3, Float>>::DataType::value: return debug << "Attribute::DataType::" #value; |
||||||
|
_c(UnsignedByte) |
||||||
|
_c(Byte) |
||||||
|
_c(UnsignedShort) |
||||||
|
_c(Short) |
||||||
|
_c(UnsignedInt) |
||||||
|
_c(Int) |
||||||
|
_c(HalfFloat) |
||||||
|
_c(Float) |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
_c(Double) |
||||||
|
_c(UnsignedInt10f11f11fRev) |
||||||
|
#endif |
||||||
|
#undef _c |
||||||
|
} |
||||||
|
|
||||||
|
return debug << "Attribute::DataType::(invalid)"; |
||||||
|
} |
||||||
|
|
||||||
|
Debug operator<<(Debug debug, Attribute<Math::Vector<4, Float>>::DataType value) { |
||||||
|
switch(value) { |
||||||
|
#define _c(value) case Attribute<Math::Vector<4, Float>>::DataType::value: return debug << "Attribute::DataType::" #value; |
||||||
|
_c(UnsignedByte) |
||||||
|
_c(Byte) |
||||||
|
_c(UnsignedShort) |
||||||
|
_c(Short) |
||||||
|
_c(UnsignedInt) |
||||||
|
_c(Int) |
||||||
|
_c(HalfFloat) |
||||||
|
_c(Float) |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
_c(Double) |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
_c(UnsignedInt2101010Rev) |
||||||
|
_c(Int2101010Rev) |
||||||
|
#endif |
||||||
|
#undef _c |
||||||
|
} |
||||||
|
|
||||||
|
return debug << "Attribute::DataType::(invalid)"; |
||||||
|
} |
||||||
|
|
||||||
|
}} |
||||||
@ -0,0 +1,657 @@ |
|||||||
|
#ifndef Magnum_Attribute_h |
||||||
|
#define Magnum_Attribute_h |
||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015 |
||||||
|
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. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** @file
|
||||||
|
* @brief Class @ref Magnum::Attribute |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <Corrade/Containers/EnumSet.h> |
||||||
|
|
||||||
|
#include "Magnum/Magnum.h" |
||||||
|
#include "Magnum/OpenGL.h" |
||||||
|
#include "Magnum/visibility.h" |
||||||
|
|
||||||
|
namespace Magnum { |
||||||
|
|
||||||
|
namespace Implementation { template<class> struct Attribute; } |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Base class for attribute location and type |
||||||
|
|
||||||
|
For use in @ref AbstractShaderProgram subclasses. Template parameter @p location |
||||||
|
is vertex attribute location, number between `0` and |
||||||
|
@ref AbstractShaderProgram::maxVertexAttributes(). To ensure compatibility, you |
||||||
|
should always have vertex attribute with location `0`. |
||||||
|
|
||||||
|
Template parameter @p T is the type which is used for shader attribute, e.g. |
||||||
|
@ref Vector4i for `ivec4`. DataType is type of passed data when adding vertex |
||||||
|
buffers to mesh. By default it is the same as type used in shader (e.g. |
||||||
|
@ref DataType::Int for @ref Vector4i). It's also possible to pass integer data |
||||||
|
to floating-point shader inputs. In this case you may want to normalize the |
||||||
|
values (e.g. color components from 0-255 to 0.0f - 1.0f) -- see |
||||||
|
@ref DataOption::Normalized. |
||||||
|
|
||||||
|
Only some types are allowed as attribute types, see @ref AbstractShaderProgram-types |
||||||
|
for more information. |
||||||
|
|
||||||
|
See @ref AbstractShaderProgram-subclassing for example usage in shaders and |
||||||
|
@ref Mesh-configuration for example usage when adding vertex buffers to mesh. |
||||||
|
*/ |
||||||
|
template<UnsignedInt location, class T> class Attribute { |
||||||
|
public: |
||||||
|
enum: UnsignedInt { |
||||||
|
/**
|
||||||
|
* Location to which the attribute is bound |
||||||
|
* |
||||||
|
* @see @ref AbstractShaderProgram::maxVertexAttributes() |
||||||
|
*/ |
||||||
|
Location = location, |
||||||
|
|
||||||
|
/**
|
||||||
|
* Count of vectors in this type |
||||||
|
* |
||||||
|
* @see @ref vectorSize() |
||||||
|
*/ |
||||||
|
VectorCount = Implementation::Attribute<T>::VectorCount |
||||||
|
}; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Type |
||||||
|
* |
||||||
|
* Type used in shader code. |
||||||
|
* @see @ref ScalarType, @ref DataType |
||||||
|
*/ |
||||||
|
typedef T Type; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Scalar type |
||||||
|
* |
||||||
|
* The underlying scalar type of the attribute. |
||||||
|
* @see @ref Type, @ref DataType |
||||||
|
*/ |
||||||
|
typedef typename Implementation::Attribute<T>::ScalarType ScalarType; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Component count |
||||||
|
* |
||||||
|
* Count of components passed to the shader. If passing smaller count |
||||||
|
* of components than corresponding type has, unspecified components |
||||||
|
* are set to default values (second and third to `0`, fourth to `1`). |
||||||
|
*/ |
||||||
|
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||||
|
enum class Components: GLint { |
||||||
|
/**
|
||||||
|
* Only first component is specified. Second, third and fourth |
||||||
|
* component are set to `0`, `0`, `1`, respectively. Only for |
||||||
|
* scalar and vector types, not matrices. |
||||||
|
*/ |
||||||
|
One = 1, |
||||||
|
|
||||||
|
/**
|
||||||
|
* First two components are specified. Third and fourth component |
||||||
|
* are set to `0`, `1`, respectively. Only for two, three and |
||||||
|
* four-component vector types and 2x2, 3x2 and 4x2 matrix types. |
||||||
|
*/ |
||||||
|
Two = 2, |
||||||
|
|
||||||
|
/**
|
||||||
|
* First three components are specified. Fourth component is set to |
||||||
|
* `1`. Only for three and four-component vector types, 2x3, 3x3 |
||||||
|
* and 4x3 matrix types. |
||||||
|
*/ |
||||||
|
Three = 3, |
||||||
|
|
||||||
|
/**
|
||||||
|
* All four components are specified. Only for four-component |
||||||
|
* vector types and 2x4, 3x4 and 4x4 matrix types. |
||||||
|
*/ |
||||||
|
Four = 4, |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
/**
|
||||||
|
* Four components with BGRA ordering. Only for four-component |
||||||
|
* float vector type. Must be used along with @ref DataType::UnsignedByte |
||||||
|
* and @ref DataOption::Normalized. |
||||||
|
* @requires_gl32 Extension @extension{ARB,vertex_array_bgra} |
||||||
|
* @requires_gl Only RGBA component ordering is supported in OpenGL |
||||||
|
* ES. |
||||||
|
*/ |
||||||
|
BGRA = GL_BGRA |
||||||
|
#endif |
||||||
|
}; |
||||||
|
#else |
||||||
|
typedef typename Implementation::Attribute<T>::Components Components; |
||||||
|
#endif |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Data type |
||||||
|
* |
||||||
|
* Type of data passed to shader. |
||||||
|
* @see @ref Type, @ref DataOptions, @ref Attribute() |
||||||
|
*/ |
||||||
|
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||||
|
enum class DataType: GLenum { |
||||||
|
UnsignedByte = GL_UNSIGNED_BYTE, /**< Unsigned byte */ |
||||||
|
Byte = GL_BYTE, /**< Byte */ |
||||||
|
UnsignedShort = GL_UNSIGNED_SHORT, /**< Unsigned short */ |
||||||
|
Short = GL_SHORT, /**< Short */ |
||||||
|
UnsignedInt = GL_UNSIGNED_INT, /**< Unsigned int */ |
||||||
|
Int = GL_INT, /**< Int */ |
||||||
|
|
||||||
|
/**
|
||||||
|
* Half float. Only for float attribute types. |
||||||
|
* @requires_gl30 Extension @extension{ARB,half_float_vertex} |
||||||
|
* @requires_gles30 Extension @es_extension{OES,vertex_half_float} |
||||||
|
* in OpenGL ES 2.0 |
||||||
|
*/ |
||||||
|
HalfFloat = GL_HALF_FLOAT, |
||||||
|
|
||||||
|
/** Float. Only for float attribute types. */ |
||||||
|
Float = GL_FLOAT, |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
/**
|
||||||
|
* Double. Only for float and double attribute types. |
||||||
|
* @requires_gl Only floats are available in OpenGL ES. |
||||||
|
*/ |
||||||
|
Double = GL_DOUBLE, |
||||||
|
|
||||||
|
/**
|
||||||
|
* Unsigned 10.11.11 packed float. Only for three-component float |
||||||
|
* vector attribute type. |
||||||
|
* @requires_gl44 Extension @extension{ARB,vertex_type_10f_11f_11f_rev} |
||||||
|
* @requires_gl Packed float attributes are not available in OpenGL |
||||||
|
* ES. |
||||||
|
*/ |
||||||
|
UnsignedInt10f11f11fRev = GL_UNSIGNED_INT_10F_11F_11F_REV, |
||||||
|
#endif |
||||||
|
|
||||||
|
/* GL_FIXED not supported */ |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
/**
|
||||||
|
* Unsigned 2.10.10.10 packed integer. Only for four-component |
||||||
|
* float vector attribute type. |
||||||
|
* @todo How about (incompatible) @es_extension{OES,vertex_type_10_10_10_2}? |
||||||
|
* @requires_gl33 Extension @extension{ARB,vertex_type_2_10_10_10_rev} |
||||||
|
* @requires_gles30 Packed attributes are not available in OpenGL |
||||||
|
* ES 2.0 |
||||||
|
*/ |
||||||
|
UnsignedInt2101010Rev = GL_UNSIGNED_INT_2_10_10_10_REV, |
||||||
|
|
||||||
|
/**
|
||||||
|
* Signed 2.10.10.10 packed integer. Only for four-component float |
||||||
|
* vector attribute type. |
||||||
|
* @requires_gl33 Extension @extension{ARB,vertex_type_2_10_10_10_rev} |
||||||
|
* @requires_gles30 Packed attributes are not available in OpenGL |
||||||
|
* ES 2.0 |
||||||
|
*/ |
||||||
|
Int2101010Rev = GL_INT_2_10_10_10_REV |
||||||
|
#endif |
||||||
|
}; |
||||||
|
#else |
||||||
|
typedef typename Implementation::Attribute<T>::DataType DataType; |
||||||
|
#endif |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Data option |
||||||
|
* @see @ref DataOptions, @ref Attribute() |
||||||
|
*/ |
||||||
|
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||||
|
enum class DataOption: UnsignedByte { |
||||||
|
/**
|
||||||
|
* Normalize integer components. Only for float attribute types. |
||||||
|
* Default is to not normalize. |
||||||
|
*/ |
||||||
|
Normalized = 1 << 0 |
||||||
|
}; |
||||||
|
#else |
||||||
|
typedef typename Implementation::Attribute<T>::DataOption DataOption; |
||||||
|
#endif |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Data options |
||||||
|
* @see @ref Attribute() |
||||||
|
*/ |
||||||
|
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||||
|
typedef typename Containers::EnumSet<DataOption> DataOptions; |
||||||
|
#else |
||||||
|
typedef typename Implementation::Attribute<T>::DataOptions DataOptions; |
||||||
|
#endif |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructor |
||||||
|
* @param components Component count |
||||||
|
* @param dataType Type of passed data. Default is the same as |
||||||
|
* type used in shader (e.g. @ref DataType::Int for @ref Vector4i). |
||||||
|
* @param dataOptions Data options. Default is no options. |
||||||
|
*/ |
||||||
|
constexpr Attribute(Components components, DataType dataType = Implementation::Attribute<T>::DefaultDataType, DataOptions dataOptions = DataOptions()): _components(components), _dataType(dataType), _dataOptions(dataOptions) {} |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructor |
||||||
|
* @param dataType Type of passed data. Default is the same as |
||||||
|
* type used in shader (e.g. @ref DataType::Int for @ref Vector4i). |
||||||
|
* @param dataOptions Data options. Default is no options. |
||||||
|
* |
||||||
|
* Component count is set to the same value as in type used in shader |
||||||
|
* (e.g. @ref Components::Three for @ref Vector3). |
||||||
|
*/ |
||||||
|
constexpr Attribute(DataType dataType = Implementation::Attribute<T>::DefaultDataType, DataOptions dataOptions = DataOptions()): _components(Implementation::Attribute<T>::DefaultComponents), _dataType(dataType), _dataOptions(dataOptions) {} |
||||||
|
|
||||||
|
/** @brief Component count of passed data */ |
||||||
|
constexpr Components components() const { return _components; } |
||||||
|
|
||||||
|
/** @brief Type of passed data */ |
||||||
|
constexpr DataType dataType() const { return _dataType; } |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Size of each vector in passed data |
||||||
|
* |
||||||
|
* @see @ref VectorCount |
||||||
|
*/ |
||||||
|
UnsignedInt vectorSize() const { |
||||||
|
return Implementation::Attribute<T>::size(GLint(_components), _dataType); |
||||||
|
} |
||||||
|
|
||||||
|
/** @brief Data options */ |
||||||
|
constexpr DataOptions dataOptions() const { return _dataOptions; } |
||||||
|
|
||||||
|
private: |
||||||
|
Components _components; |
||||||
|
DataType _dataType; |
||||||
|
DataOptions _dataOptions; |
||||||
|
}; |
||||||
|
|
||||||
|
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||||
|
/** @debugoperatorclassenum{Magnum::Attribute,Magnum::Attribute::Components} */ |
||||||
|
template<class T> Debug operator<<(Debug debug, Attribute<T>::Components); |
||||||
|
|
||||||
|
/** @debugoperatorclassenum{Magnum::Attribute,Magnum::Attribute::DataType} */ |
||||||
|
template<class T> Debug operator<<(Debug debug, Attribute<T>::DataType); |
||||||
|
#endif |
||||||
|
|
||||||
|
namespace Implementation { |
||||||
|
|
||||||
|
/* Base for sized attributes */ |
||||||
|
template<std::size_t cols, std::size_t rows> struct SizedAttribute; |
||||||
|
|
||||||
|
/* Vector attribute sizes */ |
||||||
|
template<std::size_t cols> struct SizedVectorAttribute { |
||||||
|
enum: UnsignedInt { VectorCount = UnsignedInt(cols) }; |
||||||
|
}; |
||||||
|
template<> struct SizedAttribute<1, 1>: SizedVectorAttribute<1> { |
||||||
|
enum class Components: GLint { One = 1 }; |
||||||
|
#if !defined(CORRADE_GCC45_COMPATIBILITY) && !defined(CORRADE_MSVC2013_COMPATIBILITY) |
||||||
|
constexpr static |
||||||
|
#else |
||||||
|
static const |
||||||
|
#endif |
||||||
|
Components DefaultComponents = Components::One; |
||||||
|
}; |
||||||
|
template<> struct SizedAttribute<1, 2>: SizedVectorAttribute<1> { |
||||||
|
enum class Components: GLint { One = 1, Two = 2 }; |
||||||
|
#if !defined(CORRADE_GCC45_COMPATIBILITY) && !defined(CORRADE_MSVC2013_COMPATIBILITY) |
||||||
|
constexpr static |
||||||
|
#else |
||||||
|
static const |
||||||
|
#endif |
||||||
|
Components DefaultComponents = Components::Two; |
||||||
|
}; |
||||||
|
template<> struct SizedAttribute<1, 3>: SizedVectorAttribute<1> { |
||||||
|
enum class Components: GLint { One = 1, Two = 2, Three = 3 }; |
||||||
|
#if !defined(CORRADE_GCC45_COMPATIBILITY) && !defined(CORRADE_MSVC2013_COMPATIBILITY) |
||||||
|
constexpr static |
||||||
|
#else |
||||||
|
static const |
||||||
|
#endif |
||||||
|
Components DefaultComponents = Components::Three; |
||||||
|
}; |
||||||
|
template<> struct SizedAttribute<1, 4>: SizedVectorAttribute<1> { |
||||||
|
enum class Components: GLint { One = 1, Two = 2, Three = 3, Four = 4 }; |
||||||
|
#if !defined(CORRADE_GCC45_COMPATIBILITY) && !defined(CORRADE_MSVC2013_COMPATIBILITY) |
||||||
|
constexpr static |
||||||
|
#else |
||||||
|
static const |
||||||
|
#endif |
||||||
|
Components DefaultComponents = Components::Four; |
||||||
|
}; |
||||||
|
Debug MAGNUM_EXPORT operator<<(Debug debug, SizedAttribute<1, 1>::Components value); |
||||||
|
Debug MAGNUM_EXPORT operator<<(Debug debug, SizedAttribute<1, 2>::Components value); |
||||||
|
Debug MAGNUM_EXPORT operator<<(Debug debug, SizedAttribute<1, 3>::Components value); |
||||||
|
Debug MAGNUM_EXPORT operator<<(Debug debug, SizedAttribute<1, 4>::Components value); |
||||||
|
|
||||||
|
/* Matrix attribute sizes */ |
||||||
|
template<std::size_t rows> struct SizedMatrixAttribute; |
||||||
|
template<> struct SizedMatrixAttribute<2> { |
||||||
|
enum class Components: GLint { Two = 2 }; |
||||||
|
#if !defined(CORRADE_GCC45_COMPATIBILITY) && !defined(CORRADE_MSVC2013_COMPATIBILITY) |
||||||
|
constexpr static |
||||||
|
#else |
||||||
|
static const |
||||||
|
#endif |
||||||
|
Components DefaultComponents = Components::Two; |
||||||
|
}; |
||||||
|
template<> struct SizedMatrixAttribute<3> { |
||||||
|
enum class Components: GLint { Three = 3 }; |
||||||
|
#if !defined(CORRADE_GCC45_COMPATIBILITY) && !defined(CORRADE_MSVC2013_COMPATIBILITY) |
||||||
|
constexpr static |
||||||
|
#else |
||||||
|
static const |
||||||
|
#endif |
||||||
|
Components DefaultComponents = Components::Three; |
||||||
|
}; |
||||||
|
template<> struct SizedMatrixAttribute<4> { |
||||||
|
enum class Components: GLint { Four = 4 }; |
||||||
|
#if !defined(CORRADE_GCC45_COMPATIBILITY) && !defined(CORRADE_MSVC2013_COMPATIBILITY) |
||||||
|
constexpr static |
||||||
|
#else |
||||||
|
static const |
||||||
|
#endif |
||||||
|
Components DefaultComponents = Components::Four; |
||||||
|
}; |
||||||
|
Debug MAGNUM_EXPORT operator<<(Debug debug, SizedMatrixAttribute<2>::Components value); |
||||||
|
Debug MAGNUM_EXPORT operator<<(Debug debug, SizedMatrixAttribute<3>::Components value); |
||||||
|
Debug MAGNUM_EXPORT operator<<(Debug debug, SizedMatrixAttribute<4>::Components value); |
||||||
|
template<> struct SizedAttribute<2, 2>: SizedVectorAttribute<2>, SizedMatrixAttribute<2> {}; |
||||||
|
template<> struct SizedAttribute<3, 3>: SizedVectorAttribute<3>, SizedMatrixAttribute<3> {}; |
||||||
|
template<> struct SizedAttribute<4, 4>: SizedVectorAttribute<4>, SizedMatrixAttribute<4> {}; |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
template<> struct SizedAttribute<2, 3>: SizedVectorAttribute<2>, SizedMatrixAttribute<3> {}; |
||||||
|
template<> struct SizedAttribute<3, 2>: SizedVectorAttribute<3>, SizedMatrixAttribute<2> {}; |
||||||
|
template<> struct SizedAttribute<2, 4>: SizedVectorAttribute<2>, SizedMatrixAttribute<4> {}; |
||||||
|
template<> struct SizedAttribute<4, 2>: SizedVectorAttribute<4>, SizedMatrixAttribute<2> {}; |
||||||
|
template<> struct SizedAttribute<3, 4>: SizedVectorAttribute<3>, SizedMatrixAttribute<4> {}; |
||||||
|
template<> struct SizedAttribute<4, 3>: SizedVectorAttribute<4>, SizedMatrixAttribute<3> {}; |
||||||
|
#endif |
||||||
|
|
||||||
|
/* Base for attributes */ |
||||||
|
template<class> struct Attribute; |
||||||
|
|
||||||
|
/* Base for float attributes */ |
||||||
|
struct FloatAttribute { |
||||||
|
typedef Float ScalarType; |
||||||
|
|
||||||
|
enum class DataType: GLenum { |
||||||
|
UnsignedByte = GL_UNSIGNED_BYTE, |
||||||
|
Byte = GL_BYTE, |
||||||
|
UnsignedShort = GL_UNSIGNED_SHORT, |
||||||
|
Short = GL_SHORT, |
||||||
|
UnsignedInt = GL_UNSIGNED_INT, |
||||||
|
Int = GL_INT, |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
HalfFloat = GL_HALF_FLOAT, |
||||||
|
#else |
||||||
|
HalfFloat = GL_HALF_FLOAT_OES, |
||||||
|
#endif |
||||||
|
Float = GL_FLOAT |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
, |
||||||
|
Double = GL_DOUBLE |
||||||
|
#endif |
||||||
|
}; |
||||||
|
#if !defined(CORRADE_GCC45_COMPATIBILITY) && !defined(CORRADE_MSVC2013_COMPATIBILITY) |
||||||
|
constexpr static |
||||||
|
#else |
||||||
|
static const |
||||||
|
#endif |
||||||
|
DataType DefaultDataType = DataType::Float; |
||||||
|
|
||||||
|
enum class DataOption: UnsignedByte { |
||||||
|
Normalized = 1 << 0 |
||||||
|
}; |
||||||
|
typedef Containers::EnumSet<DataOption, UnsignedByte> DataOptions; |
||||||
|
|
||||||
|
static UnsignedInt MAGNUM_EXPORT size(GLint components, DataType dataType); |
||||||
|
}; |
||||||
|
|
||||||
|
CORRADE_ENUMSET_OPERATORS(FloatAttribute::DataOptions) |
||||||
|
|
||||||
|
Debug MAGNUM_EXPORT operator<<(Debug debug, FloatAttribute::DataType value); |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
/* Base for int attributes */ |
||||||
|
struct IntAttribute { |
||||||
|
typedef Int ScalarType; |
||||||
|
|
||||||
|
enum class DataType: GLenum { |
||||||
|
UnsignedByte = GL_UNSIGNED_BYTE, |
||||||
|
Byte = GL_BYTE, |
||||||
|
UnsignedShort = GL_UNSIGNED_SHORT, |
||||||
|
Short = GL_SHORT, |
||||||
|
UnsignedInt = GL_UNSIGNED_INT, |
||||||
|
Int = GL_INT |
||||||
|
}; |
||||||
|
#if !defined(CORRADE_GCC45_COMPATIBILITY) && !defined(CORRADE_MSVC2013_COMPATIBILITY) |
||||||
|
constexpr static |
||||||
|
#else |
||||||
|
static const |
||||||
|
#endif |
||||||
|
DataType DefaultDataType = DataType::Int; |
||||||
|
|
||||||
|
enum class DataOption: UnsignedByte {}; |
||||||
|
typedef Containers::EnumSet<DataOption, UnsignedByte> DataOptions; |
||||||
|
|
||||||
|
static UnsignedInt MAGNUM_EXPORT size(GLint components, DataType dataType); |
||||||
|
}; |
||||||
|
|
||||||
|
CORRADE_ENUMSET_OPERATORS(IntAttribute::DataOptions) |
||||||
|
|
||||||
|
Debug MAGNUM_EXPORT operator<<(Debug debug, IntAttribute::DataType value); |
||||||
|
|
||||||
|
/* Base for unsigned int attributes */ |
||||||
|
struct UnsignedIntAttribute { |
||||||
|
typedef UnsignedInt ScalarType; |
||||||
|
|
||||||
|
typedef IntAttribute::DataType DataType; |
||||||
|
#if !defined(CORRADE_GCC45_COMPATIBILITY) && !defined(CORRADE_MSVC2013_COMPATIBILITY) |
||||||
|
constexpr static |
||||||
|
#else |
||||||
|
static const |
||||||
|
#endif |
||||||
|
DataType DefaultDataType = DataType::UnsignedInt; |
||||||
|
|
||||||
|
typedef IntAttribute::DataOption DataOption; |
||||||
|
typedef IntAttribute::DataOptions DataOptions; |
||||||
|
|
||||||
|
static UnsignedInt size(GLint components, DataType dataType) { |
||||||
|
return IntAttribute::size(components, dataType); |
||||||
|
} |
||||||
|
}; |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
/* Base for double attributes */ |
||||||
|
struct DoubleAttribute { |
||||||
|
typedef Double ScalarType; |
||||||
|
|
||||||
|
enum class DataType: GLenum { |
||||||
|
Double = GL_DOUBLE |
||||||
|
}; |
||||||
|
#if !defined(CORRADE_GCC45_COMPATIBILITY) && !defined(CORRADE_MSVC2013_COMPATIBILITY) |
||||||
|
constexpr static |
||||||
|
#else |
||||||
|
static const |
||||||
|
#endif |
||||||
|
DataType DefaultDataType = DataType::Double; |
||||||
|
|
||||||
|
typedef IntAttribute::DataOption DataOption; |
||||||
|
typedef IntAttribute::DataOptions DataOptions; |
||||||
|
|
||||||
|
static UnsignedInt MAGNUM_EXPORT size(GLint components, DataType dataType); |
||||||
|
}; |
||||||
|
|
||||||
|
Debug MAGNUM_EXPORT operator<<(Debug debug, DoubleAttribute::DataType value); |
||||||
|
#endif |
||||||
|
|
||||||
|
/* Floating-point three-component vector has additional data type compared to
|
||||||
|
classic floats */ |
||||||
|
template<> struct Attribute<Math::Vector<3, Float>>: SizedAttribute<1, 3> { |
||||||
|
typedef Float ScalarType; |
||||||
|
|
||||||
|
enum class DataType: GLenum { |
||||||
|
UnsignedByte = GL_UNSIGNED_BYTE, |
||||||
|
Byte = GL_BYTE, |
||||||
|
UnsignedShort = GL_UNSIGNED_SHORT, |
||||||
|
Short = GL_SHORT, |
||||||
|
UnsignedInt = GL_UNSIGNED_INT, |
||||||
|
Int = GL_INT, |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
HalfFloat = GL_HALF_FLOAT, |
||||||
|
#else |
||||||
|
HalfFloat = GL_HALF_FLOAT_OES, |
||||||
|
#endif |
||||||
|
Float = GL_FLOAT |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
, |
||||||
|
Double = GL_DOUBLE, |
||||||
|
UnsignedInt10f11f11fRev = GL_UNSIGNED_INT_10F_11F_11F_REV |
||||||
|
#endif |
||||||
|
}; |
||||||
|
#if !defined(CORRADE_GCC45_COMPATIBILITY) && !defined(CORRADE_MSVC2013_COMPATIBILITY) |
||||||
|
constexpr static |
||||||
|
#else |
||||||
|
static const |
||||||
|
#endif |
||||||
|
DataType DefaultDataType = DataType::Float; |
||||||
|
|
||||||
|
typedef FloatAttribute::DataOption DataOption; |
||||||
|
typedef FloatAttribute::DataOptions DataOptions; |
||||||
|
|
||||||
|
static UnsignedInt MAGNUM_EXPORT size(GLint components, DataType dataType); |
||||||
|
}; |
||||||
|
|
||||||
|
Debug MAGNUM_EXPORT operator<<(Debug debug, Attribute<Math::Vector<3, Float>>::DataType value); |
||||||
|
|
||||||
|
/* Floating-point four-component vector is absolutely special case */ |
||||||
|
template<> struct Attribute<Math::Vector<4, Float>> { |
||||||
|
typedef Float ScalarType; |
||||||
|
|
||||||
|
enum class Components: GLint { |
||||||
|
One = 1, |
||||||
|
Two = 2, |
||||||
|
Three = 3, |
||||||
|
Four = 4 |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
, |
||||||
|
BGRA = GL_BGRA |
||||||
|
#endif |
||||||
|
}; |
||||||
|
#if !defined(CORRADE_GCC45_COMPATIBILITY) && !defined(CORRADE_MSVC2013_COMPATIBILITY) |
||||||
|
constexpr static |
||||||
|
#else |
||||||
|
static const |
||||||
|
#endif |
||||||
|
Components DefaultComponents = Components::Four; |
||||||
|
|
||||||
|
enum class DataType: GLenum { |
||||||
|
UnsignedByte = GL_UNSIGNED_BYTE, |
||||||
|
Byte = GL_BYTE, |
||||||
|
UnsignedShort = GL_UNSIGNED_SHORT, |
||||||
|
Short = GL_SHORT, |
||||||
|
UnsignedInt = GL_UNSIGNED_INT, |
||||||
|
Int = GL_INT, |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
HalfFloat = GL_HALF_FLOAT, |
||||||
|
#else |
||||||
|
HalfFloat = GL_HALF_FLOAT_OES, |
||||||
|
#endif |
||||||
|
Float = GL_FLOAT |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
, |
||||||
|
Double = GL_DOUBLE |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
, |
||||||
|
UnsignedInt2101010Rev = GL_UNSIGNED_INT_2_10_10_10_REV, |
||||||
|
Int2101010Rev = GL_INT_2_10_10_10_REV |
||||||
|
#endif |
||||||
|
}; |
||||||
|
#if !defined(CORRADE_GCC45_COMPATIBILITY) && !defined(CORRADE_MSVC2013_COMPATIBILITY) |
||||||
|
constexpr static |
||||||
|
#else |
||||||
|
static const |
||||||
|
#endif |
||||||
|
DataType DefaultDataType = DataType::Float; |
||||||
|
|
||||||
|
typedef FloatAttribute::DataOption DataOption; |
||||||
|
typedef FloatAttribute::DataOptions DataOptions; |
||||||
|
|
||||||
|
enum: UnsignedInt { VectorCount = 1 }; |
||||||
|
|
||||||
|
static UnsignedInt MAGNUM_EXPORT size(GLint components, DataType dataType); |
||||||
|
}; |
||||||
|
|
||||||
|
Debug MAGNUM_EXPORT operator<<(Debug debug, Attribute<Math::Vector<4, Float>>::Components value); |
||||||
|
Debug MAGNUM_EXPORT operator<<(Debug debug, Attribute<Math::Vector<4, Float>>::DataType value); |
||||||
|
|
||||||
|
/* Common float, int, unsigned int and double scalar attributes */ |
||||||
|
template<> struct Attribute<Float>: FloatAttribute, SizedAttribute<1, 1> {}; |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
template<> struct Attribute<Int>: IntAttribute, SizedAttribute<1, 1> {}; |
||||||
|
template<> struct Attribute<UnsignedInt>: UnsignedIntAttribute, SizedAttribute<1, 1> {}; |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
template<> struct Attribute<Double>: DoubleAttribute, SizedAttribute<1, 1> {}; |
||||||
|
#endif |
||||||
|
#endif |
||||||
|
|
||||||
|
/* Common float, int, unsigned int and double vector attributes */ |
||||||
|
template<std::size_t size_> struct Attribute<Math::Vector<size_, Float>>: FloatAttribute, SizedAttribute<1, size_> {}; |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
template<std::size_t size_> struct Attribute<Math::Vector<size_, Int>>: IntAttribute, SizedAttribute<1, size_> {}; |
||||||
|
template<std::size_t size_> struct Attribute<Math::Vector<size_, UnsignedInt>>: UnsignedIntAttribute, SizedAttribute<1, size_> {}; |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
template<std::size_t size_> struct Attribute<Math::Vector<size_, Double>>: DoubleAttribute, SizedAttribute<1, size_> {}; |
||||||
|
#endif |
||||||
|
#endif |
||||||
|
template<class T> struct Attribute<Math::Vector2<T>>: Attribute<Math::Vector<2, T>> {}; |
||||||
|
template<class T> struct Attribute<Math::Vector3<T>>: Attribute<Math::Vector<3, T>> {}; |
||||||
|
template<class T> struct Attribute<Math::Vector4<T>>: Attribute<Math::Vector<4, T>> {}; |
||||||
|
template<class T> struct Attribute<BasicColor3<T>>: Attribute<Math::Vector3<T>> {}; |
||||||
|
template<class T> struct Attribute<BasicColor4<T>>: Attribute<Math::Vector4<T>> {}; |
||||||
|
|
||||||
|
/* Common float and double rectangular matrix attributes */ |
||||||
|
template<std::size_t cols, std::size_t rows> struct Attribute<Math::RectangularMatrix<cols, rows, Float>>: FloatAttribute, SizedAttribute<cols, rows> {}; |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
template<std::size_t cols, std::size_t rows> struct Attribute<Math::RectangularMatrix<cols, rows, Double>>: DoubleAttribute, SizedAttribute<cols, rows> {}; |
||||||
|
#endif |
||||||
|
|
||||||
|
/* Common float and double square matrix attributes */ |
||||||
|
template<std::size_t size_> struct Attribute<Math::Matrix<size_, Float>>: Attribute<Math::RectangularMatrix<size_, size_, Float>> {}; |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
template<std::size_t size_> struct Attribute<Math::Matrix<size_, Double>>: Attribute<Math::RectangularMatrix<size_, size_, Double>> {}; |
||||||
|
#endif |
||||||
|
template<class T> struct Attribute<Math::Matrix3<T>>: Attribute<Math::Matrix<3, T>> {}; |
||||||
|
template<class T> struct Attribute<Math::Matrix4<T>>: Attribute<Math::Matrix<4, T>> {}; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
#endif |
||||||