From 8632ac73d720764471f26e9a44464456ce80f891 Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Sun, 1 May 2022 23:07:06 -0400 Subject: [PATCH 01/30] Added the ability to directly set the fragment and vertex shaders as strings --- README.md | 4 ++ .../com/appspell/shaderview/ShaderView.kt | 59 ++++++++++++++----- .../shaderview/gl/shader/ShaderBuilder.kt | 9 +++ local.properties | 4 +- 4 files changed, 59 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 320bd56..11e49da 100644 --- a/README.md +++ b/README.md @@ -82,8 +82,12 @@ with(shaderView) { ## The full list of ShaderView properties: `fragmentShaderRawResId` - reference to the vertex shader file in RAW resource solder [example] +OR +`fragmentShader` - a string of the fragment shader code `vertexShaderRawResId` - reference to the fragment shader file in RAW resource solder [example] +OR +`vertexShader` - a string of the vertex shader code `shaderParams` - custom parameters that we're going to send to the shader (uniform) diff --git a/lib/src/main/java/com/appspell/shaderview/ShaderView.kt b/lib/src/main/java/com/appspell/shaderview/ShaderView.kt index 56669f3..79a0318 100644 --- a/lib/src/main/java/com/appspell/shaderview/ShaderView.kt +++ b/lib/src/main/java/com/appspell/shaderview/ShaderView.kt @@ -45,6 +45,17 @@ class ShaderView @JvmOverloads constructor( field = value } + var vertexShader: String? = null + set(value) { + needToRecreateShaders = true + field = value + } + var fragmentShader: String? = null + set(value) { + needToRecreateShaders = true + field = value + } + var shaderParams: ShaderParams? = null set(value) { field = value @@ -158,21 +169,39 @@ class ShaderView @JvmOverloads constructor( // delete existing shader if we have some renderer.shader.release() - // create a new shader - renderer.shader = renderer.shader.newBuilder() - .create( - context = context, - vertexShaderRawResId = vertexShaderRawResId ?: DEFAULT_VERTEX_SHADER_RESOURCE, - fragmentShaderRawResId = fragmentShader - ) - .apply { - // if we have some ShaderParams to set - shaderParams?.apply { params(this) } - } - .build() - .also { - needToRecreateShaders = true - } + vertexShader?.let { + // create a new shader from text + renderer.shader = renderer.shader.newBuilder() + .create( + vertexShader = this.vertexShader!!, + fragmentShader = this.fragmentShader!! + ) + .apply { + // if we have some ShaderParams to set + shaderParams?.apply { params(this) } + } + .build() + .also { + needToRecreateShaders = true + } + } ?: run { + // create a new shader from resources + renderer.shader = renderer.shader.newBuilder() + .create( + context = context, + vertexShaderRawResId = vertexShaderRawResId + ?: DEFAULT_VERTEX_SHADER_RESOURCE, + fragmentShaderRawResId = fragmentShader + ) + .apply { + // if we have some ShaderParams to set + shaderParams?.apply { params(this) } + } + .build() + .also { + needToRecreateShaders = true + } + } } } diff --git a/lib/src/main/java/com/appspell/shaderview/gl/shader/ShaderBuilder.kt b/lib/src/main/java/com/appspell/shaderview/gl/shader/ShaderBuilder.kt index 34bd487..287c7fd 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/shader/ShaderBuilder.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/shader/ShaderBuilder.kt @@ -43,6 +43,15 @@ class ShaderBuilder { } return this } + fun create( + vertexShader: String, + fragmentShader: String + ): ShaderBuilder { + if (!shader.createProgram(vertexShader, fragmentShader)) { + LibLog.e(TAG, "shader program wasn't created") + } + return this + } fun params(shaderParams: ShaderParams): ShaderBuilder { shader.params = shaderParams diff --git a/local.properties b/local.properties index d235f30..5da0242 100644 --- a/local.properties +++ b/local.properties @@ -4,5 +4,5 @@ # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. -#Thu Dec 24 14:06:27 MSK 2020 -sdk.dir=/Users/alexey/Library/Android/sdk +#Sun May 01 00:25:25 EDT 2022 +sdk.dir=C\:\\Users\\oxter\\AppData\\Local\\Android\\Sdk From d95a978b5767b2e655105fc936596652bbafed5b Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 01:55:09 -0400 Subject: [PATCH 02/30] Added fps as ShaderView property. Updated readme. --- README.md | 10 +++-- .../com/appspell/shaderview/ShaderView.kt | 8 ++++ .../shaderview/gl/view/GLTextureView.kt | 39 +++++++++++++++++-- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 11e49da..f7e9a38 100644 --- a/README.md +++ b/README.md @@ -81,12 +81,12 @@ with(shaderView) { ## The full list of ShaderView properties: -`fragmentShaderRawResId` - reference to the vertex shader file in RAW resource solder [example] -OR +`fragmentShaderRawResId` - reference to the vertex shader file in RAW resource solder [example] +OR `fragmentShader` - a string of the fragment shader code -`vertexShaderRawResId` - reference to the fragment shader file in RAW resource solder [example] -OR +`vertexShaderRawResId` - reference to the fragment shader file in RAW resource solder [example] +OR `vertexShader` - a string of the vertex shader code `shaderParams` - custom parameters that we're going to send to the shader (uniform) @@ -97,6 +97,8 @@ OR `updateContinuously` - should we render the view each frame (default is "false") +`fps` - At what framerate should the shader be drawn if updateContinuously set to true + `debugMode` - enable or disable debug logs diff --git a/lib/src/main/java/com/appspell/shaderview/ShaderView.kt b/lib/src/main/java/com/appspell/shaderview/ShaderView.kt index 79a0318..28cb5ca 100644 --- a/lib/src/main/java/com/appspell/shaderview/ShaderView.kt +++ b/lib/src/main/java/com/appspell/shaderview/ShaderView.kt @@ -98,6 +98,14 @@ class ShaderView @JvmOverloads constructor( } } + var fps: Int + set(value) { + setFPS(fps) + } + get(): Int { + return getFPS() + } + private val rendererListener = object : GLQuadRender.ShaderViewListener { override fun onSurfaceCreated() { initShaders() diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index b14f58d..4409889 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -421,6 +421,20 @@ open class GLTextureView @JvmOverloads constructor( return mGLThread!!.renderMode } + /** + * Set how often RENDERMODE_CONTINUOUSLY draws the shader + */ + fun setFPS(fps: Int) { + mGLThread!!.fps = fps + } + + /** + * Get the current framerate of RENDERMODE_CONTINUOUSLY + */ + fun getFPS(): Int { + return mGLThread!!.fps + } + /** * Request that the renderer render a frame. * This method is typically used when the render mode has been set to @@ -1590,9 +1604,16 @@ open class GLTextureView @JvmOverloads constructor( } private fun readyToDraw(): Boolean { - return (!mPaused && mHasSurface && !mSurfaceIsBad - && mWidth > 0 && mHeight > 0 - && (mRequestRender || mRenderMode == RENDERMODE_CONTINUOUSLY)) + val canDraw = !mPaused && mHasSurface && !mSurfaceIsBad && mWidth > 0 && mHeight > 0 + return if (canDraw) { + val secondsPerFrame = 1.0 / mFPS + val secondsPassed = (System.currentTimeMillis() - mPrevDrawTime) / 1000.0 + val isDrawFrame = mRequestRender || (mRenderMode == RENDERMODE_CONTINUOUSLY && secondsPassed >= secondsPerFrame) + if (isDrawFrame) + mPrevDrawTime = System.currentTimeMillis() + isDrawFrame + } else + false } var renderMode: Int @@ -1607,6 +1628,16 @@ open class GLTextureView @JvmOverloads constructor( } } + var fps: Int + get() { + threadLock.withLock { return mFPS } + } + set(fps) { + threadLock.withLock { + mRenderMode = fps + } + } + fun requestRender() { threadLock.withLock { mRequestRender = true @@ -1797,6 +1828,8 @@ open class GLTextureView @JvmOverloads constructor( private var mShouldReleaseEglContext = false private var mWidth = 0 private var mHeight = 0 + private var mPrevDrawTime: Long = Long.MIN_VALUE + private var mFPS = 0 private var mRenderMode: Int private var mRequestRender = true private var mWantRenderNotification: Boolean From 9e58f5c093a9f205ddd86f8741006f0ed3b0f22c Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 02:20:30 -0400 Subject: [PATCH 03/30] Changed fps to be used in the await call of the drawing thread rather than the function that checks if ready to draw shader. --- .../shaderview/gl/view/GLTextureView.kt | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index 4409889..ffea6a0 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -12,6 +12,7 @@ import androidx.annotation.CallSuper import com.appspell.shaderview.log.LibLog import java.io.Writer import java.lang.ref.WeakReference +import java.util.concurrent.TimeUnit import java.util.concurrent.locks.ReentrantLock import javax.microedition.khronos.egl.* import javax.microedition.khronos.opengles.GL @@ -1479,7 +1480,7 @@ open class GLTextureView @JvmOverloads constructor( + " mRenderMode: " + mRenderMode) ) } - threadLockCondition.await() + threadLockCondition.await((1.0 / mFPS).toLong(), TimeUnit.SECONDS) } } // end of synchronized(sGLThreadManager) if (event != null) { @@ -1604,16 +1605,9 @@ open class GLTextureView @JvmOverloads constructor( } private fun readyToDraw(): Boolean { - val canDraw = !mPaused && mHasSurface && !mSurfaceIsBad && mWidth > 0 && mHeight > 0 - return if (canDraw) { - val secondsPerFrame = 1.0 / mFPS - val secondsPassed = (System.currentTimeMillis() - mPrevDrawTime) / 1000.0 - val isDrawFrame = mRequestRender || (mRenderMode == RENDERMODE_CONTINUOUSLY && secondsPassed >= secondsPerFrame) - if (isDrawFrame) - mPrevDrawTime = System.currentTimeMillis() - isDrawFrame - } else - false + return (!mPaused && mHasSurface && !mSurfaceIsBad + && mWidth > 0 && mHeight > 0 + && (mRequestRender || mRenderMode == RENDERMODE_CONTINUOUSLY)) } var renderMode: Int @@ -1828,7 +1822,6 @@ open class GLTextureView @JvmOverloads constructor( private var mShouldReleaseEglContext = false private var mWidth = 0 private var mHeight = 0 - private var mPrevDrawTime: Long = Long.MIN_VALUE private var mFPS = 0 private var mRenderMode: Int private var mRequestRender = true From fd9e88f8f1931bbc36896c493fa488b35e0a3a89 Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 02:30:21 -0400 Subject: [PATCH 04/30] Fixed an issue where await was being given 0 rather than expected amount. Made an fps of 0 or lower a special case. Updated readme. --- README.md | 2 +- .../java/com/appspell/shaderview/gl/view/GLTextureView.kt | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f7e9a38..f409304 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ OR `updateContinuously` - should we render the view each frame (default is "false") -`fps` - At what framerate should the shader be drawn if updateContinuously set to true +`fps` - At what framerate should the shader be drawn if updateContinuously set to true (0 or below means as quickly as the device can handle) `debugMode` - enable or disable debug logs diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index ffea6a0..d181733 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1480,7 +1480,10 @@ open class GLTextureView @JvmOverloads constructor( + " mRenderMode: " + mRenderMode) ) } - threadLockCondition.await((1.0 / mFPS).toLong(), TimeUnit.SECONDS) + if (mFPS > 0) + threadLockCondition.await((1000.0 / mFPS).toLong(), TimeUnit.MILLISECONDS) + else + threadLockCondition.await() } } // end of synchronized(sGLThreadManager) if (event != null) { From 48d8d47df984c729808b73d8fcf590b6d4a1bc71 Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 02:58:39 -0400 Subject: [PATCH 05/30] Moved thread await to try and fix the continuous stuck issue --- .../com/appspell/shaderview/gl/view/GLTextureView.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index d181733..e1fd4fd 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1480,10 +1480,8 @@ open class GLTextureView @JvmOverloads constructor( + " mRenderMode: " + mRenderMode) ) } - if (mFPS > 0) - threadLockCondition.await((1000.0 / mFPS).toLong(), TimeUnit.MILLISECONDS) - else - threadLockCondition.await() + + threadLockCondition.await() } } // end of synchronized(sGLThreadManager) if (event != null) { @@ -1591,6 +1589,9 @@ open class GLTextureView @JvmOverloads constructor( doRenderNotification = true wantRenderNotification = false } + + if (mFPS > 0) + threadLockCondition.await((1000f / mFPS).toLong(), TimeUnit.MILLISECONDS) } } finally { /* From e0c769721f54dd1d098230092d4974eb52767b17 Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 04:04:38 -0400 Subject: [PATCH 06/30] Trying a different approach where the draw call is limited directly --- .../shaderview/gl/view/GLTextureView.kt | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index e1fd4fd..ec59336 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1545,24 +1545,31 @@ open class GLTextureView @JvmOverloads constructor( if (enableLogRendererDrawFrame) { LibLog.w("GLThread", "onDrawFrame tid=$id") } - run { - val view = mGLTextureViewWeakRef.get() - if (view != null) { - try { - Trace.traceBegin( - Trace.TRACE_TAG_VIEW, - "onDrawFrame" - ) - view.mRenderer?.onDrawFrame(gl) - if (finishDrawingRunnable != null) { - finishDrawingRunnable!!.run() - finishDrawingRunnable = null + + val secondsPerFrame = 1f / mFPS + val deltaTime = (System.currentTimeMillis() - mPrevDrawTime) / 1000f + if (deltaTime >= secondsPerFrame) { + mPrevDrawTime = System.currentTimeMillis() + run { + val view = mGLTextureViewWeakRef.get() + if (view != null) { + try { + Trace.traceBegin( + Trace.TRACE_TAG_VIEW, + "onDrawFrame" + ) + view.mRenderer?.onDrawFrame(gl) + if (finishDrawingRunnable != null) { + finishDrawingRunnable!!.run() + finishDrawingRunnable = null + } + } finally { + Trace.traceEnd(Trace.TRACE_TAG_VIEW) } - } finally { - Trace.traceEnd(Trace.TRACE_TAG_VIEW) } } } + val swapError = mEglHelper!!.swap() when (swapError) { EGL10.EGL_SUCCESS -> { @@ -1589,9 +1596,6 @@ open class GLTextureView @JvmOverloads constructor( doRenderNotification = true wantRenderNotification = false } - - if (mFPS > 0) - threadLockCondition.await((1000f / mFPS).toLong(), TimeUnit.MILLISECONDS) } } finally { /* @@ -1826,6 +1830,7 @@ open class GLTextureView @JvmOverloads constructor( private var mShouldReleaseEglContext = false private var mWidth = 0 private var mHeight = 0 + private var mPrevDrawTime: Long = Long.MIN_VALUE private var mFPS = 0 private var mRenderMode: Int private var mRequestRender = true From db33fd1f4bbdc295bca8034b8872201b93f46e02 Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 04:13:20 -0400 Subject: [PATCH 07/30] Localized fps limiter even further --- .../shaderview/gl/view/GLTextureView.kt | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index ec59336..fcaa4f0 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1546,30 +1546,31 @@ open class GLTextureView @JvmOverloads constructor( LibLog.w("GLThread", "onDrawFrame tid=$id") } - val secondsPerFrame = 1f / mFPS - val deltaTime = (System.currentTimeMillis() - mPrevDrawTime) / 1000f - if (deltaTime >= secondsPerFrame) { - mPrevDrawTime = System.currentTimeMillis() - run { - val view = mGLTextureViewWeakRef.get() - if (view != null) { - try { - Trace.traceBegin( - Trace.TRACE_TAG_VIEW, - "onDrawFrame" - ) + + run { + val view = mGLTextureViewWeakRef.get() + if (view != null) { + try { + Trace.traceBegin( + Trace.TRACE_TAG_VIEW, + "onDrawFrame" + ) + val secondsPerFrame = 1f / mFPS + val deltaTime = (System.currentTimeMillis() - mPrevDrawTime) / 1000f + if (mFPS < 0 || deltaTime >= secondsPerFrame) { + mPrevDrawTime = System.currentTimeMillis() view.mRenderer?.onDrawFrame(gl) - if (finishDrawingRunnable != null) { - finishDrawingRunnable!!.run() - finishDrawingRunnable = null - } - } finally { - Trace.traceEnd(Trace.TRACE_TAG_VIEW) } + if (finishDrawingRunnable != null) { + finishDrawingRunnable!!.run() + finishDrawingRunnable = null + } + } finally { + Trace.traceEnd(Trace.TRACE_TAG_VIEW) } } } - + val swapError = mEglHelper!!.swap() when (swapError) { EGL10.EGL_SUCCESS -> { From 3204c02277ba8722592fc311c9297cfc98583eda Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 17:49:14 -0400 Subject: [PATCH 08/30] Moved back to await method but set it to right before drawing happens --- .../com/appspell/shaderview/gl/view/GLTextureView.kt | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index fcaa4f0..36be10b 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1546,7 +1546,8 @@ open class GLTextureView @JvmOverloads constructor( LibLog.w("GLThread", "onDrawFrame tid=$id") } - + if (mFPS > 0) + threadLockCondition.await((1000f / mFPS).toLong(), TimeUnit.MILLISECONDS); run { val view = mGLTextureViewWeakRef.get() if (view != null) { @@ -1555,12 +1556,7 @@ open class GLTextureView @JvmOverloads constructor( Trace.TRACE_TAG_VIEW, "onDrawFrame" ) - val secondsPerFrame = 1f / mFPS - val deltaTime = (System.currentTimeMillis() - mPrevDrawTime) / 1000f - if (mFPS < 0 || deltaTime >= secondsPerFrame) { - mPrevDrawTime = System.currentTimeMillis() - view.mRenderer?.onDrawFrame(gl) - } + view.mRenderer?.onDrawFrame(gl) if (finishDrawingRunnable != null) { finishDrawingRunnable!!.run() finishDrawingRunnable = null @@ -1831,7 +1827,6 @@ open class GLTextureView @JvmOverloads constructor( private var mShouldReleaseEglContext = false private var mWidth = 0 private var mHeight = 0 - private var mPrevDrawTime: Long = Long.MIN_VALUE private var mFPS = 0 private var mRenderMode: Int private var mRequestRender = true From 4a477e2c3a77759f60269fe9202450bcb36b32c5 Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 18:17:36 -0400 Subject: [PATCH 09/30] Removed semicolon and encapsulated line --- .../java/com/appspell/shaderview/gl/view/GLTextureView.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index 36be10b..6169e07 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1546,8 +1546,9 @@ open class GLTextureView @JvmOverloads constructor( LibLog.w("GLThread", "onDrawFrame tid=$id") } - if (mFPS > 0) - threadLockCondition.await((1000f / mFPS).toLong(), TimeUnit.MILLISECONDS); + if (mFPS > 0) { + threadLockCondition.await((1000f / mFPS).toLong(), TimeUnit.MILLISECONDS) + } run { val view = mGLTextureViewWeakRef.get() if (view != null) { From 9dcf58239d0e8db8e51ade0a3baefc2023e5149c Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 18:32:36 -0400 Subject: [PATCH 10/30] Quick sanity check --- .../java/com/appspell/shaderview/gl/view/GLTextureView.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index 6169e07..95d41d1 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1546,9 +1546,9 @@ open class GLTextureView @JvmOverloads constructor( LibLog.w("GLThread", "onDrawFrame tid=$id") } - if (mFPS > 0) { - threadLockCondition.await((1000f / mFPS).toLong(), TimeUnit.MILLISECONDS) - } + //if (mFPS > 0) { + // threadLockCondition.await((1000f / mFPS).toLong(), TimeUnit.MILLISECONDS) + //} run { val view = mGLTextureViewWeakRef.get() if (view != null) { From 8adc714c623b6cc7bd702537c4c241728fbfc84e Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 18:54:59 -0400 Subject: [PATCH 11/30] Fixed a stupid mistake where setting fps would set render mode instead --- .../java/com/appspell/shaderview/gl/view/GLTextureView.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index 95d41d1..9bed8da 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1546,9 +1546,9 @@ open class GLTextureView @JvmOverloads constructor( LibLog.w("GLThread", "onDrawFrame tid=$id") } - //if (mFPS > 0) { - // threadLockCondition.await((1000f / mFPS).toLong(), TimeUnit.MILLISECONDS) - //} + if (mFPS > 0) { + threadLockCondition.await((1000f / mFPS).toLong(), TimeUnit.MILLISECONDS) + } run { val view = mGLTextureViewWeakRef.get() if (view != null) { @@ -1634,7 +1634,7 @@ open class GLTextureView @JvmOverloads constructor( } set(fps) { threadLock.withLock { - mRenderMode = fps + mFPS = fps } } From 72c55d0a1319babd6c48860f7fc0dc5670f1e246 Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 20:12:04 -0400 Subject: [PATCH 12/30] Reverted to original method --- .../shaderview/gl/view/GLTextureView.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index 9bed8da..da71445 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1546,9 +1546,6 @@ open class GLTextureView @JvmOverloads constructor( LibLog.w("GLThread", "onDrawFrame tid=$id") } - if (mFPS > 0) { - threadLockCondition.await((1000f / mFPS).toLong(), TimeUnit.MILLISECONDS) - } run { val view = mGLTextureViewWeakRef.get() if (view != null) { @@ -1611,9 +1608,16 @@ open class GLTextureView @JvmOverloads constructor( } private fun readyToDraw(): Boolean { - return (!mPaused && mHasSurface && !mSurfaceIsBad - && mWidth > 0 && mHeight > 0 - && (mRequestRender || mRenderMode == RENDERMODE_CONTINUOUSLY)) + val canDraw = !mPaused && mHasSurface && !mSurfaceIsBad && mWidth > 0 && mHeight > 0 + return if (canDraw) { + val secondsPerFrame = 1f / mFPS + val secondsPassed = (System.currentTimeMillis() - mPrevDrawTime) / 1000f + val isDrawFrame = mRequestRender || (mRenderMode == RENDERMODE_CONTINUOUSLY && secondsPassed >= secondsPerFrame) + if (isDrawFrame) + mPrevDrawTime = System.currentTimeMillis() + isDrawFrame + } else + false } var renderMode: Int @@ -1828,6 +1832,7 @@ open class GLTextureView @JvmOverloads constructor( private var mShouldReleaseEglContext = false private var mWidth = 0 private var mHeight = 0 + private var mPrevDrawTime: Long = Long.MIN_VALUE private var mFPS = 0 private var mRenderMode: Int private var mRequestRender = true From 6c9084fffef63c39980d4db9fc18d11cbba8bd40 Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 20:23:00 -0400 Subject: [PATCH 13/30] Added debug message to check under the hood --- .../java/com/appspell/shaderview/gl/view/GLTextureView.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index da71445..d7a8c6e 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -6,6 +6,7 @@ import android.opengl.EGL14 import android.opengl.EGLExt import android.opengl.GLDebugHelper import android.util.AttributeSet +import android.util.Log import android.view.TextureView import android.view.View import androidx.annotation.CallSuper @@ -1612,7 +1613,9 @@ open class GLTextureView @JvmOverloads constructor( return if (canDraw) { val secondsPerFrame = 1f / mFPS val secondsPassed = (System.currentTimeMillis() - mPrevDrawTime) / 1000f - val isDrawFrame = mRequestRender || (mRenderMode == RENDERMODE_CONTINUOUSLY && secondsPassed >= secondsPerFrame) + val timeForNexFrame = secondsPassed >= secondsPerFrame; + Log.d("GLTextureView", "$secondsPassed >= $secondsPerFrame ? $timeForNexFrame"); + val isDrawFrame = mRequestRender || (mRenderMode == RENDERMODE_CONTINUOUSLY && timeForNexFrame) if (isDrawFrame) mPrevDrawTime = System.currentTimeMillis() isDrawFrame From b6a9e569545b425be111c9385fe3f1a44f57cb37 Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 20:32:30 -0400 Subject: [PATCH 14/30] Switched to previously tried approach --- .../shaderview/gl/view/GLTextureView.kt | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index d7a8c6e..916f47f 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1547,21 +1547,28 @@ open class GLTextureView @JvmOverloads constructor( LibLog.w("GLThread", "onDrawFrame tid=$id") } - run { - val view = mGLTextureViewWeakRef.get() - if (view != null) { - try { - Trace.traceBegin( - Trace.TRACE_TAG_VIEW, - "onDrawFrame" - ) - view.mRenderer?.onDrawFrame(gl) - if (finishDrawingRunnable != null) { - finishDrawingRunnable!!.run() - finishDrawingRunnable = null + val secondsPerFrame = 1f / mFPS + val secondsPassed = (System.currentTimeMillis() - mPrevDrawTime) / 1000f + val timeForNexFrame = secondsPassed >= secondsPerFrame + Log.d("GLTextureView", "$secondsPassed >= $secondsPerFrame ? $timeForNexFrame") + if (timeForNexFrame) { + mPrevDrawTime = System.currentTimeMillis() + run { + val view = mGLTextureViewWeakRef.get() + if (view != null) { + try { + Trace.traceBegin( + Trace.TRACE_TAG_VIEW, + "onDrawFrame" + ) + view.mRenderer?.onDrawFrame(gl) + if (finishDrawingRunnable != null) { + finishDrawingRunnable!!.run() + finishDrawingRunnable = null + } + } finally { + Trace.traceEnd(Trace.TRACE_TAG_VIEW) } - } finally { - Trace.traceEnd(Trace.TRACE_TAG_VIEW) } } } @@ -1609,18 +1616,9 @@ open class GLTextureView @JvmOverloads constructor( } private fun readyToDraw(): Boolean { - val canDraw = !mPaused && mHasSurface && !mSurfaceIsBad && mWidth > 0 && mHeight > 0 - return if (canDraw) { - val secondsPerFrame = 1f / mFPS - val secondsPassed = (System.currentTimeMillis() - mPrevDrawTime) / 1000f - val timeForNexFrame = secondsPassed >= secondsPerFrame; - Log.d("GLTextureView", "$secondsPassed >= $secondsPerFrame ? $timeForNexFrame"); - val isDrawFrame = mRequestRender || (mRenderMode == RENDERMODE_CONTINUOUSLY && timeForNexFrame) - if (isDrawFrame) - mPrevDrawTime = System.currentTimeMillis() - isDrawFrame - } else - false + return (!mPaused && mHasSurface && !mSurfaceIsBad + && mWidth > 0 && mHeight > 0 + && (mRequestRender || mRenderMode == RENDERMODE_CONTINUOUSLY)) } var renderMode: Int From cbec733ccdc64a3120e1a5e8ac3a42ca0d93e32e Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 20:38:16 -0400 Subject: [PATCH 15/30] Changed start value of prevDrawTime --- .../main/java/com/appspell/shaderview/gl/view/GLTextureView.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index 916f47f..73b5004 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1833,7 +1833,7 @@ open class GLTextureView @JvmOverloads constructor( private var mShouldReleaseEglContext = false private var mWidth = 0 private var mHeight = 0 - private var mPrevDrawTime: Long = Long.MIN_VALUE + private var mPrevDrawTime: Long = System.currentTimeMillis() private var mFPS = 0 private var mRenderMode: Int private var mRequestRender = true From d526f3ccbd314ac40ddd605f5eb1beea8e3668ff Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 20:48:18 -0400 Subject: [PATCH 16/30] Changed scope of mPrevDrawTime. Removed debug message. --- .../java/com/appspell/shaderview/gl/view/GLTextureView.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index 73b5004..ffbde9f 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1287,6 +1287,7 @@ open class GLTextureView @JvmOverloads constructor( var h = 0 var event: Runnable? = null var finishDrawingRunnable: Runnable? = null + var prevDrawTime = System.currentTimeMillis() while (true) { threadLock.withLock { while (true) { @@ -1548,11 +1549,10 @@ open class GLTextureView @JvmOverloads constructor( } val secondsPerFrame = 1f / mFPS - val secondsPassed = (System.currentTimeMillis() - mPrevDrawTime) / 1000f + val secondsPassed = (System.currentTimeMillis() - prevDrawTime) / 1000f val timeForNexFrame = secondsPassed >= secondsPerFrame - Log.d("GLTextureView", "$secondsPassed >= $secondsPerFrame ? $timeForNexFrame") if (timeForNexFrame) { - mPrevDrawTime = System.currentTimeMillis() + prevDrawTime = System.currentTimeMillis() run { val view = mGLTextureViewWeakRef.get() if (view != null) { @@ -1833,7 +1833,6 @@ open class GLTextureView @JvmOverloads constructor( private var mShouldReleaseEglContext = false private var mWidth = 0 private var mHeight = 0 - private var mPrevDrawTime: Long = System.currentTimeMillis() private var mFPS = 0 private var mRenderMode: Int private var mRequestRender = true From 779e0c34247e79fe214d267212c6fd623888540f Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 20:55:18 -0400 Subject: [PATCH 17/30] Attempt at making timestep more accurate --- .../java/com/appspell/shaderview/gl/view/GLTextureView.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index ffbde9f..df8dce5 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1548,9 +1548,9 @@ open class GLTextureView @JvmOverloads constructor( LibLog.w("GLThread", "onDrawFrame tid=$id") } - val secondsPerFrame = 1f / mFPS - val secondsPassed = (System.currentTimeMillis() - prevDrawTime) / 1000f - val timeForNexFrame = secondsPassed >= secondsPerFrame + val millisPerFrame = 1000.0 / mFPS + val millisPassed = System.currentTimeMillis() - prevDrawTime + val timeForNexFrame = millisPassed >= millisPerFrame if (timeForNexFrame) { prevDrawTime = System.currentTimeMillis() run { From eb78cfcf59024e21e8d6eb4dbd0fc57b604750ab Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 21:03:44 -0400 Subject: [PATCH 18/30] More localized again --- .../shaderview/gl/view/GLTextureView.kt | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index df8dce5..e374808 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1548,27 +1548,28 @@ open class GLTextureView @JvmOverloads constructor( LibLog.w("GLThread", "onDrawFrame tid=$id") } - val millisPerFrame = 1000.0 / mFPS - val millisPassed = System.currentTimeMillis() - prevDrawTime - val timeForNexFrame = millisPassed >= millisPerFrame - if (timeForNexFrame) { - prevDrawTime = System.currentTimeMillis() - run { - val view = mGLTextureViewWeakRef.get() - if (view != null) { - try { - Trace.traceBegin( - Trace.TRACE_TAG_VIEW, - "onDrawFrame" - ) + + run { + val view = mGLTextureViewWeakRef.get() + if (view != null) { + try { + Trace.traceBegin( + Trace.TRACE_TAG_VIEW, + "onDrawFrame" + ) + val millisPerFrame = 1000.0 / mFPS + val millisPassed = System.currentTimeMillis() - prevDrawTime + val timeForNexFrame = millisPassed >= millisPerFrame + if (timeForNexFrame) { + prevDrawTime = System.currentTimeMillis() view.mRenderer?.onDrawFrame(gl) - if (finishDrawingRunnable != null) { - finishDrawingRunnable!!.run() - finishDrawingRunnable = null - } - } finally { - Trace.traceEnd(Trace.TRACE_TAG_VIEW) } + if (finishDrawingRunnable != null) { + finishDrawingRunnable!!.run() + finishDrawingRunnable = null + } + } finally { + Trace.traceEnd(Trace.TRACE_TAG_VIEW) } } } From 12c50447d0d395c670b63ff714cfc23a82110c63 Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 21:15:24 -0400 Subject: [PATCH 19/30] Unlocalized fps. Added more debug messages. --- .../shaderview/gl/view/GLTextureView.kt | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index e374808..7666d73 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1522,6 +1522,7 @@ open class GLTextureView @JvmOverloads constructor( if (view != null) { try { Trace.traceBegin(Trace.TRACE_TAG_VIEW, "onSurfaceCreated") + Log.d("GLTextureView", "Surface created"); view.mRenderer?.onSurfaceCreated(gl, mEglHelper!!.mEglConfig) } finally { Trace.traceEnd(Trace.TRACE_TAG_VIEW) @@ -1537,6 +1538,7 @@ open class GLTextureView @JvmOverloads constructor( if (view != null) { try { Trace.traceBegin(Trace.TRACE_TAG_VIEW, "onSurfaceChanged") + Log.d("GLTextureView", "Surface changed"); view.mRenderer?.onSurfaceChanged(gl, w, h) } finally { Trace.traceEnd(Trace.TRACE_TAG_VIEW) @@ -1548,28 +1550,28 @@ open class GLTextureView @JvmOverloads constructor( LibLog.w("GLThread", "onDrawFrame tid=$id") } - - run { - val view = mGLTextureViewWeakRef.get() - if (view != null) { - try { - Trace.traceBegin( - Trace.TRACE_TAG_VIEW, - "onDrawFrame" - ) - val millisPerFrame = 1000.0 / mFPS - val millisPassed = System.currentTimeMillis() - prevDrawTime - val timeForNexFrame = millisPassed >= millisPerFrame - if (timeForNexFrame) { - prevDrawTime = System.currentTimeMillis() + val millisPerFrame = 1000.0 / mFPS + val millisPassed = System.currentTimeMillis() - prevDrawTime + val timeForNexFrame = millisPassed >= millisPerFrame + if (timeForNexFrame) { + prevDrawTime = System.currentTimeMillis() + run { + val view = mGLTextureViewWeakRef.get() + if (view != null) { + try { + Trace.traceBegin( + Trace.TRACE_TAG_VIEW, + "onDrawFrame" + ) + Log.d("GLTextureView", "Draw frame"); view.mRenderer?.onDrawFrame(gl) + if (finishDrawingRunnable != null) { + finishDrawingRunnable!!.run() + finishDrawingRunnable = null + } + } finally { + Trace.traceEnd(Trace.TRACE_TAG_VIEW) } - if (finishDrawingRunnable != null) { - finishDrawingRunnable!!.run() - finishDrawingRunnable = null - } - } finally { - Trace.traceEnd(Trace.TRACE_TAG_VIEW) } } } From c61db6f75f41dd756c741ac781359c243681ef0f Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 21:28:52 -0400 Subject: [PATCH 20/30] Opted for microseconds for more accuracy. Added and removed some debug messages. --- .../appspell/shaderview/gl/view/GLTextureView.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index 7666d73..0c23b96 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -445,6 +445,7 @@ open class GLTextureView @JvmOverloads constructor( * from any thread. Must not be called before a renderer has been set. */ fun requestRender() { + Log.d("GLTextureView", "Render requested") mGLThread!!.requestRender() } @@ -453,6 +454,7 @@ open class GLTextureView @JvmOverloads constructor( * not normally called or subclassed by clients of GLTextureView. */ fun surfaceCreated(holder: SurfaceTexture?) { + Log.d("GLTextureView", "Surface created") mGLThread!!.surfaceCreated() } @@ -470,6 +472,7 @@ open class GLTextureView @JvmOverloads constructor( * not normally called or subclassed by clients of GLTextureView. */ fun surfaceChanged(holder: SurfaceTexture?, format: Int, w: Int, h: Int) { + Log.d("GLTextureView", "Surface changed") mGLThread!!.onWindowResize(w, h) } @@ -529,6 +532,7 @@ open class GLTextureView @JvmOverloads constructor( * @param r the runnable to be run on the GL rendering thread. */ fun queueEvent(r: Runnable?) { + Log.d("GLTextureView", "Event queued") mGLThread!!.queueEvent(r) } @@ -1522,7 +1526,6 @@ open class GLTextureView @JvmOverloads constructor( if (view != null) { try { Trace.traceBegin(Trace.TRACE_TAG_VIEW, "onSurfaceCreated") - Log.d("GLTextureView", "Surface created"); view.mRenderer?.onSurfaceCreated(gl, mEglHelper!!.mEglConfig) } finally { Trace.traceEnd(Trace.TRACE_TAG_VIEW) @@ -1538,7 +1541,6 @@ open class GLTextureView @JvmOverloads constructor( if (view != null) { try { Trace.traceBegin(Trace.TRACE_TAG_VIEW, "onSurfaceChanged") - Log.d("GLTextureView", "Surface changed"); view.mRenderer?.onSurfaceChanged(gl, w, h) } finally { Trace.traceEnd(Trace.TRACE_TAG_VIEW) @@ -1550,11 +1552,11 @@ open class GLTextureView @JvmOverloads constructor( LibLog.w("GLThread", "onDrawFrame tid=$id") } - val millisPerFrame = 1000.0 / mFPS - val millisPassed = System.currentTimeMillis() - prevDrawTime - val timeForNexFrame = millisPassed >= millisPerFrame + val microsPerFrame = 1000000.0 / mFPS + val microsPassed = (System.currentTimeMillis() * 1000) - prevDrawTime + val timeForNexFrame = microsPassed >= microsPerFrame if (timeForNexFrame) { - prevDrawTime = System.currentTimeMillis() + prevDrawTime = System.currentTimeMillis() * 1000 run { val view = mGLTextureViewWeakRef.get() if (view != null) { From 131bdf955e32385d86392d6eaf83d49beff5c4a8 Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 21:37:08 -0400 Subject: [PATCH 21/30] Removed some debug messages. Localized again. --- .../shaderview/gl/view/GLTextureView.kt | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index 0c23b96..a6f36c5 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -445,7 +445,6 @@ open class GLTextureView @JvmOverloads constructor( * from any thread. Must not be called before a renderer has been set. */ fun requestRender() { - Log.d("GLTextureView", "Render requested") mGLThread!!.requestRender() } @@ -454,7 +453,6 @@ open class GLTextureView @JvmOverloads constructor( * not normally called or subclassed by clients of GLTextureView. */ fun surfaceCreated(holder: SurfaceTexture?) { - Log.d("GLTextureView", "Surface created") mGLThread!!.surfaceCreated() } @@ -472,7 +470,6 @@ open class GLTextureView @JvmOverloads constructor( * not normally called or subclassed by clients of GLTextureView. */ fun surfaceChanged(holder: SurfaceTexture?, format: Int, w: Int, h: Int) { - Log.d("GLTextureView", "Surface changed") mGLThread!!.onWindowResize(w, h) } @@ -532,7 +529,6 @@ open class GLTextureView @JvmOverloads constructor( * @param r the runnable to be run on the GL rendering thread. */ fun queueEvent(r: Runnable?) { - Log.d("GLTextureView", "Event queued") mGLThread!!.queueEvent(r) } @@ -1552,11 +1548,7 @@ open class GLTextureView @JvmOverloads constructor( LibLog.w("GLThread", "onDrawFrame tid=$id") } - val microsPerFrame = 1000000.0 / mFPS - val microsPassed = (System.currentTimeMillis() * 1000) - prevDrawTime - val timeForNexFrame = microsPassed >= microsPerFrame - if (timeForNexFrame) { - prevDrawTime = System.currentTimeMillis() * 1000 + run { val view = mGLTextureViewWeakRef.get() if (view != null) { @@ -1565,8 +1557,14 @@ open class GLTextureView @JvmOverloads constructor( Trace.TRACE_TAG_VIEW, "onDrawFrame" ) - Log.d("GLTextureView", "Draw frame"); - view.mRenderer?.onDrawFrame(gl) + val microsPerFrame = (1000000.0 / mFPS).toLong() + val microsPassed = (System.currentTimeMillis() * 1000) - prevDrawTime + val timeForNexFrame = microsPassed >= microsPerFrame + if (timeForNexFrame) { + prevDrawTime = System.currentTimeMillis() * 1000 + Log.d("GLTextureView", "Draw frame"); + view.mRenderer?.onDrawFrame(gl) + } if (finishDrawingRunnable != null) { finishDrawingRunnable!!.run() finishDrawingRunnable = null @@ -1576,7 +1574,6 @@ open class GLTextureView @JvmOverloads constructor( } } } - } val swapError = mEglHelper!!.swap() when (swapError) { From 259db6b421be0523cff8e74c81380e430acba073 Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 21:46:09 -0400 Subject: [PATCH 22/30] Added more debug messages --- .../java/com/appspell/shaderview/gl/render/GLQuadRender.kt | 2 ++ .../java/com/appspell/shaderview/gl/view/GLTextureView.kt | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/render/GLQuadRender.kt b/lib/src/main/java/com/appspell/shaderview/gl/render/GLQuadRender.kt index a003404..4e8153a 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/render/GLQuadRender.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/render/GLQuadRender.kt @@ -3,6 +3,7 @@ package com.appspell.shaderview.gl.render import android.opengl.GLES20 import android.opengl.GLES30 import android.opengl.Matrix +import android.util.Log import com.appspell.shaderview.gl.params.ShaderParams import com.appspell.shaderview.gl.shader.GLShader import com.appspell.shaderview.gl.view.GLTextureView @@ -108,6 +109,7 @@ internal class GLQuadRenderImpl( } override fun onDrawFrame(gl: GL10?) { + Log.d("GLQuadRenderImpl", "Draw frame"); if (!shader.isReady) { return } diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index a6f36c5..4bb7490 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -13,7 +13,6 @@ import androidx.annotation.CallSuper import com.appspell.shaderview.log.LibLog import java.io.Writer import java.lang.ref.WeakReference -import java.util.concurrent.TimeUnit import java.util.concurrent.locks.ReentrantLock import javax.microedition.khronos.egl.* import javax.microedition.khronos.opengles.GL @@ -1559,8 +1558,9 @@ open class GLTextureView @JvmOverloads constructor( ) val microsPerFrame = (1000000.0 / mFPS).toLong() val microsPassed = (System.currentTimeMillis() * 1000) - prevDrawTime - val timeForNexFrame = microsPassed >= microsPerFrame - if (timeForNexFrame) { + val isTimeForNextFrame = microsPassed >= microsPerFrame + Log.d("GLTextureView", "$microsPassed >= $microsPerFrame ? $isTimeForNextFrame"); + if (isTimeForNextFrame) { prevDrawTime = System.currentTimeMillis() * 1000 Log.d("GLTextureView", "Draw frame"); view.mRenderer?.onDrawFrame(gl) From d530a0e4a769b4ce7e63fa9df856cffe9816eb70 Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 22:00:08 -0400 Subject: [PATCH 23/30] Unlocalized again but included more into the if statement. Removed a debug message. --- .../shaderview/gl/view/GLTextureView.kt | 69 ++++++++++--------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index 4bb7490..792671f 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1547,7 +1547,14 @@ open class GLTextureView @JvmOverloads constructor( LibLog.w("GLThread", "onDrawFrame tid=$id") } - + val millisPerFrame = (1000f / mFPS).toLong() + val millisPassed = (System.currentTimeMillis()) - prevDrawTime + val isTimeForNextFrame = millisPassed >= millisPerFrame + //Frames passed at a rate of 1 per millisecond + //Log.d("GLTextureView", "$microsPassed >= $microsPerFrame ? $isTimeForNextFrame"); + if (isTimeForNextFrame) { + prevDrawTime = System.currentTimeMillis() + Log.d("GLTextureView", "Draw frame"); run { val view = mGLTextureViewWeakRef.get() if (view != null) { @@ -1556,15 +1563,8 @@ open class GLTextureView @JvmOverloads constructor( Trace.TRACE_TAG_VIEW, "onDrawFrame" ) - val microsPerFrame = (1000000.0 / mFPS).toLong() - val microsPassed = (System.currentTimeMillis() * 1000) - prevDrawTime - val isTimeForNextFrame = microsPassed >= microsPerFrame - Log.d("GLTextureView", "$microsPassed >= $microsPerFrame ? $isTimeForNextFrame"); - if (isTimeForNextFrame) { - prevDrawTime = System.currentTimeMillis() * 1000 - Log.d("GLTextureView", "Draw frame"); - view.mRenderer?.onDrawFrame(gl) - } + + view.mRenderer?.onDrawFrame(gl) if (finishDrawingRunnable != null) { finishDrawingRunnable!!.run() finishDrawingRunnable = null @@ -1575,31 +1575,36 @@ open class GLTextureView @JvmOverloads constructor( } } - val swapError = mEglHelper!!.swap() - when (swapError) { - EGL10.EGL_SUCCESS -> { - } - EGL11.EGL_CONTEXT_LOST -> { - if (enableLogSurface) { - LibLog.i("GLThread", "egl context lost tid=$id") + val swapError = mEglHelper!!.swap() + when (swapError) { + EGL10.EGL_SUCCESS -> { } - lostEglContext = true - } - else -> { - // Other errors typically mean that the current surface is bad, - // probably because the SurfaceView surface has been destroyed, - // but we haven't been notified yet. - // Log the error to help developers understand why rendering stopped. - LogHelper.logEglErrorAsWarning("GLThread", "eglSwapBuffers", swapError) - threadLock.withLock { - mSurfaceIsBad = true - threadLockCondition.signalAll() + EGL11.EGL_CONTEXT_LOST -> { + if (enableLogSurface) { + LibLog.i("GLThread", "egl context lost tid=$id") + } + lostEglContext = true + } + else -> { + // Other errors typically mean that the current surface is bad, + // probably because the SurfaceView surface has been destroyed, + // but we haven't been notified yet. + // Log the error to help developers understand why rendering stopped. + LogHelper.logEglErrorAsWarning( + "GLThread", + "eglSwapBuffers", + swapError + ) + threadLock.withLock { + mSurfaceIsBad = true + threadLockCondition.signalAll() + } } } - } - if (wantRenderNotification) { - doRenderNotification = true - wantRenderNotification = false + if (wantRenderNotification) { + doRenderNotification = true + wantRenderNotification = false + } } } } finally { From 404b4bf355e93d3d17b46fc2993678f5f35aabeb Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 22:17:06 -0400 Subject: [PATCH 24/30] Removed debug messages. Changed fps to framerate in ShaderView. Updated readme. --- README.md | 2 +- lib/src/main/java/com/appspell/shaderview/ShaderView.kt | 4 ++-- .../java/com/appspell/shaderview/gl/render/GLQuadRender.kt | 2 -- .../java/com/appspell/shaderview/gl/view/GLTextureView.kt | 4 ---- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f409304..b934611 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ OR `updateContinuously` - should we render the view each frame (default is "false") -`fps` - At what framerate should the shader be drawn if updateContinuously set to true (0 or below means as quickly as the device can handle) +`framerate` - The fps, or how many frames the shader should be drawn per second (-1 means every frame) `debugMode` - enable or disable debug logs diff --git a/lib/src/main/java/com/appspell/shaderview/ShaderView.kt b/lib/src/main/java/com/appspell/shaderview/ShaderView.kt index 28cb5ca..688ea56 100644 --- a/lib/src/main/java/com/appspell/shaderview/ShaderView.kt +++ b/lib/src/main/java/com/appspell/shaderview/ShaderView.kt @@ -98,9 +98,9 @@ class ShaderView @JvmOverloads constructor( } } - var fps: Int + var framerate: Int set(value) { - setFPS(fps) + setFPS(value) } get(): Int { return getFPS() diff --git a/lib/src/main/java/com/appspell/shaderview/gl/render/GLQuadRender.kt b/lib/src/main/java/com/appspell/shaderview/gl/render/GLQuadRender.kt index 4e8153a..a003404 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/render/GLQuadRender.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/render/GLQuadRender.kt @@ -3,7 +3,6 @@ package com.appspell.shaderview.gl.render import android.opengl.GLES20 import android.opengl.GLES30 import android.opengl.Matrix -import android.util.Log import com.appspell.shaderview.gl.params.ShaderParams import com.appspell.shaderview.gl.shader.GLShader import com.appspell.shaderview.gl.view.GLTextureView @@ -109,7 +108,6 @@ internal class GLQuadRenderImpl( } override fun onDrawFrame(gl: GL10?) { - Log.d("GLQuadRenderImpl", "Draw frame"); if (!shader.isReady) { return } diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index 792671f..981d3a6 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -6,7 +6,6 @@ import android.opengl.EGL14 import android.opengl.EGLExt import android.opengl.GLDebugHelper import android.util.AttributeSet -import android.util.Log import android.view.TextureView import android.view.View import androidx.annotation.CallSuper @@ -1550,11 +1549,8 @@ open class GLTextureView @JvmOverloads constructor( val millisPerFrame = (1000f / mFPS).toLong() val millisPassed = (System.currentTimeMillis()) - prevDrawTime val isTimeForNextFrame = millisPassed >= millisPerFrame - //Frames passed at a rate of 1 per millisecond - //Log.d("GLTextureView", "$microsPassed >= $microsPerFrame ? $isTimeForNextFrame"); if (isTimeForNextFrame) { prevDrawTime = System.currentTimeMillis() - Log.d("GLTextureView", "Draw frame"); run { val view = mGLTextureViewWeakRef.get() if (view != null) { From 1f985cb2dbc039f4f3f4b2a3fced66f34547dd6c Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 22:27:30 -0400 Subject: [PATCH 25/30] Added a comment to framerate in ShaderView. Made a small change to the readme. --- README.md | 2 +- lib/src/main/java/com/appspell/shaderview/ShaderView.kt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b934611..83a34f1 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ OR `updateContinuously` - should we render the view each frame (default is "false") -`framerate` - The fps, or how many frames the shader should be drawn per second (-1 means every frame) +`framerate` - The fps, or how many frames the shader should be drawn per second when update mode is set to continuously (-1 means every frame) `debugMode` - enable or disable debug logs diff --git a/lib/src/main/java/com/appspell/shaderview/ShaderView.kt b/lib/src/main/java/com/appspell/shaderview/ShaderView.kt index 688ea56..76112dc 100644 --- a/lib/src/main/java/com/appspell/shaderview/ShaderView.kt +++ b/lib/src/main/java/com/appspell/shaderview/ShaderView.kt @@ -98,6 +98,9 @@ class ShaderView @JvmOverloads constructor( } } + /** + * how many frames the shader should be drawn per second + */ var framerate: Int set(value) { setFPS(value) From 828e11f3722f5eb85e4e8264d8cbc7a59cfe3f55 Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Thu, 5 May 2022 22:41:56 -0400 Subject: [PATCH 26/30] Trying await method again. Made tiny change to readme. --- README.md | 2 +- .../shaderview/gl/view/GLTextureView.kt | 92 +++++++++---------- 2 files changed, 46 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 83a34f1..f53c646 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ OR `updateContinuously` - should we render the view each frame (default is "false") -`framerate` - The fps, or how many frames the shader should be drawn per second when update mode is set to continuously (-1 means every frame) +`framerate` - how many frames the shader should be drawn per second when update mode is set to continuously (-1 means every frame) `debugMode` - enable or disable debug logs diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index 981d3a6..aa6eb94 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -12,6 +12,7 @@ import androidx.annotation.CallSuper import com.appspell.shaderview.log.LibLog import java.io.Writer import java.lang.ref.WeakReference +import java.util.concurrent.TimeUnit import java.util.concurrent.locks.ReentrantLock import javax.microedition.khronos.egl.* import javax.microedition.khronos.opengles.GL @@ -1546,62 +1547,59 @@ open class GLTextureView @JvmOverloads constructor( LibLog.w("GLThread", "onDrawFrame tid=$id") } - val millisPerFrame = (1000f / mFPS).toLong() - val millisPassed = (System.currentTimeMillis()) - prevDrawTime - val isTimeForNextFrame = millisPassed >= millisPerFrame - if (isTimeForNextFrame) { - prevDrawTime = System.currentTimeMillis() - run { - val view = mGLTextureViewWeakRef.get() - if (view != null) { - try { - Trace.traceBegin( - Trace.TRACE_TAG_VIEW, - "onDrawFrame" - ) + run { + val view = mGLTextureViewWeakRef.get() + if (view != null) { + try { + Trace.traceBegin( + Trace.TRACE_TAG_VIEW, + "onDrawFrame" + ) - view.mRenderer?.onDrawFrame(gl) - if (finishDrawingRunnable != null) { - finishDrawingRunnable!!.run() - finishDrawingRunnable = null - } - } finally { - Trace.traceEnd(Trace.TRACE_TAG_VIEW) + view.mRenderer?.onDrawFrame(gl) + if (finishDrawingRunnable != null) { + finishDrawingRunnable!!.run() + finishDrawingRunnable = null } + } finally { + Trace.traceEnd(Trace.TRACE_TAG_VIEW) } } + } - val swapError = mEglHelper!!.swap() - when (swapError) { - EGL10.EGL_SUCCESS -> { - } - EGL11.EGL_CONTEXT_LOST -> { - if (enableLogSurface) { - LibLog.i("GLThread", "egl context lost tid=$id") - } - lostEglContext = true - } - else -> { - // Other errors typically mean that the current surface is bad, - // probably because the SurfaceView surface has been destroyed, - // but we haven't been notified yet. - // Log the error to help developers understand why rendering stopped. - LogHelper.logEglErrorAsWarning( - "GLThread", - "eglSwapBuffers", - swapError - ) - threadLock.withLock { - mSurfaceIsBad = true - threadLockCondition.signalAll() - } + val swapError = mEglHelper!!.swap() + when (swapError) { + EGL10.EGL_SUCCESS -> { + } + EGL11.EGL_CONTEXT_LOST -> { + if (enableLogSurface) { + LibLog.i("GLThread", "egl context lost tid=$id") } + lostEglContext = true } - if (wantRenderNotification) { - doRenderNotification = true - wantRenderNotification = false + else -> { + // Other errors typically mean that the current surface is bad, + // probably because the SurfaceView surface has been destroyed, + // but we haven't been notified yet. + // Log the error to help developers understand why rendering stopped. + LogHelper.logEglErrorAsWarning( + "GLThread", + "eglSwapBuffers", + swapError + ) + threadLock.withLock { + mSurfaceIsBad = true + threadLockCondition.signalAll() + } } } + if (wantRenderNotification) { + doRenderNotification = true + wantRenderNotification = false + } + + val millisPerFrame = (1000f / mFPS).toLong() + threadLockCondition.await(millisPerFrame, TimeUnit.MILLISECONDS); } } finally { /* From 069cb256aacf9bcdbccc32daf807e5db42080391 Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Fri, 6 May 2022 02:39:49 -0400 Subject: [PATCH 27/30] Changed await to sleep. --- .../main/java/com/appspell/shaderview/gl/view/GLTextureView.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index aa6eb94..bbebf29 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1599,7 +1599,7 @@ open class GLTextureView @JvmOverloads constructor( } val millisPerFrame = (1000f / mFPS).toLong() - threadLockCondition.await(millisPerFrame, TimeUnit.MILLISECONDS); + sleep(millisPerFrame); } } finally { /* From 5ee858efd9425d93321163c658db487dced82d4f Mon Sep 17 00:00:00 2001 From: Oxters Wyzgowski Date: Fri, 6 May 2022 03:29:52 -0400 Subject: [PATCH 28/30] Added special case fps. Made small change in readme. --- README.md | 2 +- .../java/com/appspell/shaderview/gl/view/GLTextureView.kt | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f53c646..b68f349 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ OR `updateContinuously` - should we render the view each frame (default is "false") -`framerate` - how many frames the shader should be drawn per second when update mode is set to continuously (-1 means every frame) +`framerate` - how many frames the shader should be drawn per second when update mode is set to continuously (<=0 means every frame) `debugMode` - enable or disable debug logs diff --git a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt index bbebf29..13439c8 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/view/GLTextureView.kt @@ -1286,7 +1286,6 @@ open class GLTextureView @JvmOverloads constructor( var h = 0 var event: Runnable? = null var finishDrawingRunnable: Runnable? = null - var prevDrawTime = System.currentTimeMillis() while (true) { threadLock.withLock { while (true) { @@ -1598,8 +1597,10 @@ open class GLTextureView @JvmOverloads constructor( wantRenderNotification = false } - val millisPerFrame = (1000f / mFPS).toLong() - sleep(millisPerFrame); + if (mFPS > 0) { + val millisPerFrame = (1000f / mFPS).toLong() + sleep(millisPerFrame); + } } } finally { /* From b3a16114f6dd7fba0a27f4369893fe9a22d2c21c Mon Sep 17 00:00:00 2001 From: Oxters Date: Sun, 2 Apr 2023 22:49:22 -0400 Subject: [PATCH 29/30] Removed runtime exception in checkGlError in GLQuadRender. Changed almost all GLES calls to be GLES32. --- README.md | 2 +- .../shaderview/demo/list/ShaderListAdapter.kt | 16 +-- .../annotations/ShaderExperimentalApi.kt | 2 +- .../com/appspell/shaderview/ext/Texture.kt | 31 +++--- .../gl/params/ShaderParamsBuilder.kt | 6 +- .../shaderview/gl/params/ShaderParamsImpl.kt | 98 +++++++++---------- .../shaderview/gl/params/SpecialParam.kt | 4 +- .../shaderview/gl/render/GLQuadRender.kt | 32 +++--- .../shaderview/gl/shader/GLShaderImpl.kt | 38 +++---- local.properties | 8 -- 10 files changed, 114 insertions(+), 123 deletions(-) delete mode 100644 local.properties diff --git a/README.md b/README.md index b68f349..d002673 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ shaderView.shaderParams = ShaderParamsBuilder() .addTexture2D( "uNormalTexture", // name of `sampler2D` in the fragment shader R.drawable.normal_button, // drawable that we use for such texture - GLES30.GL_TEXTURE0 // texture slot + GLES32.GL_TEXTURE0 // texture slot ) .addColor("uColor", R.color.grey, resources) // send color as `uniform vec4` .addVec4f("uColor2", floatArrayOf(0.5f, 0.5f, 0.5f, 1f)) diff --git a/demo/src/main/java/com/appspell/shaderview/demo/list/ShaderListAdapter.kt b/demo/src/main/java/com/appspell/shaderview/demo/list/ShaderListAdapter.kt index 6dab4d4..897ef3f 100644 --- a/demo/src/main/java/com/appspell/shaderview/demo/list/ShaderListAdapter.kt +++ b/demo/src/main/java/com/appspell/shaderview/demo/list/ShaderListAdapter.kt @@ -1,6 +1,6 @@ package com.appspell.shaderview.demo.list -import android.opengl.GLES30 +import android.opengl.GLES32 import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -74,17 +74,17 @@ class ShaderListAdapter : RecyclerView.Adapter .addTexture2D( "uTextureSampler1", R.drawable.bokeh, - GLES30.GL_TEXTURE0 + GLES32.GL_TEXTURE0 ) .addTexture2D( "uTextureSampler2", R.drawable.normal_button, - GLES30.GL_TEXTURE1 + GLES32.GL_TEXTURE1 ) .addTexture2D( "uTextureSampler3", R.drawable.test_texture, - GLES30.GL_TEXTURE2 + GLES32.GL_TEXTURE2 ) .build() } @@ -102,7 +102,7 @@ class ShaderListAdapter : RecyclerView.Adapter .addTexture2D( "uNormalTexture", R.drawable.normal_button, - GLES30.GL_TEXTURE0 + GLES32.GL_TEXTURE0 ) .addColor("uColor", R.color.grey, resources) .addVec3f("uVaryingColor", floatArrayOf(0.5f, 0.5f, 0.5f)) @@ -128,7 +128,7 @@ class ShaderListAdapter : RecyclerView.Adapter .addTexture2D( "uNormalTexture", R.drawable.normal_sphere, - GLES30.GL_TEXTURE0 + GLES32.GL_TEXTURE0 ) .addVec4f("uColor", floatArrayOf(0.5f, 0.5f, 0.5f, 1f)) .addVec3f("uVaryingColor", floatArrayOf(0.4f, 0.4f, 0.5f)) @@ -199,7 +199,7 @@ class ShaderListAdapter : RecyclerView.Adapter .addTexture2D( "uTexture", R.drawable.android, - GLES30.GL_TEXTURE0 + GLES32.GL_TEXTURE0 ) .addVec2f("uOffset") .build() @@ -223,7 +223,7 @@ class ShaderListAdapter : RecyclerView.Adapter .addTexture2D( "uTexture", R.drawable.test_texture, - GLES30.GL_TEXTURE0 + GLES32.GL_TEXTURE0 ) .addVec2f("uScale", floatArrayOf(0f, 0f)) .addInt("uBlurSize", 3) diff --git a/lib/src/main/java/com/appspell/shaderview/annotations/ShaderExperimentalApi.kt b/lib/src/main/java/com/appspell/shaderview/annotations/ShaderExperimentalApi.kt index 0cb646d..806600c 100644 --- a/lib/src/main/java/com/appspell/shaderview/annotations/ShaderExperimentalApi.kt +++ b/lib/src/main/java/com/appspell/shaderview/annotations/ShaderExperimentalApi.kt @@ -1,6 +1,6 @@ package com.appspell.shaderview.annotations @Suppress("DEPRECATION") -@Experimental(level = Experimental.Level.WARNING) +//@Experimental(level = Experimental.Level.WARNING) @RequiresOptIn(level = RequiresOptIn.Level.WARNING) public annotation class ShaderExperimentalApi \ No newline at end of file diff --git a/lib/src/main/java/com/appspell/shaderview/ext/Texture.kt b/lib/src/main/java/com/appspell/shaderview/ext/Texture.kt index 6a4d9dc..d1b7d0d 100644 --- a/lib/src/main/java/com/appspell/shaderview/ext/Texture.kt +++ b/lib/src/main/java/com/appspell/shaderview/ext/Texture.kt @@ -4,8 +4,7 @@ import android.content.res.Resources import android.graphics.Bitmap import android.graphics.BitmapFactory import android.opengl.GLES11Ext -import android.opengl.GLES20 -import android.opengl.GLES30 +import android.opengl.GLES32 import android.opengl.GLUtils import androidx.annotation.DrawableRes import java.nio.IntBuffer @@ -21,16 +20,16 @@ import java.nio.IntBuffer */ fun createExternalTexture(): Int { val textureIds = IntArray(1) - GLES30.glGenTextures(1, IntBuffer.wrap(textureIds)) + GLES32.glGenTextures(1, IntBuffer.wrap(textureIds)) if (textureIds[0] == 0) { throw java.lang.RuntimeException("It's not possible to generate ID for texture") } - GLES30.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureIds[0]) - GLES30.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR) - GLES30.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR) + GLES32.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureIds[0]) + GLES32.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES32.GL_TEXTURE_MIN_FILTER, GLES32.GL_LINEAR) + GLES32.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES32.GL_TEXTURE_MAG_FILTER, GLES32.GL_LINEAR) - GLES30.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE) - GLES30.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE) + GLES32.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES32.GL_TEXTURE_WRAP_S, GLES32.GL_CLAMP_TO_EDGE) + GLES32.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES32.GL_TEXTURE_WRAP_T, GLES32.GL_CLAMP_TO_EDGE) return textureIds[0] } @@ -47,30 +46,30 @@ fun Resources.loadBitmapForTexture(@DrawableRes drawableRes: Int): Bitmap { * @needToRecycle - do we need to recycle current Bitmap when we write it GPI? */ @Throws(RuntimeException::class) -fun Bitmap.toGlTexture(needToRecycle: Boolean = true, textureSlot: Int = GLES30.GL_TEXTURE0): Int { +fun Bitmap.toGlTexture(needToRecycle: Boolean = true, textureSlot: Int = GLES32.GL_TEXTURE0): Int { // init textures val textureIds = IntArray(1) - GLES30.glGenTextures(1, textureIds, 0) // generate ID for texture + GLES32.glGenTextures(1, textureIds, 0) // generate ID for texture if (textureIds[0] == 0) { throw java.lang.RuntimeException("It's not possible to generate ID for texture") } - GLES30.glActiveTexture(textureSlot) // activate slot #0 for texture - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, textureIds[0]) // bind texture by ID with active slot + GLES32.glActiveTexture(textureSlot) // activate slot #0 for texture + GLES32.glBindTexture(GLES32.GL_TEXTURE_2D, textureIds[0]) // bind texture by ID with active slot // texture filters - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR) + GLES32.glTexParameteri(GLES32.GL_TEXTURE_2D, GLES32.GL_TEXTURE_MIN_FILTER, GLES32.GL_LINEAR) + GLES32.glTexParameteri(GLES32.GL_TEXTURE_2D, GLES32.GL_TEXTURE_MAG_FILTER, GLES32.GL_LINEAR) // write bitmap to GPU - GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, this, 0) + GLUtils.texImage2D(GLES32.GL_TEXTURE_2D, 0, this, 0) // we don't need this bitmap anymore if (needToRecycle) { this.recycle() } // unbind texture from slot - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0) + GLES32.glBindTexture(GLES32.GL_TEXTURE_2D, 0) return textureIds[0] } \ No newline at end of file diff --git a/lib/src/main/java/com/appspell/shaderview/gl/params/ShaderParamsBuilder.kt b/lib/src/main/java/com/appspell/shaderview/gl/params/ShaderParamsBuilder.kt index 9a08012..f18afa7 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/params/ShaderParamsBuilder.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/params/ShaderParamsBuilder.kt @@ -3,7 +3,7 @@ package com.appspell.shaderview.gl.params import android.content.res.Resources import android.graphics.Bitmap import android.graphics.Color -import android.opengl.GLES30 +import android.opengl.GLES32 import androidx.annotation.ColorInt import androidx.annotation.ColorRes import androidx.annotation.DrawableRes @@ -125,7 +125,7 @@ class ShaderParamsBuilder { fun addTexture2D( paramName: String, bitmap: Bitmap? = null, - textureSlot: Int = GLES30.GL_TEXTURE0 + textureSlot: Int = GLES32.GL_TEXTURE0 ): ShaderParamsBuilder { val param = Param( valeType = Param.ValueType.SAMPLER_2D, @@ -146,7 +146,7 @@ class ShaderParamsBuilder { fun addTexture2D( paramName: String, @DrawableRes textureResourceId: Int, - textureSlot: Int = GLES30.GL_TEXTURE0 + textureSlot: Int = GLES32.GL_TEXTURE0 ): ShaderParamsBuilder { val param = Param( valeType = Param.ValueType.SAMPLER_2D, diff --git a/lib/src/main/java/com/appspell/shaderview/gl/params/ShaderParamsImpl.kt b/lib/src/main/java/com/appspell/shaderview/gl/params/ShaderParamsImpl.kt index 6efa8b9..4f1828f 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/params/ShaderParamsImpl.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/params/ShaderParamsImpl.kt @@ -3,7 +3,7 @@ package com.appspell.shaderview.gl.params import android.content.res.Resources import android.graphics.Bitmap import android.graphics.SurfaceTexture -import android.opengl.GLES30 +import android.opengl.GLES32 import android.view.Surface import com.appspell.shaderview.annotations.ShaderExperimentalApi import com.appspell.shaderview.ext.createExternalTexture @@ -64,7 +64,7 @@ class ShaderParamsImpl : ShaderParams { private fun updateUniformLocation(paramName: String, shaderProgram: Int) { map[paramName]?.apply { - location = GLES30.glGetUniformLocation(shaderProgram, paramName) + location = GLES32.glGetUniformLocation(shaderProgram, paramName) } } @@ -105,30 +105,30 @@ class ShaderParamsImpl : ShaderParams { continue } when (param.valeType) { - Param.ValueType.FLOAT -> GLES30.glUniform1f(param.location, param.value as Float) - Param.ValueType.INT -> GLES30.glUniform1i(param.location, param.value as Int) - Param.ValueType.BOOL -> GLES30.glUniform1i(param.location, if (param.value as Boolean) 1 else 0) - Param.ValueType.FLOAT_VEC2 -> GLES30.glUniform2fv(param.location, 1, (param.value as FloatArray), 0) - Param.ValueType.FLOAT_VEC3 -> GLES30.glUniform3fv(param.location, 1, (param.value as FloatArray), 0) - Param.ValueType.FLOAT_VEC4 -> GLES30.glUniform4fv(param.location, 1, (param.value as FloatArray), 0) - Param.ValueType.INT_VEC2 -> GLES30.glUniform2iv(param.location, 1, (param.value as IntArray), 0) - Param.ValueType.INT_VEC3 -> GLES30.glUniform3iv(param.location, 1, (param.value as IntArray), 0) - Param.ValueType.INT_VEC4 -> GLES30.glUniform4iv(param.location, 1, (param.value as IntArray), 0) - Param.ValueType.MAT3 -> GLES30.glUniformMatrix3fv( + Param.ValueType.FLOAT -> GLES32.glUniform1f(param.location, param.value as Float) + Param.ValueType.INT -> GLES32.glUniform1i(param.location, param.value as Int) + Param.ValueType.BOOL -> GLES32.glUniform1i(param.location, if (param.value as Boolean) 1 else 0) + Param.ValueType.FLOAT_VEC2 -> GLES32.glUniform2fv(param.location, 1, (param.value as FloatArray), 0) + Param.ValueType.FLOAT_VEC3 -> GLES32.glUniform3fv(param.location, 1, (param.value as FloatArray), 0) + Param.ValueType.FLOAT_VEC4 -> GLES32.glUniform4fv(param.location, 1, (param.value as FloatArray), 0) + Param.ValueType.INT_VEC2 -> GLES32.glUniform2iv(param.location, 1, (param.value as IntArray), 0) + Param.ValueType.INT_VEC3 -> GLES32.glUniform3iv(param.location, 1, (param.value as IntArray), 0) + Param.ValueType.INT_VEC4 -> GLES32.glUniform4iv(param.location, 1, (param.value as IntArray), 0) + Param.ValueType.MAT3 -> GLES32.glUniformMatrix3fv( param.location, 1, false, (param.value as FloatArray), 0 ) - Param.ValueType.MAT4 -> GLES30.glUniformMatrix4fv( + Param.ValueType.MAT4 -> GLES32.glUniformMatrix4fv( param.location, 1, false, (param.value as FloatArray), 0 ) - Param.ValueType.MAT3x4 -> GLES30.glUniformMatrix3x4fv( + Param.ValueType.MAT3x4 -> GLES32.glUniformMatrix3x4fv( param.location, 1, false, @@ -137,9 +137,9 @@ class ShaderParamsImpl : ShaderParams { ) Param.ValueType.SAMPLER_2D -> { (param.value as? TextureParam)?.apply { - GLES30.glUniform1i(param.location, textureSlot.convertTextureSlotToIndex()) - GLES30.glActiveTexture(textureSlot) - textureId?.also { GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, it) } + GLES32.glUniform1i(param.location, textureSlot.convertTextureSlotToIndex()) + GLES32.glActiveTexture(textureSlot) + textureId?.also { GLES32.glBindTexture(GLES32.GL_TEXTURE_2D, it) } } } Param.ValueType.SAMPLER_OES -> { @@ -208,38 +208,38 @@ class ShaderParamsImpl : ShaderParams { private fun Int.convertTextureSlotToIndex(): Int = when (this) { - GLES30.GL_TEXTURE0 -> 0 - GLES30.GL_TEXTURE1 -> 1 - GLES30.GL_TEXTURE2 -> 2 - GLES30.GL_TEXTURE3 -> 3 - GLES30.GL_TEXTURE4 -> 4 - GLES30.GL_TEXTURE5 -> 5 - GLES30.GL_TEXTURE6 -> 6 - GLES30.GL_TEXTURE7 -> 7 - GLES30.GL_TEXTURE8 -> 8 - GLES30.GL_TEXTURE9 -> 9 - GLES30.GL_TEXTURE10 -> 10 - GLES30.GL_TEXTURE11 -> 11 - GLES30.GL_TEXTURE12 -> 12 - GLES30.GL_TEXTURE13 -> 13 - GLES30.GL_TEXTURE14 -> 14 - GLES30.GL_TEXTURE15 -> 15 - GLES30.GL_TEXTURE16 -> 16 - GLES30.GL_TEXTURE17 -> 17 - GLES30.GL_TEXTURE18 -> 18 - GLES30.GL_TEXTURE19 -> 19 - GLES30.GL_TEXTURE20 -> 20 - GLES30.GL_TEXTURE21 -> 21 - GLES30.GL_TEXTURE22 -> 22 - GLES30.GL_TEXTURE23 -> 23 - GLES30.GL_TEXTURE24 -> 24 - GLES30.GL_TEXTURE25 -> 25 - GLES30.GL_TEXTURE26 -> 26 - GLES30.GL_TEXTURE27 -> 27 - GLES30.GL_TEXTURE28 -> 28 - GLES30.GL_TEXTURE29 -> 29 - GLES30.GL_TEXTURE30 -> 30 - GLES30.GL_TEXTURE31 -> 31 + GLES32.GL_TEXTURE0 -> 0 + GLES32.GL_TEXTURE1 -> 1 + GLES32.GL_TEXTURE2 -> 2 + GLES32.GL_TEXTURE3 -> 3 + GLES32.GL_TEXTURE4 -> 4 + GLES32.GL_TEXTURE5 -> 5 + GLES32.GL_TEXTURE6 -> 6 + GLES32.GL_TEXTURE7 -> 7 + GLES32.GL_TEXTURE8 -> 8 + GLES32.GL_TEXTURE9 -> 9 + GLES32.GL_TEXTURE10 -> 10 + GLES32.GL_TEXTURE11 -> 11 + GLES32.GL_TEXTURE12 -> 12 + GLES32.GL_TEXTURE13 -> 13 + GLES32.GL_TEXTURE14 -> 14 + GLES32.GL_TEXTURE15 -> 15 + GLES32.GL_TEXTURE16 -> 16 + GLES32.GL_TEXTURE17 -> 17 + GLES32.GL_TEXTURE18 -> 18 + GLES32.GL_TEXTURE19 -> 19 + GLES32.GL_TEXTURE20 -> 20 + GLES32.GL_TEXTURE21 -> 21 + GLES32.GL_TEXTURE22 -> 22 + GLES32.GL_TEXTURE23 -> 23 + GLES32.GL_TEXTURE24 -> 24 + GLES32.GL_TEXTURE25 -> 25 + GLES32.GL_TEXTURE26 -> 26 + GLES32.GL_TEXTURE27 -> 27 + GLES32.GL_TEXTURE28 -> 28 + GLES32.GL_TEXTURE29 -> 29 + GLES32.GL_TEXTURE30 -> 30 + GLES32.GL_TEXTURE31 -> 31 else -> 0 } } \ No newline at end of file diff --git a/lib/src/main/java/com/appspell/shaderview/gl/params/SpecialParam.kt b/lib/src/main/java/com/appspell/shaderview/gl/params/SpecialParam.kt index a72f749..2b2b5b8 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/params/SpecialParam.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/params/SpecialParam.kt @@ -2,7 +2,7 @@ package com.appspell.shaderview.gl.params import android.graphics.Bitmap import android.graphics.SurfaceTexture -import android.opengl.GLES30 +import android.opengl.GLES32 import android.view.Surface import androidx.annotation.DrawableRes import java.util.concurrent.atomic.AtomicBoolean @@ -20,5 +20,5 @@ data class TextureParam( val bitmap: Bitmap? = null, var textureId: Int? = null, val needToRecycleWhenUploaded: Boolean = true, - val textureSlot: Int = GLES30.GL_TEXTURE0 + val textureSlot: Int = GLES32.GL_TEXTURE0 ) \ No newline at end of file diff --git a/lib/src/main/java/com/appspell/shaderview/gl/render/GLQuadRender.kt b/lib/src/main/java/com/appspell/shaderview/gl/render/GLQuadRender.kt index a003404..802b672 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/render/GLQuadRender.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/render/GLQuadRender.kt @@ -1,7 +1,6 @@ package com.appspell.shaderview.gl.render -import android.opengl.GLES20 -import android.opengl.GLES30 +import android.opengl.GLES32 import android.opengl.Matrix import com.appspell.shaderview.gl.params.ShaderParams import com.appspell.shaderview.gl.shader.GLShader @@ -83,7 +82,7 @@ internal class GLQuadRenderImpl( } override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) { - GLES30.glViewport(0, 0, width, height) + GLES32.glViewport(0, 0, width, height) } override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) { @@ -112,10 +111,10 @@ internal class GLQuadRenderImpl( return } - GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f) - GLES30.glClear(GLES30.GL_DEPTH_BUFFER_BIT or GLES30.GL_COLOR_BUFFER_BIT) + GLES32.glClearColor(0.0f, 0.0f, 0.0f, 0.0f) + GLES32.glClear(GLES32.GL_DEPTH_BUFFER_BIT or GLES32.GL_COLOR_BUFFER_BIT) - GLES30.glUseProgram(shader.program) + GLES32.glUseProgram(shader.program) checkGlError("glUseProgram") // shader input (built-in attributes) @@ -134,21 +133,21 @@ internal class GLQuadRenderImpl( shader.onDrawFrame() // activate blending for textures - GLES30.glBlendFunc(GLES30.GL_SRC_ALPHA, GLES30.GL_ONE_MINUS_SRC_ALPHA) - GLES30.glEnable(GLES20.GL_BLEND) + GLES32.glBlendFunc(GLES32.GL_SRC_ALPHA, GLES32.GL_ONE_MINUS_SRC_ALPHA) + GLES32.glEnable(GLES32.GL_BLEND) // draw scene - GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4) + GLES32.glDrawArrays(GLES32.GL_TRIANGLE_STRIP, 0, 4) checkGlError("glDrawArrays") - GLES30.glFinish() + GLES32.glFinish() } /** * get location of some input attribute for shader */ private fun glGetAttribLocation(attrName: String): Int { - val attrLocation = GLES30.glGetAttribLocation(shader.program, attrName) + val attrLocation = GLES32.glGetAttribLocation(shader.program, attrName) checkGlError("glGetAttribLocation $attrName") return attrLocation } @@ -162,24 +161,25 @@ internal class GLQuadRenderImpl( return } quadVertices.position(offset) - GLES30.glVertexAttribPointer( + GLES32.glVertexAttribPointer( attrLocation, size, - GLES30.GL_FLOAT, + GLES32.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, quadVertices ) checkGlError("glVertexAttribPointer $attrName") - GLES30.glEnableVertexAttribArray(attrLocation) + GLES32.glEnableVertexAttribArray(attrLocation) checkGlError("glEnableVertexAttribArray $attrName") } private fun checkGlError(op: String) { var error: Int - while (GLES30.glGetError().also { error = it } != GLES30.GL_NO_ERROR) { + while (GLES32.glGetError().also { error = it } != GLES32.GL_NO_ERROR) { LibLog.e(TAG, "$op: glError $error") - throw RuntimeException("$op: glError $error") + // don't throw an exception since it cannot be caught outside of ShaderView + //throw RuntimeException("$op: glError $error") } } } \ No newline at end of file diff --git a/lib/src/main/java/com/appspell/shaderview/gl/shader/GLShaderImpl.kt b/lib/src/main/java/com/appspell/shaderview/gl/shader/GLShaderImpl.kt index a1881a3..a899990 100644 --- a/lib/src/main/java/com/appspell/shaderview/gl/shader/GLShaderImpl.kt +++ b/lib/src/main/java/com/appspell/shaderview/gl/shader/GLShaderImpl.kt @@ -1,7 +1,7 @@ package com.appspell.shaderview.gl.shader import android.content.res.Resources -import android.opengl.GLES30 +import android.opengl.GLES32 import com.appspell.shaderview.gl.params.ShaderParams import com.appspell.shaderview.log.LibLog @@ -18,19 +18,19 @@ class GLShaderImpl constructor( if (program != UNKNOWN_PROGRAM) { release() } - val vertexShader = loadShader(GLES30.GL_VERTEX_SHADER, vertexSource) + val vertexShader = loadShader(GLES32.GL_VERTEX_SHADER, vertexSource) if (vertexShader == UNKNOWN_PROGRAM) { return false } - val pixelShader = loadShader(GLES30.GL_FRAGMENT_SHADER, fragmentSource) + val pixelShader = loadShader(GLES32.GL_FRAGMENT_SHADER, fragmentSource) if (pixelShader == UNKNOWN_PROGRAM) { return false } - program = GLES30.glCreateProgram() + program = GLES32.glCreateProgram() if (program != UNKNOWN_PROGRAM) { - GLES30.glAttachShader(program, vertexShader) + GLES32.glAttachShader(program, vertexShader) checkGlError("glAttachShader: vertex") - GLES30.glAttachShader(program, pixelShader) + GLES32.glAttachShader(program, pixelShader) checkGlError("glAttachShader: pixel") return linkProgram() } @@ -41,13 +41,13 @@ class GLShaderImpl constructor( if (program == UNKNOWN_PROGRAM) { return false } - GLES30.glLinkProgram(program) + GLES32.glLinkProgram(program) val linkStatus = IntArray(1) - GLES30.glGetProgramiv(program, GLES30.GL_LINK_STATUS, linkStatus, 0) - if (linkStatus[0] != GLES30.GL_TRUE) { + GLES32.glGetProgramiv(program, GLES32.GL_LINK_STATUS, linkStatus, 0) + if (linkStatus[0] != GLES32.GL_TRUE) { LibLog.e(TAG, "Could not link program: ") - LibLog.e(TAG, GLES30.glGetProgramInfoLog(program)) - GLES30.glDeleteProgram(program) + LibLog.e(TAG, GLES32.glGetProgramInfoLog(program)) + GLES32.glDeleteProgram(program) program = UNKNOWN_PROGRAM return false } @@ -63,7 +63,7 @@ class GLShaderImpl constructor( override fun release() { if (program != UNKNOWN_PROGRAM) { - GLES30.glDeleteProgram(program) + GLES32.glDeleteProgram(program) program = UNKNOWN_PROGRAM } params.release() @@ -97,16 +97,16 @@ class GLShaderImpl constructor( } private fun loadShader(shaderType: Int, source: String): Int { - var shader = GLES30.glCreateShader(shaderType) + var shader = GLES32.glCreateShader(shaderType) if (shader != UNKNOWN_PROGRAM) { - GLES30.glShaderSource(shader, source) - GLES30.glCompileShader(shader) + GLES32.glShaderSource(shader, source) + GLES32.glCompileShader(shader) val compiled = IntArray(1) - GLES30.glGetShaderiv(shader, GLES30.GL_COMPILE_STATUS, compiled, 0) + GLES32.glGetShaderiv(shader, GLES32.GL_COMPILE_STATUS, compiled, 0) if (compiled[0] == UNKNOWN_PROGRAM) { LibLog.e(TAG, "Could not compile shader $shaderType:") - LibLog.e(TAG, GLES30.glGetShaderInfoLog(shader)) - GLES30.glDeleteShader(shader) + LibLog.e(TAG, GLES32.glGetShaderInfoLog(shader)) + GLES32.glDeleteShader(shader) shader = UNKNOWN_PROGRAM } } @@ -115,7 +115,7 @@ class GLShaderImpl constructor( private fun checkGlError(op: String) { var error: Int - while (GLES30.glGetError().also { error = it } != GLES30.GL_NO_ERROR) { + while (GLES32.glGetError().also { error = it } != GLES32.GL_NO_ERROR) { LibLog.e(TAG, "$op: glError $error") throw RuntimeException("$op: glError $error") } diff --git a/local.properties b/local.properties deleted file mode 100644 index 5da0242..0000000 --- a/local.properties +++ /dev/null @@ -1,8 +0,0 @@ -## This file must *NOT* be checked into Version Control Systems, -# as it contains information specific to your local configuration. -# -# Location of the SDK. This is only used by Gradle. -# For customization when using a Version Control System, please read the -# header note. -#Sun May 01 00:25:25 EDT 2022 -sdk.dir=C\:\\Users\\oxter\\AppData\\Local\\Android\\Sdk From 1e92b6b60f1c76ed4acd6d8139d038bb75107996 Mon Sep 17 00:00:00 2001 From: Oxters Date: Sun, 2 Apr 2023 23:05:09 -0400 Subject: [PATCH 30/30] Changed version to 0.8.12 and fixed jitpack link in readme --- README.md | 2 +- lib/publish.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d002673..187c79d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # ShaderView -[![](https://jitpack.io/v/appspell/ShaderView.svg)](https://jitpack.io/#appspell/ShaderView) +[![](https://jitpack.io/v/oxters168/ShaderView.svg)](https://jitpack.io/#oxters168/ShaderView) This library is the easiest way to use **OpenGL shaders** as an **[Android View](https://developer.android.com/reference/android/view/View)**. You just simply need to add **ShaderView** in your layout and set up shaders. The advantage of this library that you can use ShaderView in your hierarchy as a regular View. diff --git a/lib/publish.gradle b/lib/publish.gradle index 9785e8d..06be77c 100644 --- a/lib/publish.gradle +++ b/lib/publish.gradle @@ -1,6 +1,6 @@ apply plugin: 'maven-publish' -version '0.8.8' +version '0.8.12' task sourceJar(type: Jar) { from android.sourceSets.main.java.srcDirs