Merge remote-tracking branch 'origin' into linux-ci
This commit is contained in:
54
test/util/hash.test.cpp
Normal file
54
test/util/hash.test.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include <mbgl/test/util.hpp>
|
||||
|
||||
#include <mbgl/util/hash.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <random>
|
||||
#include <vector>
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
TEST(OrderIndependentHash, Permutations) {
|
||||
// Try collections of up to this many elements
|
||||
constexpr int maxSize = 6;
|
||||
// Try this many different sets of values for each size
|
||||
constexpr int iterations = 10;
|
||||
// Use values up to this large
|
||||
constexpr size_t maxVal = 10;
|
||||
|
||||
std::seed_seq seed{0xf00dLL};
|
||||
std::default_random_engine engine(seed);
|
||||
std::uniform_int_distribution<size_t> distribution(0, maxVal);
|
||||
|
||||
for (int curSize = 1; curSize <= maxSize; ++curSize) {
|
||||
for (int ii = 0; ii < iterations; ++ii) {
|
||||
// Generate `curSize` random values
|
||||
std::vector<size_t> values;
|
||||
for (int jj = 0; jj < curSize; ++jj) {
|
||||
values.push_back(distribution(engine));
|
||||
}
|
||||
|
||||
// Generate the hash for each permutation, comparing subsequent values to the first one.
|
||||
bool isFirst = true;
|
||||
size_t initialValue = 0;
|
||||
do {
|
||||
const auto curValue = util::order_independent_hash(values.begin(), values.end());
|
||||
if (isFirst || curValue != initialValue) {
|
||||
for (auto v : values) {
|
||||
std::cout << v << ",";
|
||||
}
|
||||
std::cout << " - " << std::hex << curValue << std::endl;
|
||||
}
|
||||
if (isFirst) {
|
||||
initialValue = curValue;
|
||||
isFirst = false;
|
||||
} else {
|
||||
EXPECT_EQ(initialValue, curValue);
|
||||
}
|
||||
} while (std::next_permutation(values.begin(), values.end()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,17 @@
|
||||
#include <mbgl/gfx/backend_scope.hpp>
|
||||
#include <mbgl/gfx/render_pass.hpp>
|
||||
#include <mbgl/gl/context.hpp>
|
||||
#include <mbgl/gl/texture.hpp>
|
||||
#include <mbgl/gl/defines.hpp>
|
||||
#include <mbgl/gl/renderable_resource.hpp>
|
||||
#include <mbgl/gl/headless_backend.hpp>
|
||||
#include <mbgl/gl/offscreen_texture.hpp>
|
||||
|
||||
#if MLN_LEGACY_RENDERER
|
||||
#include <mbgl/gl/texture.hpp>
|
||||
#else
|
||||
#include <mbgl/gl/texture2d.hpp>
|
||||
#endif
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace mbgl::platform;
|
||||
|
||||
@@ -75,11 +80,7 @@ struct Buffer {
|
||||
GLuint buffer = 0;
|
||||
};
|
||||
|
||||
#if MLN_LEGACY_RENDERER
|
||||
TEST(OffscreenTexture, RenderToTexture) {
|
||||
#else
|
||||
TEST(OffscreenTexture, DISABLED_RenderToTexture) {
|
||||
#endif
|
||||
if (gfx::Backend::GetType() != gfx::Backend::Type::OpenGL) {
|
||||
return;
|
||||
}
|
||||
@@ -145,13 +146,13 @@ void main() {
|
||||
|
||||
// Then, create a texture, bind it, and render yellow to that texture. This
|
||||
// should not affect the originally bound FBO.
|
||||
gl::OffscreenTexture texture(context, {128, 128});
|
||||
gl::OffscreenTexture offscreenTexture(context, {128, 128});
|
||||
|
||||
// Scissor test shouldn't leak after OffscreenTexture::bind().
|
||||
MBGL_CHECK_ERROR(glScissor(32, 32, 64, 64));
|
||||
context.scissorTest.setCurrentValue(true);
|
||||
|
||||
texture.getResource<gl::RenderableResource>().bind();
|
||||
offscreenTexture.getResource<gl::RenderableResource>().bind();
|
||||
|
||||
context.clear(Color(), {}, {});
|
||||
|
||||
@@ -161,7 +162,7 @@ void main() {
|
||||
MBGL_CHECK_ERROR(glVertexAttribPointer(paintShader.a_pos, 2, GL_FLOAT, GL_FALSE, 0, nullptr));
|
||||
MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, 3));
|
||||
|
||||
auto image = texture.readStillImage();
|
||||
auto image = offscreenTexture.readStillImage();
|
||||
test::checkImage("test/fixtures/offscreen_texture/render-to-texture", image, 0, 0);
|
||||
|
||||
// Now reset the FBO back to normal and retrieve the original (restored) framebuffer.
|
||||
@@ -172,12 +173,13 @@ void main() {
|
||||
|
||||
// Now, composite the Framebuffer texture we've rendered to onto the main FBO.
|
||||
#if MLN_LEGACY_RENDERER
|
||||
gl::bindTexture(context, 0, {texture.getTexture().getResource(), gfx::TextureFilterType::Linear});
|
||||
gl::bindTexture(context, 0, {offscreenTexture.getTexture().getResource(), gfx::TextureFilterType::Linear});
|
||||
MBGL_CHECK_ERROR(glUniform1i(u_texture, 0));
|
||||
#else
|
||||
// TODO: Implement based on gfx::Texture2D
|
||||
offscreenTexture.getTexture()->setSamplerConfiguration({gfx::TextureFilterType::Linear});
|
||||
std::static_pointer_cast<gl::Texture2D>(offscreenTexture.getTexture())->bind(u_texture, 0);
|
||||
#endif
|
||||
MBGL_CHECK_ERROR(glUseProgram(compositeShader.program));
|
||||
MBGL_CHECK_ERROR(glUniform1i(u_texture, 0));
|
||||
MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, viewportBuffer.buffer));
|
||||
MBGL_CHECK_ERROR(glEnableVertexAttribArray(compositeShader.a_pos));
|
||||
MBGL_CHECK_ERROR(glVertexAttribPointer(compositeShader.a_pos, 2, GL_FLOAT, GL_FALSE, 0, nullptr));
|
||||
|
||||
Reference in New Issue
Block a user