I am using GlSurfaceView and OpenGL ES 3. When I set the OpenGL renderer for my OpenGlSurfaceView nothing happens. My logs in renderer's onSurfaceCreated and onDrawFrame do not show up on logcat.
The only thing I get is this warning: W/GLSurfaceView: Warning, !readyToDraw() but waiting for draw finished! Early reporting draw finished.
GlSurfaceView:
class GameSurfaceView : GLSurfaceView
{
constructor(context: Context?) : super(context)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
lateinit var surfaceViewCallback: SurfaceViewCallback
val renderer = Renderer()
var isOpenGLSurfaceCreated = false
private set
init
{
isFocusable = true
isFocusableInTouchMode = true
isClickable = true
requestFocus()
}
override fun surfaceCreated(var1: SurfaceHolder)
{
Timber.d("surface view created") //SHOWS UP ON LOGS
instance = this
debugFlags = DEBUG_LOG_GL_CALLS
setRenderer(renderer)
}
}
Renderer:
class Renderer() : GLSurfaceView.Renderer
{
override fun onSurfaceCreated(p0: GL10?, p1: EGLConfig?)
{
Timber.v("Renderer: Surface Created") //never shows up on logs
glClearColor(1.0f, 0.0f, 0.0f, 1.0f)
}
override fun onSurfaceChanged(p0: GL10?, width: Int, height: Int)
{
Timber.d("SURFACE CHANGED") //never shows up on logs
glViewport(0, 0, width, height)
}
override fun onDrawFrame(p0: GL10?)
{
Timber.d("onDrawFrame Called") //never shows up on logs
glClear(GLES30.GL_COLOR_BUFFER_BIT)
}
}
GameFragment's layout (where the GameSurfaceView is used):
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.game.GameFragment">
<com.mypackage.appname.ui.game.GameSurfaceView
android:id="@+id/game_surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/game_score_text_tv"
style="@style/GameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/score"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.43"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/game_score_tv"
style="@style/GameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="0"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/game_score_text_tv"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/game_score_text_tv"
app:layout_constraintTop_toTopOf="@+id/game_score_text_tv" />
</androidx.constraintlayout.widget.ConstraintLayout>
Manifest:
<uses-feature
android:glEsVersion="0x00030000"
android:required="true" />
OpenGL Android Docs: https://developer.android.com/guide/topics/graphics/opengl
If you are making a custom game SurfaceView like me by extending the GLSurfaceView, do not override the callback methods like onSurfaceCreated, onSurfaceChanged.