Skip to content

Commit

Permalink
Support LumePad 2 3D (WIP, breaks other devices)
Browse files Browse the repository at this point in the history
  • Loading branch information
SupernaviX committed Apr 7, 2023
1 parent 09c9435 commit c51cfe5
Show file tree
Hide file tree
Showing 14 changed files with 288 additions and 18 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ android {
applicationIdSuffix '.leia'
minSdkVersion 30
dependencies {
implementation files("../leia-cnsdk/cnsdk.aar")
implementation project(":leia-cnsdk")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class LeiaSurfaceViewAdapter : InterlacedSurfaceView, SurfaceViewAdapter, LeiaSD
initArgs.platform.context = context.applicationContext
initArgs.platform.activity = getActivity(context)
initArgs.enableFaceTracking = true
initArgs.requiresFaceTrackingPermissionCheck = false
LeiaSDK.createSDK(initArgs)
}

Expand Down Expand Up @@ -82,7 +81,7 @@ class LeiaSurfaceViewAdapter : InterlacedSurfaceView, SurfaceViewAdapter, LeiaSD
Log.i("LeiaSurfaceViewAdapter", "setting up $textureId (error 0x${GLES20.glGetError().toString(16)})")
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId)
Log.i("LeiaSurfaceViewAdapter", "bound $textureId (error 0x${GLES20.glGetError().toString(16)})")
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGB, width * 2, height, 0, GLES20.GL_RGB, GLES20.GL_UNSIGNED_BYTE, null)
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGB, width, height, 0, GLES20.GL_RGB, GLES20.GL_UNSIGNED_BYTE, null)
Log.i("LeiaSurfaceViewAdapter", "initialized $textureId (error 0x${GLES20.glGetError().toString(16)})")

val framebuffers = IntArray(1)
Expand All @@ -103,6 +102,7 @@ class LeiaSurfaceViewAdapter : InterlacedSurfaceView, SurfaceViewAdapter, LeiaSD

override fun didInitialize(sdk: LeiaSDK) {
Log.i("LeiaSurfaceViewAdapter", "didInitialize")
sdk.enableBacklight(true)
}

override fun onFaceTrackingFatalError(sdk: LeiaSDK) {
Expand Down
45 changes: 45 additions & 0 deletions app/src/main/java/com/simongellis/vvb/emulator/CNSDKRenderer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.simongellis.vvb.emulator

import androidx.annotation.ColorInt

class CNSDKRenderer(emulator: Emulator, settings: Settings): Renderer {
private var _pointer = 0L

init {
nativeConstructor(emulator, settings)
}

fun finalize() {
destroy()
}

override fun destroy() {
if (_pointer != 0L) {
nativeDestructor()
}
}

override fun onSurfaceCreated() {
nativeOnSurfaceCreated()
}

override fun onSurfaceChanged(width: Int, height: Int) {
nativeOnSurfaceChanged(width, height)
}

override fun onDrawFrame() {
nativeOnDrawFrame()
}

class Settings(
val screenZoom: Float,
val aspectRatio: Int,
val verticalOffset: Float,
@ColorInt val color: Int)

private external fun nativeConstructor(emulator: Emulator, settings: Settings)
private external fun nativeDestructor()
private external fun nativeOnSurfaceCreated()
private external fun nativeOnSurfaceChanged(width: Int, height: Int)
private external fun nativeOnDrawFrame()
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/simongellis/vvb/game/GameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class GameActivity : AppCompatActivity() {
_audio = Audio(emulator, _preferences.audioSettings)
_controller = Controller(emulator)

_view = GameView(baseContext)
_view = GameView(this)
requestedOrientation = _view.requestedOrientation
_view.controller = _controller
setContentView(_view)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class GamePreferences(context: Context) {
val stereoSettings
get() = StereoRenderer.Settings(screenZoom, aspectRatio.ordinal, verticalOffset, color)

val cnsdkSettings
get() = CNSDKRenderer.Settings(screenZoom, aspectRatio.ordinal, verticalOffset, color)

val leiaSettings
get() = LeiaRenderer.Settings(screenZoom, aspectRatio.ordinal, verticalOffset, color, colorBG)

Expand All @@ -83,7 +86,7 @@ class GamePreferences(context: Context) {

val prefs = PreferenceManager.getDefaultSharedPreferences(context)

val displayManager = LeiaSDK.getDisplayManager(context)
val displayManager = true//LeiaSDK.getDisplayManager(context)
var defaultMode = VideoMode.ANAGLYPH.name
var defaultScreenZoom = 100
if(displayManager !== null){
Expand Down
19 changes: 8 additions & 11 deletions app/src/main/java/com/simongellis/vvb/game/GameView.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.simongellis.vvb.game

import android.app.Activity
import android.content.Context
import android.content.pm.ActivityInfo
import android.graphics.Color
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isVisible
Expand All @@ -19,7 +19,7 @@ import com.leia.android.lights.BacklightModeListener
import com.leia.android.lights.LeiaDisplayManager.BacklightMode.MODE_2D
import com.leia.android.lights.LeiaDisplayManager.BacklightMode.MODE_3D

class GameView : ConstraintLayout, BacklightModeListener {
class GameView(context: Context) : ConstraintLayout(context), BacklightModeListener {
private val _binding: GameViewBinding
private val _renderer: Renderer
private val _preferences: GamePreferences
Expand All @@ -38,12 +38,6 @@ class GameView : ConstraintLayout, BacklightModeListener {
private val _surfaceView: SurfaceViewAdapter
get() = _binding.surfaceView as SurfaceViewAdapter

constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
@Suppress("unused")
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)

init {
val emulator = Emulator.instance
_preferences = GamePreferences(context)
Expand All @@ -53,7 +47,7 @@ class GameView : ConstraintLayout, BacklightModeListener {
VideoMode.MONO_LEFT -> MonoRenderer(emulator, _preferences.monoSettings(Eye.LEFT))
VideoMode.MONO_RIGHT -> MonoRenderer(emulator, _preferences.monoSettings(Eye.RIGHT))
VideoMode.STEREO -> StereoRenderer(emulator, _preferences.stereoSettings)
VideoMode.LEIA -> LeiaRenderer(emulator, _preferences.leiaSettings)
VideoMode.LEIA -> CNSDKRenderer(emulator, _preferences.cnsdkSettings)
}

val layoutInflater = LayoutInflater.from(context)
Expand All @@ -77,11 +71,14 @@ class GameView : ConstraintLayout, BacklightModeListener {

setBackgroundColor(Color.BLACK)

/*
mDisplayManager = LeiaSDK.getDisplayManager(context)
mDisplayManager?.apply {
registerBacklightModeListener(this@GameView)
checkShouldToggle3D(true)
}
*/
}

fun onPause() {
Expand Down Expand Up @@ -124,10 +121,10 @@ class GameView : ConstraintLayout, BacklightModeListener {
}

private fun enable3D() {
mDisplayManager?.requestBacklightMode(MODE_3D)
//mDisplayManager?.requestBacklightMode(MODE_3D)
}

private fun disable3D() {
mDisplayManager?.requestBacklightMode(MODE_2D)
//mDisplayManager?.requestBacklightMode(MODE_2D)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PreviewActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
VvbLibrary.instance.initialize(this)
_view = GameView(baseContext)
_view = GameView(this)
_preferences = GamePreferences(baseContext)
requestedOrientation = _view.requestedOrientation
setContentView(_view)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class VideoMenuFragment: PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.preferences_video, rootKey)
var defaultModeName = VideoMode.ANAGLYPH.name
val leiaDisplayManager = LeiaSDK.getDisplayManager(context)
val leiaDisplayManager = true//LeiaSDK.getDisplayManager(context)
var defaultBGColor = ContextCompat.getColor(requireContext(), R.color.black)
var defaultScreenZoom = 100
if(leiaDisplayManager !== null){
Expand Down
1 change: 1 addition & 0 deletions leia-cnsdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
2 changes: 2 additions & 0 deletions leia-cnsdk/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
configurations.maybeCreate("default")
artifacts.add("default", file('cnsdk.aar'))
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include ':cardboard-sdk'
include ':leia-cnsdk'
include ':app'
rootProject.name = "Virtual Virtual Boy"
2 changes: 2 additions & 0 deletions src/video/renderers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod anaglyph;
mod cardboard;
mod cnsdk;
mod common;
mod gl;
mod leia;
Expand All @@ -9,6 +10,7 @@ mod stereo;
pub mod jni {
pub use super::anaglyph::jni::*;
pub use super::cardboard::jni::*;
pub use super::cnsdk::jni::*;
pub use super::leia::jni::*;
pub use super::mono::jni::*;
pub use super::stereo::jni::*;
Expand Down
Loading

0 comments on commit c51cfe5

Please sign in to comment.