summaryrefslogtreecommitdiff
path: root/test/util/offscreen_texture.test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/util/offscreen_texture.test.cpp')
-rw-r--r--test/util/offscreen_texture.test.cpp38
1 files changed, 24 insertions, 14 deletions
diff --git a/test/util/offscreen_texture.test.cpp b/test/util/offscreen_texture.test.cpp
index 4aded07b2f..31fb985394 100644
--- a/test/util/offscreen_texture.test.cpp
+++ b/test/util/offscreen_texture.test.cpp
@@ -2,16 +2,16 @@
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/context.hpp>
-#include <mbgl/platform/default/headless_backend.hpp>
-#include <mbgl/platform/default/offscreen_view.hpp>
+#include <mbgl/gl/headless_backend.hpp>
+#include <mbgl/gl/offscreen_view.hpp>
#include <mbgl/util/offscreen_texture.hpp>
using namespace mbgl;
TEST(OffscreenTexture, EmptyRed) {
- HeadlessBackend backend;
- OffscreenView view(backend.getContext(), {{ 512, 256 }});
+ HeadlessBackend backend { test::sharedDisplay() };
+ OffscreenView view(backend.getContext(), { 512, 256 });
view.bind();
MBGL_CHECK_ERROR(glClearColor(1.0f, 0.0f, 0.0f, 1.0f));
@@ -67,24 +67,33 @@ struct Buffer {
TEST(OffscreenTexture, RenderToTexture) {
- HeadlessBackend backend;
+ HeadlessBackend backend { test::sharedDisplay() };
auto& context = backend.getContext();
MBGL_CHECK_ERROR(glEnable(GL_BLEND));
MBGL_CHECK_ERROR(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
Shader paintShader(R"MBGL_SHADER(
+#ifdef GL_ES
+precision mediump float;
+#endif
attribute vec2 a_pos;
void main() {
gl_Position = vec4(a_pos, 0, 1);
}
)MBGL_SHADER", R"MBGL_SHADER(
+#ifdef GL_ES
+precision mediump float;
+#endif
void main() {
gl_FragColor = vec4(0, 0.8, 0, 0.8);
}
)MBGL_SHADER");
Shader compositeShader(R"MBGL_SHADER(
+#ifdef GL_ES
+precision mediump float;
+#endif
attribute vec2 a_pos;
varying vec2 v_texcoord;
void main() {
@@ -92,6 +101,9 @@ void main() {
v_texcoord = (a_pos + 1.0) / 2.0;
}
)MBGL_SHADER", R"MBGL_SHADER(
+#ifdef GL_ES
+precision mediump float;
+#endif
uniform sampler2D u_texture;
varying vec2 v_texcoord;
void main() {
@@ -106,22 +118,20 @@ void main() {
// Make sure the texture gets destructed before we call context.reset();
{
- OffscreenView view(context, {{ 512, 256 }});
+ OffscreenView view(context, { 512, 256 });
+ view.bind();
// First, draw red to the bound FBO.
- context.clearColor = { 1, 0, 0, 1 };
- view.bind();
- MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT));
+ context.clear(Color::red(), {}, {});
// Then, create a texture, bind it, and render yellow to that texture. This should not
// affect the originally bound FBO.
- OffscreenTexture texture(context, {{ 128, 128 }});
+ OffscreenTexture texture(context, { 128, 128 });
texture.bind();
- context.clearColor = { 0, 0, 0, 0 };
- MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT));
+ context.clear(Color(), {}, {});
- context.program = paintShader.program;
+ MBGL_CHECK_ERROR(glUseProgram(paintShader.program));
MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, triangleBuffer.buffer));
MBGL_CHECK_ERROR(glEnableVertexAttribArray(paintShader.a_pos));
MBGL_CHECK_ERROR(
@@ -138,8 +148,8 @@ void main() {
test::checkImage("test/fixtures/offscreen_texture/render-to-fbo", image, 0, 0);
// Now, composite the Framebuffer texture we've rendered to onto the main FBO.
- context.program = compositeShader.program;
context.bindTexture(texture.getTexture(), 0, gl::TextureFilter::Linear);
+ 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));