Browse Source

TextureTools: accept only generic pixel formats in distancefieldcoverter.

pull/233/head
Vladimír Vondruš 8 years ago
parent
commit
112b9fd394
  1. 23
      src/Magnum/TextureTools/distancefieldconverter.cpp

23
src/Magnum/TextureTools/distancefieldconverter.cpp

@ -90,8 +90,8 @@ Arguments:
- `--magnum-...` --- engine-specific options (see - `--magnum-...` --- engine-specific options (see
@ref GL-Context-command-line for details) @ref GL-Context-command-line for details)
Images with @ref PixelFormat::Red, @ref PixelFormat::RGB or @ref PixelFormat::RGBA Images with @ref PixelFormat::R8Unorm, @ref PixelFormat::RGB8Unorm or
are accepted on input. @ref PixelFormat::RGBA8Unorm are accepted on input.
The resulting image can be then used with @ref Shaders::DistanceFieldVector The resulting image can be then used with @ref Shaders::DistanceFieldVector
shader. See also @ref TextureTools::distanceField() for more information about shader. See also @ref TextureTools::distanceField() for more information about
@ -160,9 +160,12 @@ int DistanceFieldConverter::exec() {
/* Decide about internal format */ /* Decide about internal format */
GL::TextureFormat internalFormat; GL::TextureFormat internalFormat;
if(image->format() == PixelFormat::Red) internalFormat = TextureFormat::R8; if(image->format() == PixelFormat::R8Unorm)
else if(image->format() == PixelFormat::RGB) internalFormat = TextureFormat::RGB8; internalFormat = GL::TextureFormat::R8;
else if(image->format() == PixelFormat::RGBA) internalFormat = TextureFormat::RGBA8; else if(image->format() == PixelFormat::RGB8Unorm)
internalFormat = GL::TextureFormat::RGB8;
else if(image->format() == PixelFormat::RGBA8Unorm)
internalFormat = GL::TextureFormat::RGBA8;
else { else {
Error() << "Unsupported image format" << image->format(); Error() << "Unsupported image format" << image->format();
return 4; return 4;
@ -170,15 +173,15 @@ int DistanceFieldConverter::exec() {
/* Input texture */ /* Input texture */
GL::Texture2D input; GL::Texture2D input;
input.setMinificationFilter(Sampler::Filter::Linear) input.setMinificationFilter(SamplerFilter::Linear)
.setMagnificationFilter(Sampler::Filter::Linear) .setMagnificationFilter(SamplerFilter::Linear)
.setWrapping(Sampler::Wrapping::ClampToEdge) .setWrapping(SamplerWrapping::ClampToEdge)
.setStorage(1, internalFormat, image->size()) .setStorage(1, internalFormat, image->size())
.setSubImage(0, {}, *image); .setSubImage(0, {}, *image);
/* Output texture */ /* Output texture */
GL::Texture2D output; GL::Texture2D output;
output.setStorage(1, TextureFormat::R8, args.value<Vector2i>("output-size")); output.setStorage(1, GL::TextureFormat::R8, args.value<Vector2i>("output-size"));
CORRADE_INTERNAL_ASSERT(GL::Renderer::error() == GL::Renderer::Error::NoError); CORRADE_INTERNAL_ASSERT(GL::Renderer::error() == GL::Renderer::Error::NoError);
@ -187,7 +190,7 @@ int DistanceFieldConverter::exec() {
TextureTools::distanceField(input, output, {{}, args.value<Vector2i>("output-size")}, args.value<Int>("radius"), image->size()); TextureTools::distanceField(input, output, {{}, args.value<Vector2i>("output-size")}, args.value<Int>("radius"), image->size());
/* Save image */ /* Save image */
Image2D result(PixelFormat::Red, PixelType::UnsignedByte); Image2D result{PixelFormat::R8Unorm};
output.image(0, result); output.image(0, result);
if(!converter->exportToFile(result, args.value("output"))) { if(!converter->exportToFile(result, args.value("output"))) {
Error() << "Cannot save file" << args.value("output"); Error() << "Cannot save file" << args.value("output");

Loading…
Cancel
Save