Last active
December 16, 2022 20:55
-
-
Save sonique6784/0e6613d98a6c2086d45088f9d756e753 to your computer and use it in GitHub Desktop.
GLFrontBufferedRenderer setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright 2022 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 */ | |
val callbacks = object : GLFrontBufferedRenderer.Callback<DATA_TYPE> { | |
override fun onDrawFrontBufferedLayer( | |
eglManager: EGLManager, | |
bufferWidth: Int, | |
bufferHeight: Int, | |
transform: FloatArray, | |
param: DATA_TYPE | |
) { | |
// OpenGL work for Front buffer layer | |
} | |
override fun onDrawDoubleBufferedLayer( | |
eglManager: EGLManager, | |
bufferWidth: Int, | |
bufferHeight: Int, | |
transform: FloatArray, | |
params: Collection<DATA_TYPE> | |
) { | |
// OpenGL work for Doubled buffer layer | |
} | |
} | |
val frontBufferRenderer = GLFrontBufferedRenderer(mySurfaceView, callbacks) | |
// Add a OnTouchListener, to get the motion data and send then | |
// to frontBufferRenderer for rendering. | |
mySurfaceView.setOnTouchListener { v, event -> | |
// MotionEvent to DATA_TYPE - function to implement yourself | |
val dataPoint = event.toDATA_TYPE() | |
when (event.action) { | |
MotionEvent.ACTION_DOWN -> { | |
// Render a new data point directly to the front buffer layer | |
frontBufferRenderer.renderFrontBufferedLayer(dataPoint) | |
} | |
MotionEvent.ACTION_MOVE -> { | |
// Render a new data point directly to the front buffer layer | |
frontBufferRenderer.renderFrontBufferedLayer(dataPoint) | |
} | |
MotionEvent.ACTION_UP -> { | |
// Stroke is done, commit the data points to the double buffered layer | |
frontBufferRenderer.commit() | |
} | |
else -> Unit | |
} | |
true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment