Browse Source

Shaders: assert texturing is enabled when calling Flat::bindTexture().

pull/268/head
Vladimír Vondruš 8 years ago
parent
commit
5201176cdb
  1. 4
      doc/changelog.dox
  2. 2
      src/Magnum/Shaders/CMakeLists.txt
  3. 4
      src/Magnum/Shaders/Flat.cpp
  4. 3
      src/Magnum/Shaders/Flat.h
  5. 2
      src/Magnum/Shaders/Test/CMakeLists.txt
  6. 49
      src/Magnum/Shaders/Test/FlatGLTest.cpp

4
doc/changelog.dox

@ -155,7 +155,7 @@ See also:
@subsubsection changelog-latest-changes-shaders Shaders library @subsubsection changelog-latest-changes-shaders Shaders library
- @ref Shaders::Phong::bindAmbientTexture(), - @ref Shaders::Flat::bindTexture(), @ref Shaders::Phong::bindAmbientTexture(),
@ref Shaders::Phong::bindDiffuseTexture(), @ref Shaders::Phong::bindDiffuseTexture(),
@ref Shaders::Phong::bindSpecularTexture() and @ref Shaders::Phong::bindSpecularTexture() and
@ref Shaders::Phong::bindTextures() now assert that the shader was created @ref Shaders::Phong::bindTextures() now assert that the shader was created
@ -254,7 +254,7 @@ See also:
working to fail with an assertion. See the new working to fail with an assertion. See the new
@ref Math::Matrix3::rotationShear() and @ref Math::Matrix4::rotationShear() @ref Math::Matrix3::rotationShear() and @ref Math::Matrix4::rotationShear()
accessors for a possible solution. accessors for a possible solution.
- @ref Shaders::Phong::bindAmbientTexture(), - @ref Shaders::Flat::bindTexture(), @ref Shaders::Phong::bindAmbientTexture(),
@ref Shaders::Phong::bindDiffuseTexture(), @ref Shaders::Phong::bindDiffuseTexture(),
@ref Shaders::Phong::bindSpecularTexture() and @ref Shaders::Phong::bindSpecularTexture() and
@ref Shaders::Phong::bindTextures() now assert that the shader was created @ref Shaders::Phong::bindTextures() now assert that the shader was created

2
src/Magnum/Shaders/CMakeLists.txt

@ -29,7 +29,6 @@ set_target_properties(MagnumShaders_RCS-dependencies PROPERTIES FOLDER "Magnum/S
set(MagnumShaders_SRCS set(MagnumShaders_SRCS
AbstractVector.cpp AbstractVector.cpp
DistanceFieldVector.cpp DistanceFieldVector.cpp
Flat.cpp
MeshVisualizer.cpp MeshVisualizer.cpp
Vector.cpp Vector.cpp
VertexColor.cpp VertexColor.cpp
@ -37,6 +36,7 @@ set(MagnumShaders_SRCS
${MagnumShaders_RCS}) ${MagnumShaders_RCS})
set(MagnumShaders_GracefulAssert_SRCS set(MagnumShaders_GracefulAssert_SRCS
Flat.cpp
Phong.cpp) Phong.cpp)
set(MagnumShaders_HEADERS set(MagnumShaders_HEADERS

4
src/Magnum/Shaders/Flat.cpp

@ -106,7 +106,9 @@ template<UnsignedInt dimensions> Flat<dimensions>::Flat(const Flags flags): _fla
} }
template<UnsignedInt dimensions> Flat<dimensions>& Flat<dimensions>::bindTexture(GL::Texture2D& texture) { template<UnsignedInt dimensions> Flat<dimensions>& Flat<dimensions>::bindTexture(GL::Texture2D& texture) {
if(_flags & Flag::Textured) texture.bind(TextureLayer); CORRADE_ASSERT(_flags & Flag::Textured,
"Shaders::Flat::bindTexture(): the shader was not created with texturing enabled", *this);
texture.bind(TextureLayer);
return *this; return *this;
} }

3
src/Magnum/Shaders/Flat.h

@ -186,7 +186,8 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Flat: public GL::Ab
* @brief Bind texture * @brief Bind texture
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Has effect only if @ref Flag::Textured is set. * Expects that the shader was created with @ref Flag::Textured
* enabled.
* @see @ref setColor() * @see @ref setColor()
*/ */
Flat<dimensions>& bindTexture(GL::Texture2D& texture); Flat<dimensions>& bindTexture(GL::Texture2D& texture);

2
src/Magnum/Shaders/Test/CMakeLists.txt

@ -41,7 +41,7 @@ set_target_properties(
if(BUILD_GL_TESTS) if(BUILD_GL_TESTS)
corrade_add_test(ShadersDistanceFieldVectorGLTest DistanceFieldVectorGLTest.cpp LIBRARIES MagnumShaders MagnumOpenGLTester) corrade_add_test(ShadersDistanceFieldVectorGLTest DistanceFieldVectorGLTest.cpp LIBRARIES MagnumShaders MagnumOpenGLTester)
corrade_add_test(ShadersFlatGLTest FlatGLTest.cpp LIBRARIES MagnumShaders MagnumOpenGLTester) corrade_add_test(ShadersFlatGLTest FlatGLTest.cpp LIBRARIES MagnumShadersTestLib MagnumOpenGLTester)
corrade_add_test(ShadersMeshVisualizerGLTest MeshVisualizerGLTest.cpp LIBRARIES MagnumShaders MagnumOpenGLTester) corrade_add_test(ShadersMeshVisualizerGLTest MeshVisualizerGLTest.cpp LIBRARIES MagnumShaders MagnumOpenGLTester)
corrade_add_test(ShadersPhongGLTest PhongGLTest.cpp LIBRARIES MagnumShadersTestLib MagnumOpenGLTester) corrade_add_test(ShadersPhongGLTest PhongGLTest.cpp LIBRARIES MagnumShadersTestLib MagnumOpenGLTester)
corrade_add_test(ShadersVectorGLTest VectorGLTest.cpp LIBRARIES MagnumShaders MagnumOpenGLTester) corrade_add_test(ShadersVectorGLTest VectorGLTest.cpp LIBRARIES MagnumShaders MagnumOpenGLTester)

49
src/Magnum/Shaders/Test/FlatGLTest.cpp

@ -23,8 +23,13 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
#include <sstream>
#include <Corrade/Utility/Format.h> #include <Corrade/Utility/Format.h>
#include "Magnum/ImageView.h"
#include "Magnum/PixelFormat.h"
#include "Magnum/GL/Texture.h"
#include "Magnum/GL/TextureFormat.h"
#include "Magnum/GL/OpenGLTester.h" #include "Magnum/GL/OpenGLTester.h"
#include "Magnum/Shaders/Flat.h" #include "Magnum/Shaders/Flat.h"
@ -36,6 +41,9 @@ struct FlatGLTest: GL::OpenGLTester {
template<UnsignedInt dimensions> void construct(); template<UnsignedInt dimensions> void construct();
template<UnsignedInt dimensions> void constructMove(); template<UnsignedInt dimensions> void constructMove();
template<UnsignedInt dimensions> void bindTexture();
template<UnsignedInt dimensions> void bindTextureNotEnabled();
}; };
namespace { namespace {
@ -58,7 +66,12 @@ FlatGLTest::FlatGLTest() {
addTests<FlatGLTest>({ addTests<FlatGLTest>({
&FlatGLTest::constructMove<2>, &FlatGLTest::constructMove<2>,
&FlatGLTest::constructMove<3>}); &FlatGLTest::constructMove<3>,
&FlatGLTest::bindTexture<2>,
&FlatGLTest::bindTexture<3>,
&FlatGLTest::bindTextureNotEnabled<2>,
&FlatGLTest::bindTextureNotEnabled<3>});
} }
template<UnsignedInt dimensions> void FlatGLTest::construct() { template<UnsignedInt dimensions> void FlatGLTest::construct() {
@ -96,6 +109,40 @@ template<UnsignedInt dimensions> void FlatGLTest::constructMove() {
CORRADE_VERIFY(!b.id()); CORRADE_VERIFY(!b.id());
} }
template<UnsignedInt dimensions> void FlatGLTest::bindTexture() {
setTestCaseName(Utility::formatString("bindTexture<{}>", dimensions));
char data[4];
GL::Texture2D texture;
texture
.setMinificationFilter(SamplerFilter::Linear, SamplerMipmap::Linear)
.setMagnificationFilter(SamplerFilter::Linear)
.setWrapping(SamplerWrapping::ClampToEdge)
.setImage(0, GL::TextureFormat::RGBA, ImageView2D{PixelFormat::RGBA8Unorm, {1, 1}, data});
MAGNUM_VERIFY_NO_GL_ERROR();
/* Test just that no assertion is fired */
Flat<dimensions> shader{Flat<dimensions>::Flag::Textured};
shader.bindTexture(texture);
MAGNUM_VERIFY_NO_GL_ERROR();
}
template<UnsignedInt dimensions> void FlatGLTest::bindTextureNotEnabled() {
setTestCaseName(Utility::formatString("bindTextureNotEnabled<{}>", dimensions));
std::ostringstream out;
Error redirectError{&out};
GL::Texture2D texture;
Flat<dimensions> shader;
shader.bindTexture(texture);
CORRADE_COMPARE(out.str(), "Shaders::Flat::bindTexture(): the shader was not created with texturing enabled\n");
}
}}} }}}
CORRADE_TEST_MAIN(Magnum::Shaders::Test::FlatGLTest) CORRADE_TEST_MAIN(Magnum::Shaders::Test::FlatGLTest)

Loading…
Cancel
Save