summaryrefslogtreecommitdiff
path: root/platform/android/src/example_custom_layer.cpp
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2016-11-03 15:22:21 +0200
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2016-11-07 09:38:04 +0100
commit505bf7db7a33f977a3339528bbae17bdfa30e2e0 (patch)
treefceaab6babc8dcb65304305a72c5358d50253998 /platform/android/src/example_custom_layer.cpp
parentee073f6b96f5e70a283def9cd2acebbae29b97d1 (diff)
downloadqtlocation-mapboxgl-505bf7db7a33f977a3339528bbae17bdfa30e2e0.tar.gz
[android] update custom layer example with invalidation example
Diffstat (limited to 'platform/android/src/example_custom_layer.cpp')
-rw-r--r--platform/android/src/example_custom_layer.cpp35
1 files changed, 31 insertions, 4 deletions
diff --git a/platform/android/src/example_custom_layer.cpp b/platform/android/src/example_custom_layer.cpp
index 516a8f2cd5..0fb0287f3d 100644
--- a/platform/android/src/example_custom_layer.cpp
+++ b/platform/android/src/example_custom_layer.cpp
@@ -1,14 +1,17 @@
#include <jni.h>
#include <GLES2/gl2.h>
+#include <mbgl/platform/log.hpp>
+
#include <mbgl/style/layers/custom_layer.hpp>
static const GLchar * vertexShaderSource = "attribute vec2 a_pos; void main() { gl_Position = vec4(a_pos, 0, 1); }";
-static const GLchar * fragmentShaderSource = "void main() { gl_FragColor = vec4(0, 1, 0, 1); }";
+static const GLchar * fragmentShaderSource = "uniform vec4 fill_color; void main() { gl_FragColor = fill_color; }";
class ExampleCustomLayer {
public:
~ExampleCustomLayer() {
+ mbgl::Log::Info(mbgl::Event::General, "~ExampleCustomLayer");
if (program) {
glDeleteBuffers(1, &buffer);
glDetachShader(program, vertexShader);
@@ -20,6 +23,7 @@ public:
}
void initialize() {
+ mbgl::Log::Info(mbgl::Event::General, "Initialize");
program = glCreateProgram();
vertexShader = glCreateShader(GL_VERTEX_SHADER);
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
@@ -32,6 +36,7 @@ public:
glAttachShader(program, fragmentShader);
glLinkProgram(program);
a_pos = glGetAttribLocation(program, "a_pos");
+ fill_color = glGetUniformLocation(program, "fill_color");
GLfloat background[] = { -1,-1, 1,-1, -1,1, 1,1 };
glGenBuffers(1, &buffer);
@@ -40,12 +45,15 @@ public:
}
void render() {
+ mbgl::Log::Info(mbgl::Event::General, "Render");
glUseProgram(program);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glEnableVertexAttribArray(a_pos);
glVertexAttribPointer(a_pos, 2, GL_FLOAT, GL_FALSE, 0, NULL);
glDisable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST);
+ glUniform4fv(fill_color, 1, color);
+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
@@ -54,35 +62,54 @@ public:
GLuint fragmentShader = 0;
GLuint buffer = 0;
GLuint a_pos = 0;
+ GLuint fill_color = 0;
+
+ static GLfloat color[];
};
+GLfloat ExampleCustomLayer::color[] = { 0.0f, 1.0f, 0.0f, 1.0f };
+
jlong JNICALL nativeCreateContext(JNIEnv*, jobject) {
- return reinterpret_cast<jlong>(new ExampleCustomLayer());
+ mbgl::Log::Info(mbgl::Event::General, "nativeCreateContext");
+ return reinterpret_cast<jlong>(new ExampleCustomLayer());
+}
+
+void JNICALL nativeSetColor(JNIEnv*, jobject, jfloat red, jfloat green, jfloat blue, jfloat alpha) {
+ mbgl::Log::Info(mbgl::Event::General, "nativeSetColor: %.2f, %.2f, %.2f, %.2f", red, green, blue, alpha);
+ ExampleCustomLayer::color[0] = red;
+ ExampleCustomLayer::color[1] = green;
+ ExampleCustomLayer::color[2] = blue;
+ ExampleCustomLayer::color[3] = alpha;
}
void nativeInitialize(void *context) {
+ mbgl::Log::Info(mbgl::Event::General, "nativeInitialize");
reinterpret_cast<ExampleCustomLayer*>(context)->initialize();
}
void nativeRender(void *context, const mbgl::style::CustomLayerRenderParameters& /*parameters*/) {
+ mbgl::Log::Info(mbgl::Event::General, "nativeRender");
reinterpret_cast<ExampleCustomLayer*>(context)->render();
}
void nativeDenitialize(void *context) {
+ mbgl::Log::Info(mbgl::Event::General, "nativeDeinitialize");
delete reinterpret_cast<ExampleCustomLayer*>(context);
}
extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
+ mbgl::Log::Info(mbgl::Event::General, "OnLoad");
JNIEnv *env = nullptr;
vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6);
jclass customLayerClass = env->FindClass("com/mapbox/mapboxsdk/testapp/model/customlayer/ExampleCustomLayer");
JNINativeMethod methods[] = {
- {"createContext", "()J", reinterpret_cast<void *>(&nativeCreateContext)}
+ {"createContext", "()J", reinterpret_cast<void *>(&nativeCreateContext)},
+ {"setColor", "(FFFF)V", reinterpret_cast<void *>(&nativeSetColor)}
};
- if (env->RegisterNatives(customLayerClass, methods, 1) < 0) {
+ if (env->RegisterNatives(customLayerClass, methods, 2) < 0) {
env->ExceptionDescribe();
return JNI_ERR;
}