Skip to content

Commit

Permalink
extension check
Browse files Browse the repository at this point in the history
  • Loading branch information
Sisah2 committed Mar 23, 2024
1 parent afdd30d commit e32a290
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
59 changes: 59 additions & 0 deletions app/src/main/java/ui/activity/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,70 @@ import android.preference.Preference
import android.preference.PreferenceFragment
import android.preference.PreferenceGroup

import constants.Constants
import android.opengl.EGL14.EGL_CONTEXT_CLIENT_VERSION
import android.opengl.EGL14.EGL_OPENGL_ES2_BIT
import android.opengl.GLES20
import javax.microedition.khronos.egl.EGL10
import javax.microedition.khronos.egl.EGL10.*
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.egl.EGLContext
import javax.microedition.khronos.egl.EGLDisplay

class FragmentGameSettings : PreferenceFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

addPreferencesFromResource(R.xml.game_settings)

val config = intArrayOf(
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 0,
EGL_STENCIL_SIZE, 0,
EGL_NONE
)

fun chooseEglConfig(egl: EGL10, eglDisplay: EGLDisplay) : EGLConfig {
val configsCount = intArrayOf(0);
val configs = arrayOfNulls<EGLConfig>(1);
egl.eglChooseConfig(eglDisplay, config, configs, 1, configsCount)
return configs[0]!!
}

fun getExtensionList() {
val egl = EGLContext.getEGL() as EGL10
val eglDisplay = egl.eglGetDisplay(EGL_DEFAULT_DISPLAY)
egl.eglInitialize(eglDisplay, intArrayOf(0,0)) // getting OpenGL ES 2
val eglConfig = chooseEglConfig(egl, eglDisplay);
val eglContext = egl.eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, intArrayOf(EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE));

//FIXME: Create some surface to dont rely on extension, dont crash if something get fucked
//val eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, texture_view.surfaceTexture, null)
egl.eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, eglContext)
val extensions = GLES20.glGetString(GLES20.GL_EXTENSIONS)
File(Constants.USER_CONFIG + "/extensions.cfg").writeText(extensions.replace(" ", "\n"))

egl.eglDestroyContext(eglDisplay, eglContext)
//egl.eglDestroySurface(eglDisplay, eglSurface)

if (extensions.contains("GL_EXT_depth_clamp") == false) {
findPreference("gs_enable_shadows").isEnabled = false
findPreference("gs_object_shadows").isEnabled = false
findPreference("gs_terrain_shadows").isEnabled = false
findPreference("gs_actor_shadows").isEnabled = false
findPreference("gs_player_shadows").isEnabled = false
findPreference("gs_indoor_shadows").isEnabled = false
findPreference("gs_shadow_map_resolution").isEnabled = false
findPreference("gs_shadows_distance").isEnabled = false
findPreference("gs_shadows_pcf").isEnabled = false
}
}

getExtensionList()
/*
findPreference("game_settings_game_mechanics").setOnPreferenceClickListener {
getPreferenceScreen().removeAll()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/gs_visuals.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@

<ListPreference
android:key="gs_shadows_pcf"
android:summary="%s \nSmooth out shadows edges."
android:summary="%s \nSmooth out shadows edges if small resolution is set. Higher values may have significant performance impact."
android:title="Shadows PCF Filter"
android:dialogTitle="Shadows PCF Filter"
android:entries="@array/gs_shadow_pcf_entries"
Expand Down

0 comments on commit e32a290

Please sign in to comment.