-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare for interchangeable SurfaceViews
- Loading branch information
1 parent
bfe8edf
commit dc06308
Showing
12 changed files
with
112 additions
and
35 deletions.
There are no files selected for viewing
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
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
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
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
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
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
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/simongellis/vvb/game/GLSurfaceViewAdapter.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.simongellis.vvb.game | ||
|
||
import android.content.Context | ||
import android.opengl.GLSurfaceView | ||
import android.util.AttributeSet | ||
import javax.microedition.khronos.egl.EGLConfig | ||
import javax.microedition.khronos.opengles.GL10 | ||
|
||
class GLSurfaceViewAdapter: GLSurfaceView, SurfaceViewAdapter { | ||
constructor(context: Context): super(context) | ||
constructor(context: Context, attrs: AttributeSet?): super(context, attrs) | ||
|
||
override fun setRenderer(renderer: com.simongellis.vvb.emulator.Renderer) { | ||
setEGLContextClientVersion(2) | ||
setRenderer(RendererAdapter(renderer)) | ||
renderMode = RENDERMODE_CONTINUOUSLY | ||
} | ||
|
||
class RendererAdapter(private val inner: com.simongellis.vvb.emulator.Renderer): Renderer { | ||
override fun onSurfaceCreated(gl: GL10?, p1: EGLConfig?) { | ||
inner.onSurfaceCreated() | ||
} | ||
|
||
override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) { | ||
inner.onSurfaceChanged(width, height) | ||
} | ||
|
||
override fun onDrawFrame(gl: GL10?) { | ||
inner.onDrawFrame() | ||
} | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/simongellis/vvb/game/SurfaceViewAdapter.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.simongellis.vvb.game | ||
|
||
import com.simongellis.vvb.emulator.Renderer | ||
|
||
interface SurfaceViewAdapter { | ||
fun setRenderer(renderer: Renderer) | ||
fun onPause() | ||
fun onResume() | ||
} |
36 changes: 36 additions & 0 deletions
36
app/src/main/java/com/simongellis/vvb/game/WrapperSurfaceViewAdapter.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.simongellis.vvb.game | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import android.widget.LinearLayout | ||
import com.simongellis.vvb.R | ||
import com.simongellis.vvb.databinding.WrapperSurfaceViewAdapterBinding | ||
import com.simongellis.vvb.emulator.Renderer | ||
|
||
class WrapperSurfaceViewAdapter : LinearLayout, SurfaceViewAdapter { | ||
constructor(context: Context): super(context) | ||
constructor(context: Context, attrs: AttributeSet?): super(context, attrs) | ||
|
||
init { | ||
val layoutInflater = LayoutInflater.from(context) | ||
WrapperSurfaceViewAdapterBinding.inflate(layoutInflater, this, true) | ||
} | ||
|
||
@Suppress("TypeParameterFindViewById") | ||
private val inner: SurfaceViewAdapter | ||
get() = findViewById(R.id.inner_surface_view) as SurfaceViewAdapter | ||
|
||
override fun setRenderer(renderer: Renderer) { | ||
inner.setRenderer(renderer) | ||
} | ||
|
||
override fun onPause() { | ||
inner.onPause() | ||
} | ||
|
||
override fun onResume() { | ||
inner.onResume() | ||
} | ||
|
||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
<com.simongellis.vvb.game.GLSurfaceViewAdapter | ||
android:id="@+id/inner_surface_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"/> | ||
</LinearLayout> |