mirror of https://github.com/mosra/magnum.git
Browse Source
Conflicts: src/Magnum.h src/Shaders/DistanceFieldVector.cpp src/Shaders/Flat.cpp src/Shaders/Vector.cpp
98 changed files with 3956 additions and 863 deletions
@ -0,0 +1,481 @@
|
||||
#ifndef Magnum_ColorFormat_h |
||||
#define Magnum_ColorFormat_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Enum Magnum::ColorFormat, Magnum::ColorType |
||||
*/ |
||||
|
||||
#include "Magnum.h" |
||||
#include "OpenGL.h" |
||||
#include "magnumVisibility.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
/**
|
||||
@brief Format of image data |
||||
|
||||
Note that some formats can be used only for framebuffer reading (using |
||||
AbstractFramebuffer::read()) and some only for texture data (using Texture::setImage() |
||||
and others). |
||||
@see Image, ImageReference, BufferImage, Trade::ImageData |
||||
*/ |
||||
enum class ColorFormat: GLenum { |
||||
/**
|
||||
* Floating-point red channel. |
||||
* @requires_gles30 For texture data only, extension @es_extension{EXT,texture_rg}. |
||||
* @requires_es_extension For framebuffer reading, extension @es_extension{EXT,texture_rg}. |
||||
*/ |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
Red = GL_RED, |
||||
#else |
||||
Red = GL_RED_EXT, |
||||
#endif |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/**
|
||||
* Floating-point green channel. |
||||
* @requires_gl Only @ref Magnum::ColorFormat "ColorFormat::Red" is |
||||
* available in OpenGL ES. |
||||
*/ |
||||
Green = GL_GREEN, |
||||
|
||||
/**
|
||||
* Floating-point blue channel. |
||||
* @requires_gl Only @ref Magnum::ColorFormat "ColorFormat::Red" is |
||||
* available in OpenGL ES. |
||||
*/ |
||||
Blue = GL_BLUE, |
||||
#endif |
||||
|
||||
#if defined(MAGNUM_TARGET_GLES2) || defined(DOXYGEN_GENERATING_OUTPUT) |
||||
/**
|
||||
* Floating-point luminance channel. The value is used for all RGB |
||||
* channels. |
||||
* @deprecated Included for compatibility reasons only, use |
||||
* @ref Magnum::ColorFormat "ColorFormat::Red" instead. |
||||
* @requires_gles20 Not available in ES 3.0 or desktop OpenGL. Use |
||||
* @ref Magnum::ColorFormat "ColorFormat::Red" instead. |
||||
*/ |
||||
Luminance = GL_LUMINANCE, |
||||
#endif |
||||
|
||||
/**
|
||||
* Floating-point red and green channel. |
||||
* @requires_gl30 %Extension @extension{ARB,texture_rg} and @extension{EXT,texture_integer} |
||||
* @requires_gles30 For texture data only, extension @es_extension{EXT,texture_rg}. |
||||
* @requires_es_extension For framebuffer reading, extension @es_extension{EXT,texture_rg}. |
||||
*/ |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
RG = GL_RG, |
||||
#else |
||||
RG = GL_RG_EXT, |
||||
#endif |
||||
|
||||
#if defined(MAGNUM_TARGET_GLES2) || defined(DOXYGEN_GENERATING_OUTPUT) |
||||
/**
|
||||
* Floating-point luminance and alpha channel. First value is used for all |
||||
* RGB channels, second value is used for alpha channel. |
||||
* @deprecated Included for compatibility reasons only, use |
||||
* @ref Magnum::ColorFormat "ColorFormat::RG" instead. |
||||
* @requires_gles20 Not available in ES 3.0 or desktop OpenGL. Use |
||||
* @ref Magnum::ColorFormat "ColorFormat::RG" instead. |
||||
*/ |
||||
LuminanceAlpha = GL_LUMINANCE_ALPHA, |
||||
#endif |
||||
|
||||
/**
|
||||
* Floating-point RGB. |
||||
* @requires_gl Can't be used for framebuffer reading in OpenGL ES. |
||||
*/ |
||||
RGB = GL_RGB, |
||||
|
||||
/** Floating-point RGBA. */ |
||||
RGBA = GL_RGBA, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/**
|
||||
* Floating-point BGR. |
||||
* @requires_gl Only RGB component ordering is available in OpenGL ES. |
||||
*/ |
||||
BGR = GL_BGR, |
||||
#endif |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES3 |
||||
/**
|
||||
* Floating-point BGRA. |
||||
* @requires_es_extension %Extension @es_extension{EXT,read_format_bgra} |
||||
* for framebuffer reading, extension @es_extension{APPLE,texture_format_BGRA8888} |
||||
* or @es_extension{EXT,texture_format_BGRA8888} for texture data. |
||||
*/ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
BGRA = GL_BGRA, |
||||
#else |
||||
BGRA = GL_BGRA_EXT, |
||||
#endif |
||||
#endif |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/**
|
||||
* Integer red channel. |
||||
* @requires_gl30 %Extension @extension{EXT,texture_integer} |
||||
* @requires_gles30 Only floating-point image data are available in OpenGL |
||||
* ES 2.0. |
||||
*/ |
||||
RedInteger = GL_RED_INTEGER, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/**
|
||||
* Integer green channel. |
||||
* @requires_gl30 %Extension @extension{EXT,texture_integer} |
||||
* @requires_gl Only @ref Magnum::ColorFormat "ColorFormat::RedInteger" |
||||
* is available in OpenGL ES 3.0, only floating-point image data are |
||||
* available in OpenGL ES 2.0. |
||||
*/ |
||||
GreenInteger = GL_GREEN_INTEGER, |
||||
|
||||
/**
|
||||
* Integer blue channel. |
||||
* @requires_gl30 %Extension @extension{EXT,texture_integer} |
||||
* @requires_gl Only @ref Magnum::ColorFormat "ColorFormat::RedInteger" is |
||||
* available in OpenGL ES 3.0, only floating-point image data are |
||||
* available in OpenGL ES 2.0. |
||||
*/ |
||||
BlueInteger = GL_BLUE_INTEGER, |
||||
#endif |
||||
|
||||
/**
|
||||
* Integer red and green channel. |
||||
* @requires_gl30 %Extension @extension{ARB,texture_rg} and @extension{EXT,texture_integer} |
||||
* @requires_gl Can't be used for framebuffer reading in OpenGL ES. |
||||
* @requires_gles30 For texture data only, only floating-point image data |
||||
* are available in OpenGL ES 2.0. |
||||
*/ |
||||
RGInteger = GL_RG_INTEGER, |
||||
|
||||
/**
|
||||
* Integer RGB. |
||||
* @requires_gl30 %Extension @extension{EXT,texture_integer} |
||||
* @requires_gl Can't be used for framebuffer reading in OpenGL ES. |
||||
* @requires_gles30 For texture data only, only floating-point image data |
||||
* are available in OpenGL ES 2.0. |
||||
*/ |
||||
RGBInteger = GL_RGB_INTEGER, |
||||
|
||||
/**
|
||||
* Integer RGBA. |
||||
* @requires_gl30 %Extension @extension{EXT,texture_integer} |
||||
* @requires_gles30 Only floating-point image data are available in OpenGL |
||||
* ES 2.0. |
||||
*/ |
||||
RGBAInteger = GL_RGBA_INTEGER, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/**
|
||||
* Integer BGR. |
||||
* @requires_gl30 %Extension @extension{EXT,texture_integer} |
||||
* @requires_gl Only @ref Magnum::ColorFormat "ColorFormat::RGBInteger" is |
||||
* available in OpenGL ES 3.0, only floating-point image data are |
||||
* available in OpenGL ES 2.0. |
||||
*/ |
||||
BGRInteger = GL_BGR_INTEGER, |
||||
|
||||
/**
|
||||
* Integer BGRA. |
||||
* @requires_gl30 %Extension @extension{EXT,texture_integer} |
||||
* @requires_gl Only @ref Magnum::ColorFormat "ColorFormat::RGBAInteger" is |
||||
* available in OpenGL ES 3.0, only floating-point image data are |
||||
* available in OpenGL ES 2.0. |
||||
*/ |
||||
BGRAInteger = GL_BGRA_INTEGER, |
||||
#endif |
||||
#endif |
||||
|
||||
/**
|
||||
* Depth component. |
||||
* @requires_gles30 For texture data only, extension @es_extension{ANGLE,depth_texture}. |
||||
* @requires_es_extension For framebuffer reading only, extension |
||||
* @es_extension2{NV,read_depth,GL_NV_read_depth_stencil}. |
||||
*/ |
||||
DepthComponent = GL_DEPTH_COMPONENT, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES3 |
||||
/**
|
||||
* Stencil index. |
||||
* @requires_gl44 %Extension @extension{ARB,texture_stencil8} for texture |
||||
* data, otherwise for framebuffer reading only. |
||||
* @requires_es_extension %Extension @es_extension2{NV,read_stencil,GL_NV_read_depth_stencil}, |
||||
* for framebuffer reading only. |
||||
* @todo Where to get GL_STENCIL_INDEX in ES? |
||||
*/ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
StencilIndex = GL_STENCIL_INDEX, |
||||
#else |
||||
StencilIndex = 0x1901, |
||||
#endif |
||||
#endif |
||||
|
||||
/**
|
||||
* Depth and stencil. |
||||
* @requires_gl30 %Extension @extension{ARB,framebuffer_object} |
||||
* @requires_gles30 For texture data only, extension @es_extension{OES,packed_depth_stencil}. |
||||
* @requires_es_extension For framebuffer reading only, extension |
||||
* @es_extension2{NV,read_depth_stencil,GL_NV_read_depth_stencil}. |
||||
*/ |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
DepthStencil = GL_DEPTH_STENCIL |
||||
#else |
||||
DepthStencil = GL_DEPTH_STENCIL_OES |
||||
#endif |
||||
}; |
||||
|
||||
/**
|
||||
@brief Type of image data |
||||
|
||||
Note that some formats can be used only for framebuffer reading (using |
||||
AbstractFramebuffer::read()) and some only for texture data (using Texture::setImage() |
||||
and others). |
||||
@see Image, ImageReference, BufferImage, Trade::ImageData |
||||
*/ |
||||
enum class ColorType: GLenum { |
||||
/** Each component unsigned byte. */ |
||||
UnsignedByte = GL_UNSIGNED_BYTE, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/**
|
||||
* Each component signed byte. |
||||
* @requires_gl Can't be used for framebuffer reading in OpenGL ES. |
||||
* @requires_gles30 For texture data only, only @ref Magnum::ColorType "ColorType::UnsignedByte" |
||||
* is available in OpenGL ES 2.0. |
||||
*/ |
||||
Byte = GL_BYTE, |
||||
#endif |
||||
|
||||
/**
|
||||
* Each component unsigned short. |
||||
* @requires_gl Can't be used for framebuffer reading in OpenGL ES. |
||||
* @requires_gles30 For texture data only, extension @es_extension{OES,depth_texture} |
||||
* or @es_extension{ANGLE,depth_texture}. |
||||
*/ |
||||
UnsignedShort = GL_UNSIGNED_SHORT, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/**
|
||||
* Each component signed short. |
||||
* @requires_gl Can't be used for framebuffer reading in OpenGL ES. |
||||
* @requires_gles30 For texture data only, only @ref Magnum::ColorType "ColorType::UnsignedShort" |
||||
* is available in OpenGL ES 2.0. |
||||
*/ |
||||
Short = GL_SHORT, |
||||
#endif |
||||
|
||||
/**
|
||||
* Each component unsigned int. |
||||
* @requires_gles30 Can't be used for framebuffer reading in OpenGL ES 2.0. |
||||
* @requires_gles30 For texture data only, extension @es_extension{OES,depth_texture} |
||||
* or @es_extension{ANGLE,depth_texture}. |
||||
*/ |
||||
UnsignedInt = GL_UNSIGNED_INT, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/**
|
||||
* Each component signed int. |
||||
* @requires_gles30 Only @ref Magnum::ColorType "ColorType::UnsignedInt" |
||||
* is available in OpenGL ES 2.0. |
||||
*/ |
||||
Int = GL_INT, |
||||
#endif |
||||
|
||||
/**
|
||||
* Each component half float. |
||||
* @requires_gl30 %Extension @extension{NV,half_float} / @extension{ARB,half_float_pixel} |
||||
* @requires_gles30 For texture data only, extension |
||||
* @es_extension2{OES,texture_half_float,OES_texture_float}. |
||||
*/ |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
HalfFloat = GL_HALF_FLOAT, |
||||
#else |
||||
HalfFloat = GL_HALF_FLOAT_OES, |
||||
#endif |
||||
|
||||
/**
|
||||
* Each component float. |
||||
* @requires_gles30 For texture data only, extension @es_extension{OES,texture_float}. |
||||
*/ |
||||
Float = GL_FLOAT, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/**
|
||||
* RGB, unsigned byte, red and green component 3bit, blue component 2bit. |
||||
* @requires_gl Packed 12bit types are not available in OpenGL ES. |
||||
*/ |
||||
UnsignedByte332 = GL_UNSIGNED_BYTE_3_3_2, |
||||
|
||||
/**
|
||||
* BGR, unsigned byte, red and green component 3bit, blue component 2bit. |
||||
* @requires_gl Packed 12bit types are not available in OpenGL ES. |
||||
*/ |
||||
UnsignedByte233Rev = GL_UNSIGNED_BYTE_2_3_3_REV, |
||||
#endif |
||||
|
||||
/**
|
||||
* RGB, unsigned byte, red and blue component 5bit, green 6bit. |
||||
* @requires_gl Can't be used for framebuffer reading in OpenGL ES. |
||||
*/ |
||||
UnsignedShort565 = GL_UNSIGNED_SHORT_5_6_5, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/**
|
||||
* BGR, unsigned short, red and blue 5bit, green 6bit. |
||||
* @requires_gl Only @ref Magnum::ColorType "ColorType::RGB565" is |
||||
* available in OpenGL ES. |
||||
*/ |
||||
UnsignedShort565Rev = GL_UNSIGNED_SHORT_5_6_5_REV, |
||||
#endif |
||||
|
||||
/**
|
||||
* RGBA, unsigned short, each component 4bit. |
||||
* @requires_gl Can't be used for framebuffer reading in OpenGL ES. |
||||
*/ |
||||
UnsignedShort4444 = GL_UNSIGNED_SHORT_4_4_4_4, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES3 |
||||
/**
|
||||
* ABGR, unsigned short, each component 4bit. |
||||
* @requires_es_extension For framebuffer reading only, extension |
||||
* @es_extension{EXT,read_format_bgra}. |
||||
*/ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
UnsignedShort4444Rev = GL_UNSIGNED_SHORT_4_4_4_4_REV, |
||||
#else |
||||
UnsignedShort4444Rev = GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, |
||||
#endif |
||||
#endif |
||||
|
||||
/**
|
||||
* RGBA, unsigned short, each RGB component 5bit, alpha component 1bit. |
||||
* @requires_gl Can't be used for framebuffer reading in OpenGL ES. |
||||
*/ |
||||
UnsignedShort5551 = GL_UNSIGNED_SHORT_5_5_5_1, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES3 |
||||
/**
|
||||
* ABGR, unsigned short, each RGB component 5bit, alpha component 1bit. |
||||
* @requires_es_extension For framebuffer reading only, extension |
||||
* @es_extension{EXT,read_format_bgra}. |
||||
*/ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
UnsignedShort1555Rev = GL_UNSIGNED_SHORT_1_5_5_5_REV, |
||||
#else |
||||
UnsignedShort1555Rev = GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, |
||||
#endif |
||||
#endif |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/**
|
||||
* RGBA, unsigned int, each component 8bit. |
||||
* @requires_gl Use @ref Magnum::ColorType "ColorType::UnsignedByte" in |
||||
* OpenGL ES instead. |
||||
*/ |
||||
UnsignedInt8888 = GL_UNSIGNED_INT_8_8_8_8, |
||||
|
||||
/**
|
||||
* ABGR, unsigned int, each component 8bit. |
||||
* @requires_gl Only RGBA component ordering is available in OpenGL ES, see |
||||
* @ref Magnum::ColorType "ColorType::UnsignedInt8888" for more |
||||
* information. |
||||
*/ |
||||
UnsignedInt8888Rev = GL_UNSIGNED_INT_8_8_8_8_REV, |
||||
|
||||
/**
|
||||
* RGBA, unsigned int, each RGB component 10bit, alpha component 2bit. |
||||
* @requires_gl Only @ref Magnum::ColorType "ColorType::UnsignedInt2101010Rev" |
||||
* is available in OpenGL ES. |
||||
*/ |
||||
UnsignedInt1010102 = GL_UNSIGNED_INT_10_10_10_2, |
||||
#endif |
||||
|
||||
/**
|
||||
* ABGR, unsigned int, each RGB component 10bit, alpha component 2bit. |
||||
* @requires_gles30 Can't be used for framebuffer reading in OpenGL ES 2.0. |
||||
* @requires_gles30 For texture data only, extension |
||||
* @es_extension{EXT,texture_type_2_10_10_10_REV}. |
||||
*/ |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
UnsignedInt2101010Rev = GL_UNSIGNED_INT_2_10_10_10_REV, |
||||
#else |
||||
UnsignedInt2101010Rev = GL_UNSIGNED_INT_2_10_10_10_REV_EXT, |
||||
#endif |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/**
|
||||
* BGR, unsigned int, red and green 11bit float, blue 10bit float. |
||||
* @requires_gl30 %Extension @extension{EXT,packed_float} |
||||
* @requires_gles30 Floating-point types are not available in OpenGL ES |
||||
* 2.0. |
||||
*/ |
||||
UnsignedInt10F11F11FRev = GL_UNSIGNED_INT_10F_11F_11F_REV, |
||||
|
||||
/**
|
||||
* BGR, unsigned int, each component 9bit + 5bit exponent. |
||||
* @requires_gl30 %Extension @extension{EXT,texture_shared_exponent} |
||||
* @requires_gles30 Only 8bit and 16bit types are available in OpenGL ES |
||||
* 2.0. |
||||
*/ |
||||
UnsignedInt5999Rev = GL_UNSIGNED_INT_5_9_9_9_REV, |
||||
#endif |
||||
|
||||
/**
|
||||
* Unsigned int, depth component 24bit, stencil index 8bit. |
||||
* @requires_gl30 %Extension @extension{ARB,framebuffer_object} |
||||
* @requires_gles30 For texture data only, extension @es_extension{OES,packed_depth_stencil}. |
||||
*/ |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
UnsignedInt248 = GL_UNSIGNED_INT_24_8, |
||||
#else |
||||
UnsignedInt248 = GL_UNSIGNED_INT_24_8_OES, |
||||
#endif |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/**
|
||||
* Float + unsigned int, depth component 32bit float, 24bit gap, stencil |
||||
* index 8bit. |
||||
* @requires_gl30 %Extension @extension{ARB,depth_buffer_float} |
||||
* @requires_gles30 For texture data only, only @ref Magnum::ColorType "ColorType::UnsignedInt248" |
||||
* is available in OpenGL ES 2.0. |
||||
*/ |
||||
Float32UnsignedInt248Rev = GL_FLOAT_32_UNSIGNED_INT_24_8_REV |
||||
#endif |
||||
}; |
||||
|
||||
/** @debugoperator{ColorFormat} */ |
||||
Debug MAGNUM_EXPORT operator<<(Debug debug, ColorFormat value); |
||||
|
||||
/** @debugoperator{ColorFormat} */ |
||||
Debug MAGNUM_EXPORT operator<<(Debug debug, ColorType value); |
||||
|
||||
} |
||||
|
||||
#endif |
||||
@ -0,0 +1,92 @@
|
||||
#ifndef Magnum_Implementation_ShaderState_h |
||||
#define Magnum_Implementation_ShaderState_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "OpenGL.h" |
||||
#include "Types.h" |
||||
#include "magnumConfigure.h" |
||||
|
||||
namespace Magnum { namespace Implementation { |
||||
|
||||
struct ShaderState { |
||||
explicit ShaderState(): |
||||
maxVertexOutputComponents{}, maxFragmentInputComponents{}, |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
maxTessellationControlInputComponents{}, maxTessellationControlOutputComponents{}, maxTessellationControlTotalOutputComponents{}, maxTessellationEvaluationInputComponents{}, maxTessellationEvaluationOutputComponents{}, maxGeometryInputComponents{}, maxGeometryOutputComponents{}, maxGeometryTotalOutputComponents{}, maxAtomicCounterBuffers{}, maxCombinedAtomicCounterBuffers{}, maxAtomicCounters{}, maxCombinedAtomicCounters{}, maxImageUniforms{}, maxCombinedImageUniforms{}, maxShaderStorageBlocks{}, maxCombinedShaderStorageBlocks{}, |
||||
#endif |
||||
maxTextureImageUnits{}, maxTextureImageUnitsCombined{}, |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
maxUniformBlocks{}, maxCombinedUniformBlocks{}, |
||||
#endif |
||||
maxUniformComponents{}, maxUniformComponentsCombined{} |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
, maxCombinedUniformComponents{} |
||||
#endif |
||||
{} |
||||
|
||||
enum: std::size_t { |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
StageCount = 5 |
||||
#else |
||||
StageCount = 2 |
||||
#endif |
||||
}; |
||||
|
||||
GLint maxVertexOutputComponents, |
||||
maxFragmentInputComponents; |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
GLint maxTessellationControlInputComponents, |
||||
maxTessellationControlOutputComponents, |
||||
maxTessellationControlTotalOutputComponents, |
||||
maxTessellationEvaluationInputComponents, |
||||
maxTessellationEvaluationOutputComponents, |
||||
maxGeometryInputComponents, |
||||
maxGeometryOutputComponents, |
||||
maxGeometryTotalOutputComponents; |
||||
GLint maxAtomicCounterBuffers[StageCount]; |
||||
GLint maxCombinedAtomicCounterBuffers; |
||||
GLint maxAtomicCounters[StageCount]; |
||||
GLint maxCombinedAtomicCounters; |
||||
GLint maxImageUniforms[StageCount]; |
||||
GLint maxCombinedImageUniforms; |
||||
GLint maxShaderStorageBlocks[StageCount]; |
||||
GLint maxCombinedShaderStorageBlocks; |
||||
#endif |
||||
GLint maxTextureImageUnits[StageCount]; |
||||
GLint maxTextureImageUnitsCombined; |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
GLint maxUniformBlocks[StageCount]; |
||||
GLint maxCombinedUniformBlocks; |
||||
#endif |
||||
GLint maxUniformComponents[StageCount]; |
||||
GLint maxUniformComponentsCombined; |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
GLint maxCombinedUniformComponents[StageCount]; |
||||
#endif |
||||
}; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,32 @@
|
||||
# |
||||
# This file is part of Magnum. |
||||
# |
||||
# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
# |
||||
# Permission is hereby granted, free of charge, to any person obtaining a |
||||
# copy of this software and associated documentation files (the "Software"), |
||||
# to deal in the Software without restriction, including without limitation |
||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
# and/or sell copies of the Software, and to permit persons to whom the |
||||
# Software is furnished to do so, subject to the following conditions: |
||||
# |
||||
# The above copyright notice and this permission notice shall be included |
||||
# in all copies or substantial portions of the Software. |
||||
# |
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
# DEALINGS IN THE SOFTWARE. |
||||
# |
||||
|
||||
if(BUILD_GL_TESTS) |
||||
corrade_add_test(ShadersDistanceFieldVectorTest DistanceFieldVectorTest.cpp LIBRARIES MagnumShaders ${GL_TEST_LIBRARIES}) |
||||
corrade_add_test(ShadersFlatTest FlatTest.cpp LIBRARIES MagnumShaders ${GL_TEST_LIBRARIES}) |
||||
corrade_add_test(ShadersMeshVisualizerTest MeshVisualizerTest.cpp LIBRARIES MagnumShaders ${GL_TEST_LIBRARIES}) |
||||
corrade_add_test(ShadersPhongTest PhongTest.cpp LIBRARIES MagnumShaders ${GL_TEST_LIBRARIES}) |
||||
corrade_add_test(ShadersVectorTest VectorTest.cpp LIBRARIES MagnumShaders ${GL_TEST_LIBRARIES}) |
||||
corrade_add_test(ShadersVertexColorTest VertexColorTest.cpp LIBRARIES MagnumShaders ${GL_TEST_LIBRARIES}) |
||||
endif() |
||||
@ -0,0 +1,55 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "Shaders/DistanceFieldVector.h" |
||||
#include "Test/AbstractOpenGLTester.h" |
||||
|
||||
namespace Magnum { namespace Shaders { namespace Test { |
||||
|
||||
class DistanceFieldVectorTest: public Magnum::Test::AbstractOpenGLTester { |
||||
public: |
||||
explicit DistanceFieldVectorTest(); |
||||
|
||||
void compile2D(); |
||||
void compile3D(); |
||||
}; |
||||
|
||||
DistanceFieldVectorTest::DistanceFieldVectorTest() { |
||||
addTests({&DistanceFieldVectorTest::compile2D, |
||||
&DistanceFieldVectorTest::compile3D}); |
||||
} |
||||
|
||||
void DistanceFieldVectorTest::compile2D() { |
||||
Shaders::DistanceFieldVector2D shader; |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
void DistanceFieldVectorTest::compile3D() { |
||||
Shaders::DistanceFieldVector3D shader; |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Shaders::Test::DistanceFieldVectorTest) |
||||
@ -0,0 +1,55 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "Shaders/Flat.h" |
||||
#include "Test/AbstractOpenGLTester.h" |
||||
|
||||
namespace Magnum { namespace Shaders { namespace Test { |
||||
|
||||
class FlatTest: public Magnum::Test::AbstractOpenGLTester { |
||||
public: |
||||
explicit FlatTest(); |
||||
|
||||
void compile2D(); |
||||
void compile3D(); |
||||
}; |
||||
|
||||
FlatTest::FlatTest() { |
||||
addTests({&FlatTest::compile2D, |
||||
&FlatTest::compile3D}); |
||||
} |
||||
|
||||
void FlatTest::compile2D() { |
||||
Shaders::Flat2D shader; |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
void FlatTest::compile3D() { |
||||
Shaders::Flat3D shader; |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Shaders::Test::FlatTest) |
||||
@ -0,0 +1,71 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "Context.h" |
||||
#include "Extensions.h" |
||||
#include "Shaders/MeshVisualizer.h" |
||||
#include "Test/AbstractOpenGLTester.h" |
||||
|
||||
namespace Magnum { namespace Shaders { namespace Test { |
||||
|
||||
class MeshVisualizerTest: public Magnum::Test::AbstractOpenGLTester { |
||||
public: |
||||
explicit MeshVisualizerTest(); |
||||
|
||||
void compile(); |
||||
void compileWireframeGeometryShader(); |
||||
void compileWireframeNoGeometryShader(); |
||||
}; |
||||
|
||||
MeshVisualizerTest::MeshVisualizerTest() { |
||||
addTests({&MeshVisualizerTest::compile, |
||||
&MeshVisualizerTest::compileWireframeGeometryShader, |
||||
&MeshVisualizerTest::compileWireframeNoGeometryShader}); |
||||
} |
||||
|
||||
void MeshVisualizerTest::compile() { |
||||
Shaders::MeshVisualizer shader; |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
void MeshVisualizerTest::compileWireframeGeometryShader() { |
||||
#ifdef MAGNUM_TARGET_GLES |
||||
CORRADE_SKIP("Geometry shader is not available in OpenGL ES"); |
||||
#else |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::geometry_shader4>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::geometry_shader4::string() + std::string(" is not supported")); |
||||
|
||||
Shaders::MeshVisualizer shader(Shaders::MeshVisualizer::Flag::Wireframe); |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
#endif |
||||
} |
||||
|
||||
void MeshVisualizerTest::compileWireframeNoGeometryShader() { |
||||
Shaders::MeshVisualizer shader(Shaders::MeshVisualizer::Flag::Wireframe|Shaders::MeshVisualizer::Flag::NoGeometryShader); |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Shaders::Test::MeshVisualizerTest) |
||||
@ -0,0 +1,97 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "Shaders/Phong.h" |
||||
#include "Test/AbstractOpenGLTester.h" |
||||
|
||||
namespace Magnum { namespace Shaders { namespace Test { |
||||
|
||||
class PhongTest: public Magnum::Test::AbstractOpenGLTester { |
||||
public: |
||||
explicit PhongTest(); |
||||
|
||||
void compile(); |
||||
void compileAmbientTexture(); |
||||
void compileDiffuseTexture(); |
||||
void compileSpecularTexture(); |
||||
void compileAmbientDiffuseTexture(); |
||||
void compileAmbientSpecularTexture(); |
||||
void compileDiffuseSpecularTexture(); |
||||
void compileAmbientDiffuseSpecularTexture(); |
||||
}; |
||||
|
||||
PhongTest::PhongTest() { |
||||
addTests({&PhongTest::compile, |
||||
&PhongTest::compileAmbientTexture, |
||||
&PhongTest::compileDiffuseTexture, |
||||
&PhongTest::compileSpecularTexture, |
||||
&PhongTest::compileAmbientDiffuseTexture, |
||||
&PhongTest::compileAmbientSpecularTexture, |
||||
&PhongTest::compileDiffuseSpecularTexture, |
||||
&PhongTest::compileAmbientDiffuseSpecularTexture}); |
||||
} |
||||
|
||||
void PhongTest::compile() { |
||||
Shaders::Phong shader; |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
void PhongTest::compileAmbientTexture() { |
||||
Shaders::Phong shader(Shaders::Phong::Flag::AmbientTexture); |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
void PhongTest::compileDiffuseTexture() { |
||||
Shaders::Phong shader(Shaders::Phong::Flag::DiffuseTexture); |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
void PhongTest::compileSpecularTexture() { |
||||
Shaders::Phong shader(Shaders::Phong::Flag::SpecularTexture); |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
void PhongTest::compileAmbientDiffuseTexture() { |
||||
Shaders::Phong shader(Shaders::Phong::Flag::AmbientTexture|Shaders::Phong::Flag::DiffuseTexture); |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
void PhongTest::compileAmbientSpecularTexture() { |
||||
Shaders::Phong shader(Shaders::Phong::Flag::AmbientTexture|Shaders::Phong::Flag::SpecularTexture); |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
void PhongTest::compileDiffuseSpecularTexture() { |
||||
Shaders::Phong shader(Shaders::Phong::Flag::DiffuseTexture|Shaders::Phong::Flag::SpecularTexture); |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
void PhongTest::compileAmbientDiffuseSpecularTexture() { |
||||
Shaders::Phong shader(Shaders::Phong::Flag::AmbientTexture|Shaders::Phong::Flag::DiffuseTexture|Shaders::Phong::Flag::SpecularTexture); |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Shaders::Test::PhongTest) |
||||
@ -0,0 +1,55 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "Shaders/Vector.h" |
||||
#include "Test/AbstractOpenGLTester.h" |
||||
|
||||
namespace Magnum { namespace Shaders { namespace Test { |
||||
|
||||
class VectorTest: public Magnum::Test::AbstractOpenGLTester { |
||||
public: |
||||
explicit VectorTest(); |
||||
|
||||
void compile2D(); |
||||
void compile3D(); |
||||
}; |
||||
|
||||
VectorTest::VectorTest() { |
||||
addTests({&VectorTest::compile2D, |
||||
&VectorTest::compile3D}); |
||||
} |
||||
|
||||
void VectorTest::compile2D() { |
||||
Shaders::Vector2D shader; |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
void VectorTest::compile3D() { |
||||
Shaders::Vector3D shader; |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Shaders::Test::VectorTest) |
||||
@ -0,0 +1,55 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "Shaders/VertexColor.h" |
||||
#include "Test/AbstractOpenGLTester.h" |
||||
|
||||
namespace Magnum { namespace Shaders { namespace Test { |
||||
|
||||
class VertexColorTest: public Magnum::Test::AbstractOpenGLTester { |
||||
public: |
||||
explicit VertexColorTest(); |
||||
|
||||
void compile2D(); |
||||
void compile3D(); |
||||
}; |
||||
|
||||
VertexColorTest::VertexColorTest() { |
||||
addTests({&VertexColorTest::compile2D, |
||||
&VertexColorTest::compile3D}); |
||||
} |
||||
|
||||
void VertexColorTest::compile2D() { |
||||
Shaders::VertexColor2D shader; |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
void VertexColorTest::compile3D() { |
||||
Shaders::VertexColor3D shader; |
||||
CORRADE_VERIFY(shader.validate().first); |
||||
} |
||||
|
||||
}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Shaders::Test::VertexColorTest) |
||||
@ -0,0 +1,131 @@
|
||||
#ifndef Magnum_Shapes_Collision_h |
||||
#define Magnum_Shapes_Collision_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class @ref Magnum::Shapes::Collision |
||||
*/ |
||||
|
||||
#include "Math/Vector2.h" |
||||
#include "Math/Vector3.h" |
||||
#include "DimensionTraits.h" |
||||
|
||||
namespace Magnum { namespace Shapes { |
||||
|
||||
/**
|
||||
@brief %Collision data |
||||
|
||||
Contains information about collision between objects A and B, described by |
||||
contact position, separation normal and separation distance. |
||||
|
||||
If the collision occured, contact position is on object B surface, separation |
||||
normal is *normalized* vector in which direction should object A be moved to |
||||
separate the bodies, separation distance is positive and describes minimal |
||||
movement of object A in direction of separation normal after which the contact |
||||
position will no longer be colliding with object A. |
||||
|
||||
If the collision not occured, contact position and separation normal is |
||||
undefined (i.e., *not* normalized) and separation distance is negative or zero. |
||||
@see @ref Collision2D, @ref Collision3D |
||||
*/ |
||||
template<UnsignedInt dimensions> class Collision { |
||||
public: |
||||
/**
|
||||
* @brief Default constructor |
||||
* |
||||
* Sets position, normal and separation distance to zero, as if no |
||||
* collision happened. |
||||
*/ |
||||
/*implicit*/ Collision(): _separationDistance(0.0f) {} |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* |
||||
* If separation distance is positive, the separation normal is |
||||
* expected to be normalized. |
||||
*/ |
||||
explicit Collision(typename DimensionTraits<dimensions, Float>::VectorType position, typename DimensionTraits<dimensions, Float>::VectorType separationNormal, Float separationDistance) noexcept: _position(position), _separationNormal(separationNormal), _separationDistance(separationDistance) { |
||||
CORRADE_ASSERT(_separationDistance < Math::TypeTraits<Float>::epsilon() || separationNormal.isNormalized(), "Shapes::Collision::Collision: separation normal is not normalized", ); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Whether the collision happened |
||||
* |
||||
* Negative or zero separation distance means that no collision |
||||
* happened. |
||||
* @see @ref separationDistance() |
||||
*/ |
||||
operator bool() const { return _separationDistance > 0.0f; } |
||||
|
||||
/** @brief %Collision position */ |
||||
typename DimensionTraits<dimensions, Float>::VectorType position() const { |
||||
return _position; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Separation normal |
||||
* |
||||
* @see @ref separationDistance(), @ref flipped() |
||||
*/ |
||||
typename DimensionTraits<dimensions, Float>::VectorType separationNormal() const { |
||||
return _separationNormal; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Separation distance |
||||
* |
||||
* @see @ref separationNormal(), operator bool() |
||||
*/ |
||||
Float separationDistance() const { |
||||
return _separationDistance; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Flipped collision |
||||
* |
||||
* Returns new collision object as if the collision occured between |
||||
* flipped pair of objects, i.e. with flipped separation normal and |
||||
* contact position on surface of object A. |
||||
* @see @ref position(), @ref separationNormal() |
||||
*/ |
||||
Collision<dimensions> flipped() const { |
||||
return Collision<dimensions>(_position - _separationDistance*_separationNormal, -_separationNormal, _separationDistance); |
||||
} |
||||
|
||||
private: |
||||
typename DimensionTraits<dimensions, Float>::VectorType _position; |
||||
typename DimensionTraits<dimensions, Float>::VectorType _separationNormal; |
||||
Float _separationDistance; |
||||
}; |
||||
|
||||
/** @brief Two-dimensional collision data */ |
||||
typedef Collision<2> Collision2D; |
||||
|
||||
/** @brief Three-dimensional collision data */ |
||||
typedef Collision<3> Collision3D; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,61 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include <TestSuite/Tester.h> |
||||
|
||||
#include "Shapes/Collision.h" |
||||
#include "Magnum.h" |
||||
|
||||
namespace Magnum { namespace Shapes { namespace Test { |
||||
|
||||
class CollisionTest: public TestSuite::Tester { |
||||
public: |
||||
explicit CollisionTest(); |
||||
|
||||
void boolConversion(); |
||||
void flipped(); |
||||
}; |
||||
|
||||
CollisionTest::CollisionTest() { |
||||
addTests({&CollisionTest::boolConversion, |
||||
&CollisionTest::flipped}); |
||||
} |
||||
|
||||
void CollisionTest::boolConversion() { |
||||
CORRADE_VERIFY(!Collision3D()); |
||||
CORRADE_VERIFY(!Collision3D({}, {2.0f, 0.0f, 0.0f}, 0.0f)); |
||||
CORRADE_VERIFY(!Collision3D({}, {0.0f, 0.0f, 2.0f}, -0.1f)); |
||||
CORRADE_VERIFY(Collision3D({}, {0.0f, 1.0f, 0.0f}, 0.1f)); |
||||
} |
||||
|
||||
void CollisionTest::flipped() { |
||||
const auto flipped = Collision3D({-1.0f, 0.5f, 3.0f}, {1.0f, 0.0f, 0.0f}, 0.5f).flipped(); |
||||
CORRADE_COMPARE(flipped.position(), Vector3(-1.5f, 0.5f, 3.0f)); |
||||
CORRADE_COMPARE(flipped.separationNormal(), Vector3(-1.0f, 0.0f, 0.0f)); |
||||
CORRADE_COMPARE(flipped.separationDistance(), 0.5f); |
||||
} |
||||
|
||||
}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Shapes::Test::CollisionTest) |
||||
@ -0,0 +1,134 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "Test/AbstractOpenGLTester.h" |
||||
#include "Context.h" |
||||
#include <Extensions.h> |
||||
|
||||
namespace Magnum { namespace Test { |
||||
|
||||
class ContextTest: public AbstractOpenGLTester { |
||||
public: |
||||
explicit ContextTest(); |
||||
|
||||
void version(); |
||||
void versionList(); |
||||
void supportedExtension(); |
||||
void unsupportedExtension(); |
||||
void pastExtension(); |
||||
void versionDependentExtension(); |
||||
}; |
||||
|
||||
ContextTest::ContextTest() { |
||||
addTests({&ContextTest::version, |
||||
&ContextTest::versionList, |
||||
&ContextTest::supportedExtension, |
||||
&ContextTest::unsupportedExtension, |
||||
&ContextTest::pastExtension, |
||||
&ContextTest::versionDependentExtension}); |
||||
} |
||||
|
||||
void ContextTest::version() { |
||||
const Version v = Context::current()->version(); |
||||
CORRADE_VERIFY(Context::current()->isVersionSupported(v)); |
||||
CORRADE_VERIFY(Context::current()->isVersionSupported(Version(Int(v)-1))); |
||||
CORRADE_VERIFY(!Context::current()->isVersionSupported(Version(Int(v)+1))); |
||||
|
||||
/* No assertions should be fired */ |
||||
MAGNUM_ASSERT_VERSION_SUPPORTED(v); |
||||
MAGNUM_ASSERT_VERSION_SUPPORTED(Version(Int(v)-1)); |
||||
} |
||||
|
||||
void ContextTest::versionList() { |
||||
const Version v = Context::current()->version(); |
||||
|
||||
/* Selects first supported version (thus not necessarily the highest) */ |
||||
CORRADE_VERIFY(Context::current()->supportedVersion({Version(Int(v)+1), v, Version(Int(v)-1)}) == v); |
||||
CORRADE_VERIFY(Context::current()->supportedVersion({Version(Int(v)+1), Version(Int(v)-1), v}) == Version(Int(v)-1)); |
||||
} |
||||
|
||||
void ContextTest::supportedExtension() { |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::EXT::texture_filter_anisotropic>()) |
||||
CORRADE_SKIP(Extensions::GL::EXT::texture_filter_anisotropic::string() + std::string(" extension should be supported, can't test")); |
||||
|
||||
std::string extensions(reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))); |
||||
CORRADE_VERIFY(extensions.find(Extensions::GL::EXT::texture_filter_anisotropic::string()) != std::string::npos); |
||||
} |
||||
|
||||
void ContextTest::unsupportedExtension() { |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
if(Context::current()->isExtensionSupported<Extensions::GL::GREMEDY::string_marker>()) |
||||
CORRADE_SKIP(Extensions::GL::GREMEDY::string_marker::string() + std::string(" extension shouldn't be supported, can't test")); |
||||
|
||||
std::string extensions(reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))); |
||||
CORRADE_VERIFY(extensions.find(Extensions::GL::GREMEDY::string_marker::string()) == std::string::npos); |
||||
#elif !defined(CORRADE_TARGET_NACL) |
||||
if(Context::current()->isExtensionSupported<Extensions::GL::CHROMIUM::map_sub>()) |
||||
CORRADE_SKIP(Extensions::GL::CHROMIUM::map_sub::string() + std::string(" extension shouldn't be supported, can't test")); |
||||
|
||||
std::string extensions(reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))); |
||||
CORRADE_VERIFY(extensions.find(Extensions::GL::CHROMIUM::map_sub::string()) == std::string::npos); |
||||
#else |
||||
if(Context::current()->isExtensionSupported<Extensions::GL::NV::read_buffer_front>()) |
||||
CORRADE_SKIP(Extensions::GL::NV::read_buffer_front::string() + std::string(" extension shouldn't be supported, can't test")); |
||||
|
||||
std::string extensions(reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))); |
||||
CORRADE_VERIFY(extensions.find(Extensions::GL::NV::read_buffer_front::string()) == std::string::npos); |
||||
#endif |
||||
} |
||||
|
||||
void ContextTest::pastExtension() { |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
if(!Context::current()->isVersionSupported(Version::GL300)) |
||||
CORRADE_SKIP("No already supported extensions exist in OpenGL 2.1"); |
||||
|
||||
CORRADE_VERIFY(Context::current()->isExtensionSupported<Extensions::GL::APPLE::vertex_array_object>()); |
||||
/* No assertion should be fired */ |
||||
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::APPLE::vertex_array_object); |
||||
#else |
||||
if(!Context::current()->isVersionSupported(Version::GLES300)) |
||||
CORRADE_SKIP("No already supported extensions exist in OpenGL ES 2.0"); |
||||
|
||||
CORRADE_VERIFY(Context::current()->isExtensionSupported<Extensions::GL::EXT::texture_rg>()); |
||||
/* No assertion should be fired */ |
||||
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::texture_rg); |
||||
#endif |
||||
} |
||||
|
||||
void ContextTest::versionDependentExtension() { |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
CORRADE_COMPARE(Extensions::GL::ARB::get_program_binary::requiredVersion(), Version::GL300); |
||||
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::get_program_binary>()) |
||||
CORRADE_SKIP(Extensions::GL::ARB::get_program_binary::string() + std::string("extension isn't supported, can't test")); |
||||
|
||||
CORRADE_VERIFY(Context::current()->isExtensionSupported<Extensions::GL::ARB::get_program_binary>(Context::current()->version())); |
||||
CORRADE_VERIFY(!Context::current()->isExtensionSupported<Extensions::GL::ARB::get_program_binary>(Version::GL210)); |
||||
#else |
||||
CORRADE_SKIP("No OpenGL ES 3.0-only extensions exist yet"); |
||||
#endif |
||||
} |
||||
|
||||
}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Test::ContextTest) |
||||
Loading…
Reference in new issue