Skip to content

Commit

Permalink
Add shadows settings with extension check, remove unused settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sisah2 committed Mar 24, 2024
1 parent f11be01 commit 99d256e
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 129 deletions.
8 changes: 8 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@
android:exported="true"
android:label="@string/visuals_activity_settings"
/>
<activity
android:name="ui.activity.Shadows_SettingsActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="fullUser"
android:theme="@style/MyTheme"
android:exported="true"
android:label="@string/shadows_activity_settings"
/>
<activity
android:name="ui.activity.Animations_SettingsActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
Expand Down
23 changes: 6 additions & 17 deletions app/src/main/java/ui/activity/GameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class GameActivity : SDLActivity() {

override fun loadLibraries() {
prefs = PreferenceManager.getDefaultSharedPreferences(this)
val graphicsLibrary = prefs!!.getString("pref_graphicsLibrary_v2", "")
val physicsFPS = prefs!!.getString("pref_physicsFPS2", "")
if (!physicsFPS!!.isEmpty()) {
try {
Expand All @@ -90,30 +89,20 @@ class GameActivity : SDLActivity() {
System.loadLibrary("c++_shared")
System.loadLibrary("openal")
System.loadLibrary("SDL2")
if (graphicsLibrary != "gles1") {
try {
Os.setenv("OPENMW_GLES_VERSION", "2", true)
Os.setenv("LIBGL_ES", "2", true)
} catch (e: ErrnoException) {
Log.e("OpenMW", "Failed setting environment variables.")
e.printStackTrace()
}

try {
Os.setenv("OPENMW_GLES_VERSION", "2", true)
Os.setenv("LIBGL_ES", "2", true)
} catch (e: ErrnoException) {
Log.e("OpenMW", "Failed setting environment variables.")
e.printStackTrace()
}

val textureShrinkingOption = prefs!!.getString("pref_textureShrinking_v2", "")
if (textureShrinkingOption == "low") Os.setenv("LIBGL_SHRINK", "2", true)
if (textureShrinkingOption == "medium") Os.setenv("LIBGL_SHRINK", "7", true)
if (textureShrinkingOption == "high") Os.setenv("LIBGL_SHRINK", "6", true)

val shaderDirOption = prefs!!.getString("pref_shadersDir_v2", "")
if (shaderDirOption == "modified") Os.setenv("OPENMW_SHADERS", "modified", true)
if (shaderDirOption == "zesterer") Os.setenv("OPENMW_SHADERS", "zesterer", true)

if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_nohighp", false) && shaderDirOption == "modified") {
Os.setenv("LIBGL_NOHIGHP", "1", true)
}

Os.setenv("OSG_VERTEX_BUFFER_HINT", "VBO", true)
Os.setenv("OPENMW_USER_FILE_STORAGE", Constants.USER_FILE_STORAGE + "/", true)
//Os.setenv("OSG_NOTIFY_LEVEL", "FATAL", true) //hide osg errors for now, gl4es bug.
Expand Down
39 changes: 21 additions & 18 deletions app/src/main/java/ui/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,27 @@ class MainActivity : AppCompatActivity() {
writeSetting("Post Processing", "soft particles", if(prefs.getBoolean("gs_soft_particles", false)) "true" else "false")
writeSetting("Post Processing", "transparent postpass", if(prefs.getBoolean("gs_transparent_postpass", false)) "true" else "false")

// Visuals Shadows
if(File(Constants.USER_CONFIG + "/extensions.log").exists() &&
File(Constants.USER_CONFIG + "/extensions.log").readText().contains("GL_EXT_depth_clamp")) {

writeSetting("Shadows", "enable shadows",
if(prefs.getBoolean("gs_object_shadows", false) || prefs.getBoolean("gs_terrain_shadows", false) ||
prefs.getBoolean("gs_actor_shadows", false) || prefs.getBoolean("gs_player_shadows", false))
"true" else "false")

writeSetting("Shadows", "object shadows", if(prefs.getBoolean("gs_object_shadows", false)) "true" else "false")
writeSetting("Shadows", "terrain shadows", if(prefs.getBoolean("gs_terrain_shadows", false)) "true" else "false")
writeSetting("Shadows", "actor shadows", if(prefs.getBoolean("gs_actor_shadows", false)) "true" else "false")
writeSetting("Shadows", "player shadows", if(prefs.getBoolean("gs_player_shadows", false)) "true" else "false")
writeSetting("Shadows", "indoor shadows", if(prefs.getBoolean("gs_indoor_shadows", true)) "true" else "false")
writeSetting("Shadows", "shadow map resolution", prefs.getString("gs_shadow_map_resolution", "1024").toString())
writeSetting("Shadows", "compute scene bounds", prefs.getString("gs_shadow_computation_method", "bounds").toString())
writeSetting("Shadows", "maximum shadow map distance", prefs.getString("gs_shadows_distance", "8192").toString())
writeSetting("Shadows", "shadow fade start", prefs.getString("gs_shadows_fade_start", "0.9").toString())
writeSetting("Shadows", "percentage closer filtering", prefs.getString("gs_shadows_pcf", "1").toString())
}

// Animations
writeSetting("Game", "use magic item animations", if(prefs.getBoolean("gs_use_magic_item_animation", false)) "true" else "false")
writeSetting("Game", "use additional anim sources", if(prefs.getBoolean("gs_use_additional_animation_sources", false)) "true" else "false")
Expand Down Expand Up @@ -574,24 +595,6 @@ class MainActivity : AppCompatActivity() {
}
}

// set up gamma, if invalid, use the default (1.0)
var gamma = 1.0f
try {
gamma = prefs.getString("pref_gamma", "")!!.toFloat()
} catch (e: NumberFormatException) {
// Reset the invalid setting
with(prefs.edit()) {
putString("pref_gamma", "")
apply()
}
}

try {
Os.setenv("OPENMW_GAMMA", "%.2f".format(Locale.ROOT, gamma), true)
} catch (e: ErrnoException) {
// can't really do much if that fails...
}

// If scaling didn't get set, determine it automatically
if (scaling == 0f) {
scaling = MyApp.app.defaultScaling
Expand Down
95 changes: 94 additions & 1 deletion app/src/main/java/ui/activity/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ import android.preference.Preference
import android.preference.PreferenceFragment
import android.preference.PreferenceGroup

import constants.Constants
import android.widget.Toast
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)
Expand Down Expand Up @@ -71,6 +82,12 @@ class FragmentGameSettings : PreferenceFragment() {
true
}

findPreference("game_settings_shadows").setOnPreferenceClickListener {
val intent = Intent(activity, Shadows_SettingsActivity::class.java)
this.startActivity(intent)
true
}

findPreference("game_settings_animations").setOnPreferenceClickListener {
val intent = Intent(activity, Animations_SettingsActivity::class.java)
this.startActivity(intent)
Expand Down Expand Up @@ -154,7 +171,60 @@ class FragmentGameSettingsPage(val res: Int) : PreferenceFragment(), OnSharedPre
addPreferencesFromResource(res)
preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(this)

if (res == R.xml.gs_game_mechanics) findPreference("gs_always_allow_npc_to_follow_over_water_surface").isEnabled = preferenceScreen.sharedPreferences.getBoolean("gs_build_navmesh", true)
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, pbuffer require egl 1.4 what is better?
//val eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, texture_view.surfaceTexture, null)
if (egl.eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, eglContext) == true) {
val extensions = GLES20.glGetString(GLES20.GL_EXTENSIONS)
File(Constants.USER_CONFIG + "/extensions.log").writeText(extensions.replace(" ", "\n"))

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

if (extensions.contains("GL_EXT_depth_clamp") == 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_shadow_computation_method").isEnabled = false
findPreference("gs_shadows_distance").isEnabled = false
findPreference("gs_shadows_fade_start").isEnabled = false
findPreference("gs_shadows_pcf").isEnabled = false
}
}
else Toast.makeText(this.getActivity(), "Cant check for extensions!, shadows setting wont be applyed!", Toast.LENGTH_SHORT).show()
}

if (res == R.xml.gs_shadows) getExtensionList()

// what is this?
//if (res == R.xml.gs_game_mechanics) findPreference("gs_always_allow_npc_to_follow_over_water_surface").isEnabled = preferenceScreen.sharedPreferences.getBoolean("gs_build_navmesh", true)

if (res == R.xml.gs_animations) updatePreference(preferenceScreen.sharedPreferences, "gs_use_additional_animation_sources")
if (res == R.xml.gs_engine) updatePreference(preferenceScreen.sharedPreferences, "gs_build_navmesh")
Expand Down Expand Up @@ -229,6 +299,29 @@ class Visuals_SettingsActivity : AppCompatActivity() {
}
}

class Shadows_SettingsActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)

setSupportActionBar(findViewById(R.id.settings_toolbar))
supportActionBar?.setDisplayHomeAsUpEnabled(true)

fragmentManager.beginTransaction().replace(R.id.settings_frame, FragmentGameSettingsPage(R.xml.gs_shadows)).commit()
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
onBackPressed()
true
}
else -> super.onOptionsItemSelected(item)
}
}
}

class Animations_SettingsActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
24 changes: 0 additions & 24 deletions app/src/main/java/ui/fragments/FragmentSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ class FragmentSettings : PreferenceFragment(), OnSharedPreferenceChangeListener
addPreferencesFromResource(R.xml.settings)
preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(this)

updateGammaState()

findPreference("pref_controls").setOnPreferenceClickListener {
val intent = Intent(activity, ConfigureControls::class.java)
this.startActivity(intent)
Expand Down Expand Up @@ -177,7 +175,6 @@ class FragmentSettings : PreferenceFragment(), OnSharedPreferenceChangeListener

override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
updatePreference(findPreference(key), key)
updateGammaState()
}

private fun updatePreference(preference: Preference?, key: String) {
Expand All @@ -196,25 +193,4 @@ class FragmentSettings : PreferenceFragment(), OnSharedPreferenceChangeListener
preference.summary = preference.sharedPreferences.getString("game_files", "")
}
}

/**
* @brief Disable gamma preference if GLES1 is selected
*/
private fun updateGammaState() {
val sharedPref = preferenceScreen.sharedPreferences
findPreference("pref_gamma").isEnabled =
sharedPref.getString("pref_graphicsLibrary_v2", "") != "gles1"

var isnohighpenabled = false;
if(sharedPref.getString("pref_shadersDir_v2", "") == "modified")
isnohighpenabled = true
findPreference("pref_nohighp").isEnabled = isnohighpenabled
/*
var isAdditionalAnimSourcesEnabled = false;
if(sharedPref.getBoolean("gs_use_additional_animation_sources", false) == true) isAdditionalAnimSourcesEnabled = true
findPreference("gs_weapon_sheating").isEnabled = isAdditionalAnimSourcesEnabled
findPreference("gs_shield_sheating").isEnabled = isAdditionalAnimSourcesEnabled
*/
}

}
70 changes: 45 additions & 25 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,50 @@
<item>2</item>
</string-array>

<string-array name="gs_shadow_map_resolution_entries">
<item>512</item>
<item>1024</item>
<item>2048</item>
<item>4096</item>
</string-array>

<string-array name="gs_shadow_map_resolution_values">
<item>512</item>
<item>1024</item>
<item>2048</item>
<item>4096</item>
</string-array>

<string-array name="gs_shadow_planes_computation_method_entries">
<item>None</item>
<item>Bounds</item>
<item>Primitives</item>
</string-array>

<string-array name="gs_shadow_planes_computation_method_values">
<item>none</item>
<item>bounds</item>
<item>primitives</item>
</string-array>

<string-array name="gs_shadow_pcf_entries">
<item>Disabled</item>
<item>4 samples</item>
<item>2x2x4 samples</item>
<item>3x3x4 samples</item>
<item>4x4x4 samples</item>
<item>5x5x4 samples</item>
</string-array>

<string-array name="gs_shadow_pcf_values">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
</string-array>

<string name="general_settings">Setup</string>
<string name="start_game_label">Start game</string>
<string name="closeDrawer">Navigation View</string>
Expand All @@ -81,13 +125,11 @@
<string name="pref_graphics">Graphics</string>
<string name="pref_commandLine">Custom command line arguments</string>
<string name="pref_envLine">Custom environment flags</string>
<string name="pref_nohighp">Medium shader precision</string>
<string name="pref_ui">User interface</string>
<string name="pref_textureShrinking">Texture shrinking</string>
<string name="pref_textureShrinking_default">none</string>
<string name="pref_shadersDir">Shaders preset</string>
<string name="pref_shadersDir_default">none</string>
<string name="pref_gamma">Gamma</string>
<string name="pref_uiScaling">UI scaling factor</string>
<string name="uiScaling_auto">Auto (%1$.2f)</string>
<string name="pref_screen_keeper">Keep screen always on</string>
Expand All @@ -111,23 +153,12 @@
<string name="btn_resetControlsLayout">Reset to defaults</string>
<string name="pref_physicsFPS2">Physics FPS</string>

<string-array name="pref_graphicsLibrary_entries">
<item>GLESv1</item>
<item>GLESv2</item>
</string-array>

<string-array name="pref_graphicsLibrary_values">
<item>gles1</item>
<item>gles2</item>
</string-array>

<string-array name="pref_physicsFPS2_entries">
<item>20</item>
<item>30</item>
<item>60</item>
</string-array>


<string-array name="pref_textureShrinking_entries">
<item>None</item>
<item>Low</item>
Expand All @@ -142,18 +173,6 @@
<item>high</item>
</string-array>

<string-array name="pref_shadersDir_entries">
<item>Original</item>
<item>Modified</item>
<item>Zesterer</item>
</string-array>

<string-array name="pref_shadersDir_values">
<item>none</item>
<item>modified</item>
<item>zesterer</item>
</string-array>

<string name="pref_physicsFPS2_default">30</string>


Expand All @@ -174,6 +193,7 @@
<string name="activity_settings">Settings</string>
<string name="game_mechanics_activity_settings">Game Mechanics</string>
<string name="visuals_activity_settings">Visuals</string>
<string name="shadows_activity_settings">Shadows</string>
<string name="animations_activity_settings">Animations</string>
<string name="interface_activity_settings">Interface</string>
<string name="bug_fixes_activity_settings">Bug Fixes</string>
Expand Down
Loading

0 comments on commit 99d256e

Please sign in to comment.