|
|
|
|
@ -24,15 +24,35 @@
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include <sstream> |
|
|
|
|
#include <Corrade/Containers/Optional.h> |
|
|
|
|
#include <Corrade/Containers/StridedArrayView.h> |
|
|
|
|
#include <Corrade/PluginManager/Manager.h> |
|
|
|
|
#include <Corrade/Utility/DebugStl.h> |
|
|
|
|
#include <Corrade/Utility/Directory.h> |
|
|
|
|
#include <Corrade/Utility/FormatStl.h> |
|
|
|
|
|
|
|
|
|
#include "Magnum/Image.h" |
|
|
|
|
#include "Magnum/ImageView.h" |
|
|
|
|
#include "Magnum/PixelFormat.h" |
|
|
|
|
#include "Magnum/DebugTools/CompareImage.h" |
|
|
|
|
#include "Magnum/GL/Mesh.h" |
|
|
|
|
#include "Magnum/GL/Framebuffer.h" |
|
|
|
|
#include "Magnum/GL/Renderer.h" |
|
|
|
|
#include "Magnum/GL/Renderbuffer.h" |
|
|
|
|
#include "Magnum/GL/RenderbufferFormat.h" |
|
|
|
|
#include "Magnum/GL/Texture.h" |
|
|
|
|
#include "Magnum/GL/TextureFormat.h" |
|
|
|
|
#include "Magnum/GL/OpenGLTester.h" |
|
|
|
|
#include "Magnum/MeshTools/Compile.h" |
|
|
|
|
#include "Magnum/Primitives/Circle.h" |
|
|
|
|
#include "Magnum/Primitives/UVSphere.h" |
|
|
|
|
#include "Magnum/Shaders/Flat.h" |
|
|
|
|
#include "Magnum/Trade/AbstractImporter.h" |
|
|
|
|
#include "Magnum/Trade/ImageData.h" |
|
|
|
|
#include "Magnum/Trade/MeshData2D.h" |
|
|
|
|
#include "Magnum/Trade/MeshData3D.h" |
|
|
|
|
|
|
|
|
|
#include "configure.h" |
|
|
|
|
|
|
|
|
|
namespace Magnum { namespace Shaders { namespace Test { namespace { |
|
|
|
|
|
|
|
|
|
@ -48,8 +68,34 @@ struct FlatGLTest: GL::OpenGLTester {
|
|
|
|
|
|
|
|
|
|
template<UnsignedInt dimensions> void setAlphaMask(); |
|
|
|
|
template<UnsignedInt dimensions> void setAlphaMaskNotEnabled(); |
|
|
|
|
|
|
|
|
|
void renderSetup(); |
|
|
|
|
void renderTeardown(); |
|
|
|
|
|
|
|
|
|
void renderDefaults2D(); |
|
|
|
|
void renderDefaults3D(); |
|
|
|
|
void renderColored2D(); |
|
|
|
|
void renderColored3D(); |
|
|
|
|
void renderSinglePixelTextured2D(); |
|
|
|
|
void renderSinglePixelTextured3D(); |
|
|
|
|
void renderTextured2D(); |
|
|
|
|
void renderTextured3D(); |
|
|
|
|
|
|
|
|
|
void renderAlphaSetup(); |
|
|
|
|
void renderAlphaTeardown(); |
|
|
|
|
|
|
|
|
|
void renderAlpha2D(); |
|
|
|
|
void renderAlpha3D(); |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
PluginManager::Manager<Trade::AbstractImporter> _manager{"nonexistent"}; |
|
|
|
|
|
|
|
|
|
GL::Renderbuffer _color{NoCreate}, _depth{NoCreate}; |
|
|
|
|
GL::Framebuffer _framebuffer{NoCreate}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
using namespace Math::Literals; |
|
|
|
|
|
|
|
|
|
constexpr struct { |
|
|
|
|
const char* name; |
|
|
|
|
Flat2D::Flags flags; |
|
|
|
|
@ -58,6 +104,28 @@ constexpr struct {
|
|
|
|
|
{"textured", Flat2D::Flag::Textured} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const struct { |
|
|
|
|
const char* name; |
|
|
|
|
const char* expected2D; |
|
|
|
|
const char* expected3D; |
|
|
|
|
bool blending; |
|
|
|
|
Flat2D::Flags flags; |
|
|
|
|
Float threshold; |
|
|
|
|
} RenderAlphaData[] { |
|
|
|
|
/* All those deliberately have a non-white diffuse in order to match the
|
|
|
|
|
expected data from textured() */ |
|
|
|
|
{"none", "FlatTestFiles/textured2D.tga", "FlatTestFiles/textured3D.tga", false, |
|
|
|
|
Flat2D::Flag::Textured, 0.0f}, |
|
|
|
|
{"blending", "FlatTestFiles/textured2D-alpha.tga", "FlatTestFiles/textured3D-alpha.tga", true, |
|
|
|
|
Flat2D::Flag::Textured, 0.0f}, |
|
|
|
|
{"masking 0.0", "FlatTestFiles/textured2D.tga", "FlatTestFiles/textured3D.tga", false, |
|
|
|
|
Flat2D::Flag::Textured, 0.0f}, |
|
|
|
|
{"masking 0.5", "FlatTestFiles/textured2D-alpha-mask0.5.tga", "FlatTestFiles/textured3D-alpha-mask0.5.tga", false, |
|
|
|
|
Flat2D::Flag::Textured|Flat2D::Flag::AlphaMask, 0.5f}, |
|
|
|
|
{"masking 1.0", "TestFiles/alpha-mask1.0.tga", "TestFiles/alpha-mask1.0.tga", false, |
|
|
|
|
Flat2D::Flag::Textured|Flat2D::Flag::AlphaMask, 1.0f} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
FlatGLTest::FlatGLTest() { |
|
|
|
|
addInstancedTests<FlatGLTest>({ |
|
|
|
|
&FlatGLTest::construct<2>, |
|
|
|
|
@ -77,6 +145,32 @@ FlatGLTest::FlatGLTest() {
|
|
|
|
|
&FlatGLTest::setAlphaMask<3>, |
|
|
|
|
&FlatGLTest::setAlphaMaskNotEnabled<2>, |
|
|
|
|
&FlatGLTest::setAlphaMaskNotEnabled<3>}); |
|
|
|
|
|
|
|
|
|
addTests({&FlatGLTest::renderDefaults2D, |
|
|
|
|
&FlatGLTest::renderDefaults3D, |
|
|
|
|
&FlatGLTest::renderColored2D, |
|
|
|
|
&FlatGLTest::renderColored3D, |
|
|
|
|
&FlatGLTest::renderSinglePixelTextured2D, |
|
|
|
|
&FlatGLTest::renderSinglePixelTextured3D, |
|
|
|
|
&FlatGLTest::renderTextured2D, |
|
|
|
|
&FlatGLTest::renderTextured3D}, |
|
|
|
|
&FlatGLTest::renderSetup, |
|
|
|
|
&FlatGLTest::renderTeardown); |
|
|
|
|
|
|
|
|
|
addInstancedTests({&FlatGLTest::renderAlpha2D, |
|
|
|
|
&FlatGLTest::renderAlpha3D}, |
|
|
|
|
Containers::arraySize(RenderAlphaData), |
|
|
|
|
&FlatGLTest::renderAlphaSetup, |
|
|
|
|
&FlatGLTest::renderAlphaTeardown); |
|
|
|
|
|
|
|
|
|
/* Load the plugins directly from the build tree. Otherwise they're either
|
|
|
|
|
static and already loaded or not present in the build tree */ |
|
|
|
|
#ifdef ANYIMAGEIMPORTER_PLUGIN_FILENAME |
|
|
|
|
CORRADE_INTERNAL_ASSERT(_manager.load(ANYIMAGEIMPORTER_PLUGIN_FILENAME) & PluginManager::LoadState::Loaded); |
|
|
|
|
#endif |
|
|
|
|
#ifdef TGAIMPORTER_PLUGIN_FILENAME |
|
|
|
|
CORRADE_INTERNAL_ASSERT(_manager.load(TGAIMPORTER_PLUGIN_FILENAME) & PluginManager::LoadState::Loaded); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template<UnsignedInt dimensions> void FlatGLTest::construct() { |
|
|
|
|
@ -174,6 +268,390 @@ template<UnsignedInt dimensions> void FlatGLTest::setAlphaMaskNotEnabled() {
|
|
|
|
|
"Shaders::Flat::setAlphaMask(): the shader was not created with alpha mask enabled\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
constexpr Vector2i RenderSize{80, 80}; |
|
|
|
|
|
|
|
|
|
void FlatGLTest::renderSetup() { |
|
|
|
|
/* Pick a color that's directly representable on RGBA4 as well to reduce
|
|
|
|
|
artifacts */ |
|
|
|
|
GL::Renderer::setClearColor(0x111111_rgbf); |
|
|
|
|
GL::Renderer::enable(GL::Renderer::Feature::FaceCulling); |
|
|
|
|
|
|
|
|
|
_color = GL::Renderbuffer{}; |
|
|
|
|
_color.setStorage( |
|
|
|
|
#if !defined(MAGNUM_TARGET_GLES2) || !defined(MAGNUM_TARGET_WEBGL) |
|
|
|
|
GL::RenderbufferFormat::RGBA8, |
|
|
|
|
#else |
|
|
|
|
GL::RenderbufferFormat::RGBA4, |
|
|
|
|
#endif |
|
|
|
|
RenderSize); |
|
|
|
|
_framebuffer = GL::Framebuffer{{{}, RenderSize}}; |
|
|
|
|
_framebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, _color) |
|
|
|
|
.clear(GL::FramebufferClear::Color) |
|
|
|
|
.bind(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FlatGLTest::renderTeardown() { |
|
|
|
|
_color = GL::Renderbuffer{NoCreate}; |
|
|
|
|
_framebuffer = GL::Framebuffer{NoCreate}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FlatGLTest::renderDefaults2D() { |
|
|
|
|
GL::Mesh circle = MeshTools::compile(Primitives::circle2DSolid(32)); |
|
|
|
|
|
|
|
|
|
Flat2D shader; |
|
|
|
|
circle.draw(shader); |
|
|
|
|
|
|
|
|
|
MAGNUM_VERIFY_NO_GL_ERROR(); |
|
|
|
|
|
|
|
|
|
if(!(_manager.loadState("AnyImageImporter") & PluginManager::LoadState::Loaded) || |
|
|
|
|
!(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded)) |
|
|
|
|
CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found."); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE_WITH( |
|
|
|
|
/* Dropping the alpha channel, as it's always 1.0 */ |
|
|
|
|
Containers::arrayCast<Color3ub>(_framebuffer.read(_framebuffer.viewport(), {PixelFormat::RGBA8Unorm}).pixels<Color4ub>()), |
|
|
|
|
Utility::Directory::join(SHADERS_TEST_DIR, "FlatTestFiles/defaults.tga"), |
|
|
|
|
(DebugTools::CompareImageToFile{_manager, 0.0f, 0.0f})); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FlatGLTest::renderDefaults3D() { |
|
|
|
|
GL::Mesh sphere = MeshTools::compile(Primitives::uvSphereSolid(16, 32)); |
|
|
|
|
|
|
|
|
|
Flat3D shader; |
|
|
|
|
sphere.draw(shader); |
|
|
|
|
|
|
|
|
|
MAGNUM_VERIFY_NO_GL_ERROR(); |
|
|
|
|
|
|
|
|
|
if(!(_manager.loadState("AnyImageImporter") & PluginManager::LoadState::Loaded) || |
|
|
|
|
!(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded)) |
|
|
|
|
CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found."); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE_WITH( |
|
|
|
|
/* Dropping the alpha channel, as it's always 1.0 */ |
|
|
|
|
Containers::arrayCast<Color3ub>(_framebuffer.read(_framebuffer.viewport(), {PixelFormat::RGBA8Unorm}).pixels<Color4ub>()), |
|
|
|
|
Utility::Directory::join(SHADERS_TEST_DIR, "FlatTestFiles/defaults.tga"), |
|
|
|
|
(DebugTools::CompareImageToFile{_manager, 0.0f, 0.0f})); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FlatGLTest::renderColored2D() { |
|
|
|
|
GL::Mesh circle = MeshTools::compile(Primitives::circle2DSolid(32)); |
|
|
|
|
|
|
|
|
|
Flat2D shader; |
|
|
|
|
shader.setColor(0x9999ff_rgbf) |
|
|
|
|
.setTransformationProjectionMatrix(Matrix3::projection({2.1f, 2.1f})); |
|
|
|
|
|
|
|
|
|
circle.draw(shader); |
|
|
|
|
|
|
|
|
|
MAGNUM_VERIFY_NO_GL_ERROR(); |
|
|
|
|
|
|
|
|
|
if(!(_manager.loadState("AnyImageImporter") & PluginManager::LoadState::Loaded) || |
|
|
|
|
!(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded)) |
|
|
|
|
CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found."); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE_WITH( |
|
|
|
|
/* Dropping the alpha channel, as it's always 1.0 */ |
|
|
|
|
Containers::arrayCast<Color3ub>(_framebuffer.read(_framebuffer.viewport(), {PixelFormat::RGBA8Unorm}).pixels<Color4ub>()), |
|
|
|
|
Utility::Directory::join(SHADERS_TEST_DIR, "FlatTestFiles/colored2D.tga"), |
|
|
|
|
(DebugTools::CompareImageToFile{_manager, 0.0f, 0.0f})); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FlatGLTest::renderColored3D() { |
|
|
|
|
GL::Mesh sphere = MeshTools::compile(Primitives::uvSphereSolid(16, 32)); |
|
|
|
|
|
|
|
|
|
Flat3D shader; |
|
|
|
|
shader.setColor(0x9999ff_rgbf) |
|
|
|
|
.setTransformationProjectionMatrix( |
|
|
|
|
Matrix4::perspectiveProjection(60.0_degf, 1.0f, 0.1f, 10.0f)* |
|
|
|
|
Matrix4::translation(Vector3::zAxis(-2.15f))* |
|
|
|
|
Matrix4::rotationY(-15.0_degf)* |
|
|
|
|
Matrix4::rotationX(15.0_degf)); |
|
|
|
|
|
|
|
|
|
sphere.draw(shader); |
|
|
|
|
|
|
|
|
|
MAGNUM_VERIFY_NO_GL_ERROR(); |
|
|
|
|
|
|
|
|
|
if(!(_manager.loadState("AnyImageImporter") & PluginManager::LoadState::Loaded) || |
|
|
|
|
!(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded)) |
|
|
|
|
CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found."); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE_WITH( |
|
|
|
|
/* Dropping the alpha channel, as it's always 1.0 */ |
|
|
|
|
Containers::arrayCast<Color3ub>(_framebuffer.read(_framebuffer.viewport(), {PixelFormat::RGBA8Unorm}).pixels<Color4ub>()), |
|
|
|
|
Utility::Directory::join(SHADERS_TEST_DIR, "FlatTestFiles/colored3D.tga"), |
|
|
|
|
(DebugTools::CompareImageToFile{_manager, 0.0f, 0.0f})); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
constexpr GL::TextureFormat TextureFormatRGB = |
|
|
|
|
#if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL)) |
|
|
|
|
GL::TextureFormat::RGB8 |
|
|
|
|
#else |
|
|
|
|
GL::TextureFormat::RGB |
|
|
|
|
#endif |
|
|
|
|
; |
|
|
|
|
constexpr GL::TextureFormat TextureFormatRGBA = |
|
|
|
|
#if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL)) |
|
|
|
|
GL::TextureFormat::RGBA8 |
|
|
|
|
#else |
|
|
|
|
GL::TextureFormat::RGBA |
|
|
|
|
#endif |
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
void FlatGLTest::renderSinglePixelTextured2D() { |
|
|
|
|
GL::Mesh circle = MeshTools::compile(Primitives::circle2DSolid(32, |
|
|
|
|
Primitives::CircleTextureCoords::Generate)); |
|
|
|
|
|
|
|
|
|
const Color4ub diffuseData[]{ 0x9999ff_rgb }; |
|
|
|
|
ImageView2D diffuseImage{PixelFormat::RGBA8Unorm, Vector2i{1}, diffuseData}; |
|
|
|
|
GL::Texture2D texture; |
|
|
|
|
texture.setMinificationFilter(GL::SamplerFilter::Linear) |
|
|
|
|
.setMagnificationFilter(GL::SamplerFilter::Linear) |
|
|
|
|
.setWrapping(GL::SamplerWrapping::ClampToEdge) |
|
|
|
|
.setStorage(1, TextureFormatRGBA, Vector2i{1}) |
|
|
|
|
.setSubImage(0, {}, diffuseImage); |
|
|
|
|
|
|
|
|
|
Flat2D shader{Flat3D::Flag::Textured}; |
|
|
|
|
shader.setTransformationProjectionMatrix(Matrix3::projection({2.1f, 2.1f})) |
|
|
|
|
.bindTexture(texture); |
|
|
|
|
circle.draw(shader); |
|
|
|
|
|
|
|
|
|
MAGNUM_VERIFY_NO_GL_ERROR(); |
|
|
|
|
|
|
|
|
|
if(!(_manager.loadState("AnyImageImporter") & PluginManager::LoadState::Loaded) || |
|
|
|
|
!(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded)) |
|
|
|
|
CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found."); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE_WITH( |
|
|
|
|
/* Dropping the alpha channel, as it's always 1.0 */ |
|
|
|
|
Containers::arrayCast<Color3ub>(_framebuffer.read(_framebuffer.viewport(), {PixelFormat::RGBA8Unorm}).pixels<Color4ub>()), |
|
|
|
|
Utility::Directory::join(SHADERS_TEST_DIR, "FlatTestFiles/colored2D.tga"), |
|
|
|
|
(DebugTools::CompareImageToFile{_manager, 0.0f, 0.0f})); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FlatGLTest::renderSinglePixelTextured3D() { |
|
|
|
|
GL::Mesh sphere = MeshTools::compile(Primitives::uvSphereSolid(16, 32, |
|
|
|
|
Primitives::UVSphereTextureCoords::Generate)); |
|
|
|
|
|
|
|
|
|
const Color4ub diffuseData[]{ 0x9999ff_rgb }; |
|
|
|
|
ImageView2D diffuseImage{PixelFormat::RGBA8Unorm, Vector2i{1}, diffuseData}; |
|
|
|
|
GL::Texture2D texture; |
|
|
|
|
texture.setMinificationFilter(GL::SamplerFilter::Linear) |
|
|
|
|
.setMagnificationFilter(GL::SamplerFilter::Linear) |
|
|
|
|
.setWrapping(GL::SamplerWrapping::ClampToEdge) |
|
|
|
|
.setStorage(1, TextureFormatRGBA, Vector2i{1}) |
|
|
|
|
.setSubImage(0, {}, diffuseImage); |
|
|
|
|
|
|
|
|
|
Flat3D shader{Flat3D::Flag::Textured}; |
|
|
|
|
shader.setTransformationProjectionMatrix( |
|
|
|
|
Matrix4::perspectiveProjection(60.0_degf, 1.0f, 0.1f, 10.0f)* |
|
|
|
|
Matrix4::translation(Vector3::zAxis(-2.15f))* |
|
|
|
|
Matrix4::rotationY(-15.0_degf)* |
|
|
|
|
Matrix4::rotationX(15.0_degf)) |
|
|
|
|
.bindTexture(texture); |
|
|
|
|
sphere.draw(shader); |
|
|
|
|
|
|
|
|
|
MAGNUM_VERIFY_NO_GL_ERROR(); |
|
|
|
|
|
|
|
|
|
if(!(_manager.loadState("AnyImageImporter") & PluginManager::LoadState::Loaded) || |
|
|
|
|
!(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded)) |
|
|
|
|
CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found."); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE_WITH( |
|
|
|
|
/* Dropping the alpha channel, as it's always 1.0 */ |
|
|
|
|
Containers::arrayCast<Color3ub>(_framebuffer.read(_framebuffer.viewport(), {PixelFormat::RGBA8Unorm}).pixels<Color4ub>()), |
|
|
|
|
Utility::Directory::join(SHADERS_TEST_DIR, "FlatTestFiles/colored3D.tga"), |
|
|
|
|
(DebugTools::CompareImageToFile{_manager, 0.0f, 0.0f})); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FlatGLTest::renderTextured2D() { |
|
|
|
|
if(!(_manager.loadState("AnyImageImporter") & PluginManager::LoadState::Loaded) || |
|
|
|
|
!(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded)) |
|
|
|
|
CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found."); |
|
|
|
|
|
|
|
|
|
GL::Mesh circle = MeshTools::compile(Primitives::circle2DSolid(32, |
|
|
|
|
Primitives::CircleTextureCoords::Generate)); |
|
|
|
|
|
|
|
|
|
Containers::Pointer<Trade::AbstractImporter> importer = _manager.loadAndInstantiate("AnyImageImporter"); |
|
|
|
|
CORRADE_VERIFY(importer); |
|
|
|
|
|
|
|
|
|
GL::Texture2D texture; |
|
|
|
|
Containers::Optional<Trade::ImageData2D> image; |
|
|
|
|
CORRADE_VERIFY(importer->openFile(Utility::Directory::join(SHADERS_TEST_DIR, "TestFiles/diffuse-texture.tga")) && (image = importer->image2D(0))); |
|
|
|
|
texture.setMinificationFilter(GL::SamplerFilter::Linear) |
|
|
|
|
.setMagnificationFilter(GL::SamplerFilter::Linear) |
|
|
|
|
.setWrapping(GL::SamplerWrapping::ClampToEdge) |
|
|
|
|
.setStorage(1, TextureFormatRGB, image->size()) |
|
|
|
|
.setSubImage(0, {}, *image); |
|
|
|
|
|
|
|
|
|
Flat2D shader{Flat2D::Flag::Textured}; |
|
|
|
|
shader.setTransformationProjectionMatrix(Matrix3::projection({2.1f, 2.1f})) |
|
|
|
|
/* Colorized. Case without a color (where it should be white) is tested
|
|
|
|
|
in renderSinglePixelTextured() */ |
|
|
|
|
.setColor(0x9999ff_rgbf) |
|
|
|
|
.bindTexture(texture); |
|
|
|
|
circle.draw(shader); |
|
|
|
|
|
|
|
|
|
MAGNUM_VERIFY_NO_GL_ERROR(); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE_WITH( |
|
|
|
|
/* Dropping the alpha channel, as it's always 1.0 */ |
|
|
|
|
Containers::arrayCast<Color3ub>(_framebuffer.read(_framebuffer.viewport(), {PixelFormat::RGBA8Unorm}).pixels<Color4ub>()), |
|
|
|
|
Utility::Directory::join(SHADERS_TEST_DIR, "FlatTestFiles/textured2D.tga"), |
|
|
|
|
(DebugTools::CompareImageToFile{_manager, 0.0f, 0.0f})); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FlatGLTest::renderTextured3D() { |
|
|
|
|
if(!(_manager.loadState("AnyImageImporter") & PluginManager::LoadState::Loaded) || |
|
|
|
|
!(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded)) |
|
|
|
|
CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found."); |
|
|
|
|
|
|
|
|
|
GL::Mesh sphere = MeshTools::compile(Primitives::uvSphereSolid(16, 32, |
|
|
|
|
Primitives::UVSphereTextureCoords::Generate)); |
|
|
|
|
|
|
|
|
|
Containers::Pointer<Trade::AbstractImporter> importer = _manager.loadAndInstantiate("AnyImageImporter"); |
|
|
|
|
CORRADE_VERIFY(importer); |
|
|
|
|
|
|
|
|
|
GL::Texture2D texture; |
|
|
|
|
Containers::Optional<Trade::ImageData2D> image; |
|
|
|
|
CORRADE_VERIFY(importer->openFile(Utility::Directory::join(SHADERS_TEST_DIR, "TestFiles/diffuse-texture.tga")) && (image = importer->image2D(0))); |
|
|
|
|
texture.setMinificationFilter(GL::SamplerFilter::Linear) |
|
|
|
|
.setMagnificationFilter(GL::SamplerFilter::Linear) |
|
|
|
|
.setWrapping(GL::SamplerWrapping::ClampToEdge) |
|
|
|
|
.setStorage(1, TextureFormatRGB, image->size()) |
|
|
|
|
.setSubImage(0, {}, *image); |
|
|
|
|
|
|
|
|
|
Flat3D shader{Flat3D::Flag::Textured}; |
|
|
|
|
shader.setTransformationProjectionMatrix( |
|
|
|
|
Matrix4::perspectiveProjection(60.0_degf, 1.0f, 0.1f, 10.0f)* |
|
|
|
|
Matrix4::translation(Vector3::zAxis(-2.15f))* |
|
|
|
|
Matrix4::rotationY(-15.0_degf)* |
|
|
|
|
Matrix4::rotationX(15.0_degf)) |
|
|
|
|
/* Colorized. Case without a color (where it should be white) is tested
|
|
|
|
|
in renderSinglePixelTextured() */ |
|
|
|
|
.setColor(0x9999ff_rgbf) |
|
|
|
|
.bindTexture(texture); |
|
|
|
|
sphere.draw(shader); |
|
|
|
|
|
|
|
|
|
MAGNUM_VERIFY_NO_GL_ERROR(); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE_WITH( |
|
|
|
|
/* Dropping the alpha channel, as it's always 1.0 */ |
|
|
|
|
Containers::arrayCast<Color3ub>(_framebuffer.read(_framebuffer.viewport(), {PixelFormat::RGBA8Unorm}).pixels<Color4ub>()), |
|
|
|
|
Utility::Directory::join(SHADERS_TEST_DIR, "FlatTestFiles/textured3D.tga"), |
|
|
|
|
(DebugTools::CompareImageToFile{_manager, 0.0f, 0.0f})); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FlatGLTest::renderAlphaSetup() { |
|
|
|
|
renderSetup(); |
|
|
|
|
if(RenderAlphaData[testCaseInstanceId()].blending) |
|
|
|
|
GL::Renderer::enable(GL::Renderer::Feature::Blending); |
|
|
|
|
GL::Renderer::setBlendFunction(GL::Renderer::BlendFunction::SourceAlpha, GL::Renderer::BlendFunction::OneMinusSourceAlpha); |
|
|
|
|
GL::Renderer::setBlendEquation(GL::Renderer::BlendEquation::Add); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FlatGLTest::renderAlphaTeardown() { |
|
|
|
|
if(RenderAlphaData[testCaseInstanceId()].blending) |
|
|
|
|
GL::Renderer::disable(GL::Renderer::Feature::Blending); |
|
|
|
|
renderTeardown(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FlatGLTest::renderAlpha2D() { |
|
|
|
|
auto&& data = RenderAlphaData[testCaseInstanceId()]; |
|
|
|
|
setTestCaseDescription(data.name); |
|
|
|
|
|
|
|
|
|
if(!(_manager.loadState("AnyImageImporter") & PluginManager::LoadState::Loaded) || |
|
|
|
|
!(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded)) |
|
|
|
|
CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found."); |
|
|
|
|
|
|
|
|
|
Containers::Optional<Trade::ImageData2D> image; |
|
|
|
|
Containers::Pointer<Trade::AbstractImporter> importer = _manager.loadAndInstantiate("AnyImageImporter"); |
|
|
|
|
CORRADE_VERIFY(importer); |
|
|
|
|
|
|
|
|
|
GL::Texture2D texture; |
|
|
|
|
CORRADE_VERIFY(importer->openFile(Utility::Directory::join({SHADERS_TEST_DIR, "TestFiles", "diffuse-alpha-texture.tga"})) && (image = importer->image2D(0))); |
|
|
|
|
texture.setMinificationFilter(GL::SamplerFilter::Linear) |
|
|
|
|
.setMagnificationFilter(GL::SamplerFilter::Linear) |
|
|
|
|
.setWrapping(GL::SamplerWrapping::ClampToEdge) |
|
|
|
|
.setStorage(1, TextureFormatRGBA, image->size()) |
|
|
|
|
.setSubImage(0, {}, *image); |
|
|
|
|
|
|
|
|
|
MAGNUM_VERIFY_NO_GL_ERROR(); |
|
|
|
|
|
|
|
|
|
GL::Mesh circle = MeshTools::compile(Primitives::circle2DSolid(32, |
|
|
|
|
Primitives::CircleTextureCoords::Generate)); |
|
|
|
|
|
|
|
|
|
Flat2D shader{data.flags}; |
|
|
|
|
shader.setTransformationProjectionMatrix(Matrix3::projection({2.1f, 2.1f})) |
|
|
|
|
.setColor(0x9999ff_rgbf) |
|
|
|
|
.bindTexture(texture); |
|
|
|
|
|
|
|
|
|
if(data.flags & Flat3D::Flag::AlphaMask) |
|
|
|
|
shader.setAlphaMask(data.threshold); |
|
|
|
|
|
|
|
|
|
circle.draw(shader); |
|
|
|
|
|
|
|
|
|
MAGNUM_VERIFY_NO_GL_ERROR(); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE_WITH( |
|
|
|
|
/* Dropping the alpha channel, as it's always 1.0 */ |
|
|
|
|
Containers::arrayCast<Color3ub>(_framebuffer.read(_framebuffer.viewport(), {PixelFormat::RGBA8Unorm}).pixels<Color4ub>()), |
|
|
|
|
Utility::Directory::join(SHADERS_TEST_DIR, data.expected2D), |
|
|
|
|
/* Minor differences between opaque and diffuse, not sure why */ |
|
|
|
|
(DebugTools::CompareImageToFile{_manager, 24.34f, 0.290f})); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FlatGLTest::renderAlpha3D() { |
|
|
|
|
auto&& data = RenderAlphaData[testCaseInstanceId()]; |
|
|
|
|
setTestCaseDescription(data.name); |
|
|
|
|
|
|
|
|
|
if(!(_manager.loadState("AnyImageImporter") & PluginManager::LoadState::Loaded) || |
|
|
|
|
!(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded)) |
|
|
|
|
CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found."); |
|
|
|
|
|
|
|
|
|
Containers::Optional<Trade::ImageData2D> image; |
|
|
|
|
Containers::Pointer<Trade::AbstractImporter> importer = _manager.loadAndInstantiate("AnyImageImporter"); |
|
|
|
|
CORRADE_VERIFY(importer); |
|
|
|
|
|
|
|
|
|
GL::Texture2D texture; |
|
|
|
|
CORRADE_VERIFY(importer->openFile(Utility::Directory::join({SHADERS_TEST_DIR, "TestFiles", "diffuse-alpha-texture.tga"})) && (image = importer->image2D(0))); |
|
|
|
|
texture.setMinificationFilter(GL::SamplerFilter::Linear) |
|
|
|
|
.setMagnificationFilter(GL::SamplerFilter::Linear) |
|
|
|
|
.setWrapping(GL::SamplerWrapping::ClampToEdge) |
|
|
|
|
.setStorage(1, TextureFormatRGBA, image->size()) |
|
|
|
|
.setSubImage(0, {}, *image); |
|
|
|
|
|
|
|
|
|
MAGNUM_VERIFY_NO_GL_ERROR(); |
|
|
|
|
|
|
|
|
|
GL::Mesh sphere = MeshTools::compile(Primitives::uvSphereSolid(16, 32, |
|
|
|
|
Primitives::UVSphereTextureCoords::Generate)); |
|
|
|
|
|
|
|
|
|
Flat3D shader{data.flags}; |
|
|
|
|
shader.setTransformationProjectionMatrix( |
|
|
|
|
Matrix4::perspectiveProjection(60.0_degf, 1.0f, 0.1f, 10.0f)* |
|
|
|
|
Matrix4::translation(Vector3::zAxis(-2.15f))* |
|
|
|
|
Matrix4::rotationY(-15.0_degf)* |
|
|
|
|
Matrix4::rotationX(15.0_degf)) |
|
|
|
|
.setColor(0x9999ff_rgbf) |
|
|
|
|
.bindTexture(texture); |
|
|
|
|
|
|
|
|
|
if(data.flags & Flat3D::Flag::AlphaMask) |
|
|
|
|
shader.setAlphaMask(data.threshold); |
|
|
|
|
|
|
|
|
|
/* For proper Z order draw back faces first and then front faces */ |
|
|
|
|
GL::Renderer::setFaceCullingMode(GL::Renderer::PolygonFacing::Front); |
|
|
|
|
sphere.draw(shader); |
|
|
|
|
GL::Renderer::setFaceCullingMode(GL::Renderer::PolygonFacing::Back); |
|
|
|
|
sphere.draw(shader); |
|
|
|
|
|
|
|
|
|
MAGNUM_VERIFY_NO_GL_ERROR(); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE_WITH( |
|
|
|
|
/* Dropping the alpha channel, as it's always 1.0 */ |
|
|
|
|
Containers::arrayCast<Color3ub>(_framebuffer.read(_framebuffer.viewport(), {PixelFormat::RGBA8Unorm}).pixels<Color4ub>()), |
|
|
|
|
Utility::Directory::join({SHADERS_TEST_DIR, data.expected3D}), |
|
|
|
|
/* Minor differences between opaque and diffuse, not sure why */ |
|
|
|
|
(DebugTools::CompareImageToFile{_manager, 2.0f, 0.204f})); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}}}} |
|
|
|
|
|
|
|
|
|
CORRADE_TEST_MAIN(Magnum::Shaders::Test::FlatGLTest) |
|
|
|
|
|