mirror of https://github.com/mosra/magnum.git
6 changed files with 206 additions and 2 deletions
@ -0,0 +1,38 @@ |
|||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 |
||||||
|
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 "BufferData.h" |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_WEBGL |
||||||
|
namespace Magnum { namespace DebugTools { namespace Implementation { |
||||||
|
|
||||||
|
void bufferSubData(Buffer& buffer, GLintptr offset, GLsizeiptr size, void* output) { |
||||||
|
const char* data = buffer.map<const char>(offset, size, Buffer::MapFlag::Read); |
||||||
|
std::copy(data, data + size, reinterpret_cast<char*>(output)); |
||||||
|
buffer.unmap(); |
||||||
|
} |
||||||
|
|
||||||
|
}}} |
||||||
|
#endif |
||||||
@ -0,0 +1,81 @@ |
|||||||
|
#ifndef Magnum_DebugTools_BufferData_h |
||||||
|
#define Magnum_DebugTools_BufferData_h |
||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 |
||||||
|
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. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_WEBGL |
||||||
|
/** @file
|
||||||
|
* @brief Function @ref Magnum::DebugTools::bufferData(), @ref Magnum::DebugTools::bufferSubData() |
||||||
|
*/ |
||||||
|
#endif |
||||||
|
|
||||||
|
#include <Corrade/Containers/Array.h> |
||||||
|
|
||||||
|
#include "Magnum/Buffer.h" |
||||||
|
#include "Magnum/DebugTools/visibility.h" |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_WEBGL |
||||||
|
namespace Magnum { namespace DebugTools { |
||||||
|
|
||||||
|
namespace Implementation { |
||||||
|
MAGNUM_DEBUGTOOLS_EXPORT void bufferSubData(Buffer& buffer, GLintptr offset, GLsizeiptr size, void* output); |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Buffer subdata |
||||||
|
|
||||||
|
Emulates @ref Buffer::subData() call on platforms that don't support it (such |
||||||
|
as OpenGL ES) by using @ref Buffer::map(). |
||||||
|
@requires_gles30 Extension @es_extension{EXT,map_buffer_range} in OpenGL ES |
||||||
|
2.0. |
||||||
|
@requires_gles Buffer mapping is not available in WebGL. |
||||||
|
*/ |
||||||
|
template<class T> Containers::Array<T> inline bufferSubData(Buffer& buffer, GLintptr offset, GLsizeiptr size) { |
||||||
|
Containers::Array<T> data{std::size_t(size)}; |
||||||
|
if(size) Implementation::bufferSubData(buffer, offset, size*sizeof(T), data); |
||||||
|
return data; |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Buffer data |
||||||
|
|
||||||
|
Emulates @ref Buffer::data() call on platforms that don't support it (such as |
||||||
|
OpenGL ES) by using @ref Buffer::map(). |
||||||
|
@requires_gles30 Extension @es_extension{EXT,map_buffer_range} in OpenGL ES |
||||||
|
2.0. |
||||||
|
@requires_gles Buffer mapping is not available in WebGL. |
||||||
|
*/ |
||||||
|
template<class T = char> Containers::Array<T> inline bufferData(Buffer& buffer) { |
||||||
|
const Int bufferSize = buffer.size(); |
||||||
|
CORRADE_ASSERT(bufferSize%sizeof(T) == 0, "Buffer::data(): the buffer size is" << bufferSize << "bytes, which can't be expressed as array of types with size" << sizeof(T), nullptr); |
||||||
|
return bufferSubData<T>(buffer, 0, bufferSize/sizeof(T)); |
||||||
|
} |
||||||
|
|
||||||
|
}} |
||||||
|
#else |
||||||
|
#error this header is not available in WebGL build |
||||||
|
#endif |
||||||
|
|
||||||
|
#endif |
||||||
@ -0,0 +1,71 @@ |
|||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 |
||||||
|
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 <Corrade/TestSuite/Compare/Container.h> |
||||||
|
|
||||||
|
#include "Magnum/DebugTools/BufferData.h" |
||||||
|
#include "Magnum/Test/AbstractOpenGLTester.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace DebugTools { namespace Test { |
||||||
|
|
||||||
|
struct BufferDataGLTest: Magnum::Test::AbstractOpenGLTester { |
||||||
|
explicit BufferDataGLTest(); |
||||||
|
|
||||||
|
void data(); |
||||||
|
void subData(); |
||||||
|
}; |
||||||
|
|
||||||
|
BufferDataGLTest::BufferDataGLTest() { |
||||||
|
addTests({&BufferDataGLTest::data, |
||||||
|
&BufferDataGLTest::subData}); |
||||||
|
} |
||||||
|
|
||||||
|
namespace { |
||||||
|
constexpr Int Data[] = {2, 7, 5, 13, 25}; |
||||||
|
} |
||||||
|
|
||||||
|
void BufferDataGLTest::data() { |
||||||
|
Buffer buffer; |
||||||
|
buffer.setData(Data, BufferUsage::StaticDraw); |
||||||
|
const Containers::Array<Int> contents = bufferData<Int>(buffer); |
||||||
|
MAGNUM_VERIFY_NO_ERROR(); |
||||||
|
CORRADE_COMPARE_AS(contents, |
||||||
|
Containers::ArrayView<const Int>{Data}, |
||||||
|
TestSuite::Compare::Container); |
||||||
|
} |
||||||
|
|
||||||
|
void BufferDataGLTest::subData() { |
||||||
|
Buffer buffer; |
||||||
|
buffer.setData(Data, BufferUsage::StaticDraw); |
||||||
|
const Containers::Array<Int> contents = bufferSubData<Int>(buffer, 4, 3); |
||||||
|
MAGNUM_VERIFY_NO_ERROR(); |
||||||
|
CORRADE_COMPARE_AS(contents, |
||||||
|
Containers::ArrayView<const Int>{Data}.slice(1, 4), |
||||||
|
TestSuite::Compare::Container); |
||||||
|
} |
||||||
|
|
||||||
|
}}} |
||||||
|
|
||||||
|
MAGNUM_GL_TEST_MAIN(Magnum::DebugTools::Test::BufferDataGLTest) |
||||||
Loading…
Reference in new issue