From 099fcc3b3c72b117e93d4da39ee6f70c6c5a2bc8 Mon Sep 17 00:00:00 2001 From: Asheem Mamoowala Date: Mon, 2 Apr 2018 16:15:25 -0700 Subject: Use a host interface for CustomLayer instead of function pointers (#11553) Use a host interface for CustomLayer instead of function pointers Co-authored-by: Julian Rex --- test/api/custom_layer.test.cpp | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'test') diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp index eb1d7e0d3a..6cb148a349 100644 --- a/test/api/custom_layer.test.cpp +++ b/test/api/custom_layer.test.cpp @@ -34,19 +34,8 @@ void main() { // layer implementation because it is intended to reflect how someone using custom layers // might actually write their own implementation. -class TestLayer { +class TestLayer : public mbgl::style::CustomLayerHost { public: - ~TestLayer() { - if (program) { - MBGL_CHECK_ERROR(glDeleteBuffers(1, &buffer)); - MBGL_CHECK_ERROR(glDetachShader(program, vertexShader)); - MBGL_CHECK_ERROR(glDetachShader(program, fragmentShader)); - MBGL_CHECK_ERROR(glDeleteShader(vertexShader)); - MBGL_CHECK_ERROR(glDeleteShader(fragmentShader)); - MBGL_CHECK_ERROR(glDeleteProgram(program)); - } - } - void initialize() { program = MBGL_CHECK_ERROR(glCreateProgram()); vertexShader = MBGL_CHECK_ERROR(glCreateShader(GL_VERTEX_SHADER)); @@ -67,7 +56,7 @@ public: MBGL_CHECK_ERROR(glBufferData(GL_ARRAY_BUFFER, 6 * sizeof(GLfloat), triangle, GL_STATIC_DRAW)); } - void render() { + void render(const mbgl::style::CustomLayerRenderParameters&) { MBGL_CHECK_ERROR(glUseProgram(program)); MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, buffer)); MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); @@ -75,6 +64,19 @@ public: MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, 3)); } + void contextLost() {} + + void deinitialize() { + if (program) { + MBGL_CHECK_ERROR(glDeleteBuffers(1, &buffer)); + MBGL_CHECK_ERROR(glDetachShader(program, vertexShader)); + MBGL_CHECK_ERROR(glDetachShader(program, fragmentShader)); + MBGL_CHECK_ERROR(glDeleteShader(vertexShader)); + MBGL_CHECK_ERROR(glDeleteShader(fragmentShader)); + MBGL_CHECK_ERROR(glDeleteProgram(program)); + } + } + GLuint program = 0; GLuint vertexShader = 0; GLuint fragmentShader = 0; @@ -95,15 +97,7 @@ TEST(CustomLayer, Basic) { map.setLatLngZoom({ 37.8, -122.5 }, 10); map.getStyle().addLayer(std::make_unique( "custom", - [] (void* context) { - reinterpret_cast(context)->initialize(); - }, - [] (void* context, const CustomLayerRenderParameters&) { - reinterpret_cast(context)->render(); - }, - [] (void* context) { - delete reinterpret_cast(context); - }, new TestLayer())); + std::make_unique())); auto layer = std::make_unique("landcover", "mapbox"); layer->setSourceLayer("landcover"); -- cgit v1.2.1