Browse Source

Use the new half/packed typedefs where appropriate.

Had this in a stash for a while, not sure why it wasn't commited
already.
pull/454/head
Vladimír Vondruš 6 years ago
parent
commit
d0fa28c331
  1. 20
      doc/snippets/MagnumMath.cpp
  2. 22
      src/Magnum/GL/Test/MeshGLTest.cpp

20
doc/snippets/MagnumMath.cpp

@ -716,7 +716,7 @@ if(!(b < a - epsilon || a + epsilon < b)) {
{ {
/* [Color3-fromSrgb] */ /* [Color3-fromSrgb] */
Math::Vector3<UnsignedByte> srgb; Vector3ub srgb;
auto rgb = Color3::fromSrgb(srgb); auto rgb = Color3::fromSrgb(srgb);
/* [Color3-fromSrgb] */ /* [Color3-fromSrgb] */
static_cast<void>(rgb); static_cast<void>(rgb);
@ -744,7 +744,7 @@ static_cast<void>(bFromSrgb);
{ {
/* [Color3-toSrgb] */ /* [Color3-toSrgb] */
Color3 color; Color3 color;
Math::Vector3<UnsignedByte> srgb = color.toSrgb<UnsignedByte>(); Vector3ub srgb = color.toSrgb<UnsignedByte>();
/* [Color3-toSrgb] */ /* [Color3-toSrgb] */
static_cast<void>(srgb); static_cast<void>(srgb);
} }
@ -761,7 +761,7 @@ static_cast<void>(bSrgb);
{ {
/* [Color4-fromSrgbAlpha] */ /* [Color4-fromSrgbAlpha] */
Math::Vector4<UnsignedByte> srgbAlpha; Vector4ub srgbAlpha;
auto rgba = Color4::fromSrgbAlpha(srgbAlpha); auto rgba = Color4::fromSrgbAlpha(srgbAlpha);
/* [Color4-fromSrgbAlpha] */ /* [Color4-fromSrgbAlpha] */
static_cast<void>(rgba); static_cast<void>(rgba);
@ -789,7 +789,7 @@ static_cast<void>(bFromSrgb);
{ {
/* [Color4-toSrgbAlpha] */ /* [Color4-toSrgbAlpha] */
Color4 color; Color4 color;
Math::Vector4<UnsignedByte> srgbAlpha = color.toSrgbAlpha<UnsignedByte>(); Vector4ub srgbAlpha = color.toSrgbAlpha<UnsignedByte>();
/* [Color4-toSrgbAlpha] */ /* [Color4-toSrgbAlpha] */
static_cast<void>(srgbAlpha); static_cast<void>(srgbAlpha);
} }
@ -830,7 +830,7 @@ static_cast<void>(a);
{ {
/* [_srgb] */ /* [_srgb] */
using namespace Math::Literals; using namespace Math::Literals;
Math::Vector3<UnsignedByte> a = 0x33b27f_srgb; // {0x33, 0xb2, 0x7f} Vector3ub a = 0x33b27f_srgb; // {0x33, 0xb2, 0x7f}
/* [_srgb] */ /* [_srgb] */
static_cast<void>(a); static_cast<void>(a);
} }
@ -846,7 +846,7 @@ static_cast<void>(a);
{ {
/* [_srgba] */ /* [_srgba] */
using namespace Math::Literals; using namespace Math::Literals;
Math::Vector4<UnsignedByte> a = 0x33b27fcc_srgba; // {0x33, 0xb2, 0x7f, 0xcc} Vector4ub a = 0x33b27fcc_srgba; // {0x33, 0xb2, 0x7f, 0xcc}
/* [_srgba] */ /* [_srgba] */
static_cast<void>(a); static_cast<void>(a);
} }
@ -960,10 +960,10 @@ Debug{} << UnsignedShort(a); // Prints 25675
{ {
/* [Half-usage-vector] */ /* [Half-usage-vector] */
Math::Vector3<Half> a{3.14159_h, -1.4142_h, 1.618_h}; Vector3h a{3.14159_h, -1.4142_h, 1.618_h};
Vector3 b{a}; // converts to 32-bit floats Vector3 b{a}; // converts to 32-bit floats
Debug{} << a; // prints {3.14159, -1.4142, 1.618} Debug{} << a; // prints {3.14159, -1.4142, 1.618}
Debug{} << Math::Vector3<UnsignedShort>{a}; // prints {16968, 48552, 15993} Debug{} << Vector3us{a}; // prints {16968, 48552, 15993}
/* [Half-usage-vector] */ /* [Half-usage-vector] */
} }

22
src/Magnum/GL/Test/MeshGLTest.cpp

@ -939,7 +939,7 @@ void MeshGLTest::addVertexBufferVectorNd() {
const Vector4d data[] = { const Vector4d data[] = {
{}, {0.0, -0.9, 1.0, 1.25}, {}, {0.0, -0.9, 1.0, 1.25},
Math::unpack<Vector4d>(Math::Vector4<UnsignedShort>(315, 65201, 2576, 12)) Math::unpack<Vector4d>(Vector4us{315, 65201, 2576, 12})
}; };
Buffer buffer; Buffer buffer;
buffer.setData(data, BufferUsage::StaticDraw); buffer.setData(data, BufferUsage::StaticDraw);
@ -961,10 +961,10 @@ void MeshGLTest::addVertexBufferVectorNd() {
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
const auto value = Checker(DoubleShader("dvec4", "vec4", "vec4(value)"), const auto value = Checker(DoubleShader("dvec4", "vec4", "vec4(value)"),
RenderbufferFormat::RGBA16, mesh).get<Math::Vector4<UnsignedShort>>(PixelFormat::RGBA, PixelType::UnsignedShort); RenderbufferFormat::RGBA16, mesh).get<Vector4us>(PixelFormat::RGBA, PixelType::UnsignedShort);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(value, Math::Vector4<UnsignedShort>(315, 65201, 2576, 12)); CORRADE_COMPARE(value, (Vector4us{315, 65201, 2576, 12}));
} }
#endif #endif
@ -1027,7 +1027,7 @@ void MeshGLTest::addVertexBufferMatrixNxNd() {
const Matrix3x3d data[] = { const Matrix3x3d data[] = {
{}, {},
Matrix3x3d::fromDiagonal({0.0, -0.9, 1.0}), Matrix3x3d::fromDiagonal({0.0, -0.9, 1.0}),
Matrix3x3d::fromDiagonal(Math::unpack<Vector3d>(Math::Vector3<UnsignedShort>(315, 65201, 2576))) Matrix3x3d::fromDiagonal(Math::unpack<Vector3d>(Vector3us{315, 65201, 2576}))
}; };
Buffer buffer; Buffer buffer;
buffer.setData(data, BufferUsage::StaticDraw); buffer.setData(data, BufferUsage::StaticDraw);
@ -1050,7 +1050,7 @@ void MeshGLTest::addVertexBufferMatrixNxNd() {
const auto value = Checker(DoubleShader("dmat3", "vec4", const auto value = Checker(DoubleShader("dmat3", "vec4",
"vec4(value[0][0], value[1][1], value[2][2], 0.0)"), "vec4(value[0][0], value[1][1], value[2][2], 0.0)"),
RenderbufferFormat::RGBA16, mesh).get<Math::Vector4<UnsignedShort>>(PixelFormat::RGBA, PixelType::UnsignedShort); RenderbufferFormat::RGBA16, mesh).get<Vector4us>(PixelFormat::RGBA, PixelType::UnsignedShort);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
@ -1058,13 +1058,13 @@ void MeshGLTest::addVertexBufferMatrixNxNd() {
/* Used to be a problem on Intel Windows drivers 23, not a problem on /* Used to be a problem on Intel Windows drivers 23, not a problem on
26 anymore */ 26 anymore */
CORRADE_EXPECT_FAIL_IF(Context::current().detectedDriver() & (Context::DetectedDriver::Amd|Context::DetectedDriver::NVidia), "Somehow only first two values are extracted on AMD and NVidia drivers."); CORRADE_EXPECT_FAIL_IF(Context::current().detectedDriver() & (Context::DetectedDriver::Amd|Context::DetectedDriver::NVidia), "Somehow only first two values are extracted on AMD and NVidia drivers.");
CORRADE_COMPARE(value.xyz(), Math::Vector3<UnsignedShort>(315, 65201, 2576)); CORRADE_COMPARE(value.xyz(), (Vector3us{315, 65201, 2576}));
} }
/* This is wrong, but check if it's still the right wrong. Fails on AMD /* This is wrong, but check if it's still the right wrong. Fails on AMD
15.201.1151 but seems to be fixed in 15.300.1025.0 */ 15.201.1151 but seems to be fixed in 15.300.1025.0 */
if(Context::current().detectedDriver() & (Context::DetectedDriver::Amd|Context::DetectedDriver::NVidia)) if(Context::current().detectedDriver() & (Context::DetectedDriver::Amd|Context::DetectedDriver::NVidia))
CORRADE_COMPARE(value.xyz(), Math::Vector3<UnsignedShort>(315, 65201, 0)); CORRADE_COMPARE(value.xyz(), (Vector3us{315, 65201, 0}));
} }
#endif #endif
@ -1111,7 +1111,7 @@ void MeshGLTest::addVertexBufferMatrixMxNd() {
const Matrix3x4d data[] = { const Matrix3x4d data[] = {
{}, {},
Matrix3x4d::fromDiagonal({0.0, -0.9, 1.0}), Matrix3x4d::fromDiagonal({0.0, -0.9, 1.0}),
Matrix3x4d::fromDiagonal(Math::unpack<Vector3d>(Math::Vector3<UnsignedShort>(315, 65201, 2576))) Matrix3x4d::fromDiagonal(Math::unpack<Vector3d>(Vector3us{315, 65201, 2576}))
}; };
Buffer buffer; Buffer buffer;
buffer.setData(data, BufferUsage::StaticDraw); buffer.setData(data, BufferUsage::StaticDraw);
@ -1134,7 +1134,7 @@ void MeshGLTest::addVertexBufferMatrixMxNd() {
const auto value = Checker(DoubleShader("dmat3x4", "vec4", const auto value = Checker(DoubleShader("dmat3x4", "vec4",
"vec4(value[0][0], value[1][1], value[2][2], 0.0)"), "vec4(value[0][0], value[1][1], value[2][2], 0.0)"),
RenderbufferFormat::RGBA16, mesh).get<Math::Vector4<UnsignedShort>>(PixelFormat::RGBA, PixelType::UnsignedShort); RenderbufferFormat::RGBA16, mesh).get<Vector4us>(PixelFormat::RGBA, PixelType::UnsignedShort);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
@ -1142,13 +1142,13 @@ void MeshGLTest::addVertexBufferMatrixMxNd() {
/* Used to be a problem on Intel Windows drivers 23, not a problem on /* Used to be a problem on Intel Windows drivers 23, not a problem on
26 anymore */ 26 anymore */
CORRADE_EXPECT_FAIL_IF(Context::current().detectedDriver() & (Context::DetectedDriver::Amd|Context::DetectedDriver::NVidia), "Somehow only first two values are extracted on AMD and NVidia drivers."); CORRADE_EXPECT_FAIL_IF(Context::current().detectedDriver() & (Context::DetectedDriver::Amd|Context::DetectedDriver::NVidia), "Somehow only first two values are extracted on AMD and NVidia drivers.");
CORRADE_COMPARE(value.xyz(), Math::Vector3<UnsignedShort>(315, 65201, 2576)); CORRADE_COMPARE(value.xyz(), (Vector3us{315, 65201, 2576}));
} }
/* This is wrong, but check if it's still the right wrong. Fails on AMD /* This is wrong, but check if it's still the right wrong. Fails on AMD
15.201.1151 but seems to be fixed in 15.300.1025.0 */ 15.201.1151 but seems to be fixed in 15.300.1025.0 */
if(Context::current().detectedDriver() & (Context::DetectedDriver::Amd|Context::DetectedDriver::NVidia)) if(Context::current().detectedDriver() & (Context::DetectedDriver::Amd|Context::DetectedDriver::NVidia))
CORRADE_COMPARE(value.xyz(), Math::Vector3<UnsignedShort>(315, 65201, 0)); CORRADE_COMPARE(value.xyz(), (Vector3us{315, 65201, 0}));
} }
#endif #endif

Loading…
Cancel
Save