set default renderer to auto

Added auto renderer option in settings
This commit is contained in:
izzy2lost
2025-08-30 20:39:56 -04:00
parent 8f2606956e
commit aa372ec130
6 changed files with 57 additions and 27 deletions
+2 -2
View File
@@ -724,8 +724,8 @@ extern "C"
JNIEXPORT void JNICALL
Java_com_izzy2lost_psx2_NativeApp_renderGpu(JNIEnv *env, jclass clazz,
jint p_value) {
// Accept 12(OpenGL), 13(Software), 14(Vulkan)
if (p_value != 12 && p_value != 13 && p_value != 14)
// Accept -1(Auto), 12(OpenGL), 13(Software), 14(Vulkan)
if (p_value != -1 && p_value != 12 && p_value != 13 && p_value != 14)
return;
// Persist to base settings and apply immediately if possible
@@ -70,7 +70,7 @@ public class GameSettingsDialogFragment extends DialogFragment {
blendingAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spBlendingAccuracy.setAdapter(blendingAdapter);
// Renderer Spinner (no Auto; entries: Vulkan, OpenGL, Software)
// Renderer Spinner (now includes Auto)
Spinner spRenderer = view.findViewById(R.id.sp_renderer);
ArrayAdapter<CharSequence> rendererAdapter = ArrayAdapter.createFromResource(ctx,
R.array.renderer_entries, android.R.layout.simple_spinner_item);
@@ -118,10 +118,11 @@ public class GameSettingsDialogFragment extends DialogFragment {
m = java.util.regex.Pattern.compile("(?m)^Renderer=\\s*(.+)$").matcher(content);
if (m.find()) {
String rv = m.group(1).trim();
int idx = 0; // 0=Vulkan,1=OpenGL,2=Software
if ("Vulkan".equalsIgnoreCase(rv) || "14".equals(rv)) idx = 0;
else if ("OpenGL".equalsIgnoreCase(rv) || "12".equals(rv)) idx = 1;
else if ("Software".equalsIgnoreCase(rv) || "13".equals(rv)) idx = 2;
int idx = 0; // 0=Auto,1=Vulkan,2=OpenGL,3=Software
if ("Auto".equalsIgnoreCase(rv) || "-1".equals(rv)) idx = 0;
else if ("Vulkan".equalsIgnoreCase(rv) || "14".equals(rv)) idx = 1;
else if ("OpenGL".equalsIgnoreCase(rv) || "12".equals(rv)) idx = 2;
else if ("Software".equalsIgnoreCase(rv) || "13".equals(rv)) idx = 3;
spRenderer.setSelection(idx);
appliedRenderer = true;
}
@@ -160,8 +161,13 @@ public class GameSettingsDialogFragment extends DialogFragment {
// If no per-game renderer specified, mirror the global renderer choice
if (!appliedRenderer) {
android.content.SharedPreferences prefs = ctx.getSharedPreferences("app_prefs", Context.MODE_PRIVATE);
int globalRenderer = prefs.getInt("renderer", 14); // default Vulkan
int idx = (globalRenderer == 14) ? 0 : (globalRenderer == 12 ? 1 : 2);
int globalRenderer = prefs.getInt("renderer", -1); // default Auto
int idx;
if (globalRenderer == -1) idx = 0; // Auto
else if (globalRenderer == 14) idx = 1; // Vulkan
else if (globalRenderer == 12) idx = 2; // OpenGL
else if (globalRenderer == 13) idx = 3; // Software
else idx = 0;
spRenderer.setSelection(idx);
}
// If no per-game blending specified, mirror the global blending
@@ -176,8 +182,13 @@ public class GameSettingsDialogFragment extends DialogFragment {
spBlendingAccuracy.setSelection(1);
// Mirror global default when error
android.content.SharedPreferences prefs = ctx.getSharedPreferences("app_prefs", Context.MODE_PRIVATE);
int globalRenderer = prefs.getInt("renderer", 14);
int idx = (globalRenderer == 14) ? 0 : (globalRenderer == 12 ? 1 : 2);
int globalRenderer = prefs.getInt("renderer", -1);
int idx;
if (globalRenderer == -1) idx = 0;
else if (globalRenderer == 14) idx = 1;
else if (globalRenderer == 12) idx = 2;
else if (globalRenderer == 13) idx = 3;
else idx = 0;
spRenderer.setSelection(idx);
spResolution.setSelection(0);
}
@@ -192,7 +203,7 @@ public class GameSettingsDialogFragment extends DialogFragment {
// Apply blending to runtime as well for immediate effect
NativeApp.setBlendingAccuracy(spBlendingAccuracy.getSelectedItemPosition());
// Persist per-game INI explicitly to mirror global defaults and avoid Auto
// Persist per-game INI explicitly (supports Auto as well)
writeGameSettingsIni(ctx, gameSerial, gameCrc,
spBlendingAccuracy.getSelectedItemPosition(),
spRenderer.getSelectedItemPosition(),
@@ -317,7 +328,7 @@ public class GameSettingsDialogFragment extends DialogFragment {
java.io.File ini = new java.io.File(baseDir, fileName);
// Map indices
String rendererName = (rendererIdx == 0) ? "Vulkan" : (rendererIdx == 1 ? "OpenGL" : "Software");
String rendererName = (rendererIdx == 0) ? "Auto" : (rendererIdx == 1 ? "Vulkan" : (rendererIdx == 2 ? "OpenGL" : "Software"));
float upscale = Math.max(1, Math.min(8, resolutionIdx + 1));
int abl = Math.max(0, Math.min(5, blendingAccuracyIdx));
@@ -476,8 +476,11 @@ public class MainActivity extends AppCompatActivity implements GamesCoverDialogF
btn_bios.setOnClickListener(v -> {
int current = getCurrentRendererPref();
int next;
// Cycle: OGL(12) -> VK(14) -> SW(13) -> OGL
if (current == 12) next = 14; else if (current == 14) next = 13; else next = 12;
// Cycle: AUTO(-1) -> VK(14) -> OGL(12) -> SW(13) -> AUTO
if (current == -1) next = 14;
else if (current == 14) next = 12;
else if (current == 12) next = 13;
else next = -1;
setRendererAndSave(next);
});
btn_bios.setOnLongClickListener(v -> {
@@ -969,10 +972,12 @@ public class MainActivity extends AppCompatActivity implements GamesCoverDialogF
private int getCurrentRendererPref() {
SharedPreferences prefs = getSharedPreferences("app_prefs", MODE_PRIVATE);
return prefs.getInt("renderer", 14);
// Default to -1 (Automatic) if not set
return prefs.getInt("renderer", -1);
}
private String rendererShortLabel(int r) {
if (r == -1) return "AUTO";
if (r == 12) return "OGL";
if (r == 13) return "SW";
return "VK"; // 14
@@ -25,6 +25,7 @@ public class SettingsDialogFragment extends DialogFragment {
private static final String PREFS = "app_prefs";
// Renderer constants (match native GSRendererType values used elsewhere)
private static final int RENDERER_AUTO = -1;
private static final int RENDERER_OPENGL = 12;
private static final int RENDERER_SOFTWARE = 13;
private static final int RENDERER_VULKAN = 14;
@@ -33,7 +34,8 @@ public class SettingsDialogFragment extends DialogFragment {
public static void loadAndApplySettings(Context context) {
SharedPreferences prefs = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE);
int renderer = prefs.getInt("renderer", RENDERER_VULKAN);
// Default to Automatic if no renderer has been chosen yet
int renderer = prefs.getInt("renderer", RENDERER_AUTO);
float scale = prefs.getFloat("upscale_multiplier", 1.0f);
int aspectRatio = prefs.getInt("aspect_ratio", 1);
int blendingAccuracy = prefs.getInt("blending_accuracy", 1); // 0..5
@@ -44,8 +46,8 @@ public class SettingsDialogFragment extends DialogFragment {
boolean hudVisible = prefs.getBoolean("hud_visible", false);
// Debug logging
android.util.Log.d("SettingsDialog", "Loading renderer setting: " + renderer +
" (12=OpenGL, 13=Software, 14=Vulkan)");
android.util.Log.d("SettingsDialog", "Loading renderer setting: " + renderer +
" (-1=Auto, 12=OpenGL, 13=Software, 14=Vulkan)");
// Apply all settings
NativeApp.renderGpu(renderer);
@@ -73,6 +75,7 @@ public class SettingsDialogFragment extends DialogFragment {
View view = getLayoutInflater().inflate(R.layout.dialog_settings, null, false);
RadioGroup rgRenderer = view.findViewById(R.id.rg_renderer);
RadioButton rbAuto = view.findViewById(R.id.rb_renderer_auto);
RadioButton rbGl = view.findViewById(R.id.rb_renderer_gl);
RadioButton rbVk = view.findViewById(R.id.rb_renderer_vk);
RadioButton rbSw = view.findViewById(R.id.rb_renderer_sw);
@@ -102,6 +105,7 @@ public class SettingsDialogFragment extends DialogFragment {
ColorStateList brandChecked = new ColorStateList(states, colors);
// RadioButtons
if (rbAuto != null) CompoundButtonCompat.setButtonTintList(rbAuto, brandChecked);
if (rbGl != null) CompoundButtonCompat.setButtonTintList(rbGl, brandChecked);
if (rbVk != null) CompoundButtonCompat.setButtonTintList(rbVk, brandChecked);
if (rbSw != null) CompoundButtonCompat.setButtonTintList(rbSw, brandChecked);
@@ -177,7 +181,7 @@ public class SettingsDialogFragment extends DialogFragment {
spAspectRatio.setAdapter(aspectAdapter);
SharedPreferences prefs = ctx.getSharedPreferences(PREFS, Context.MODE_PRIVATE);
int savedRenderer = prefs.getInt("renderer", RENDERER_VULKAN);
int savedRenderer = prefs.getInt("renderer", RENDERER_AUTO);
float savedScale = prefs.getFloat("upscale_multiplier", 1.0f);
int savedAspectRatio = prefs.getInt("aspect_ratio", 1); // 1 = Auto 4:3/3:2 (recommended)
boolean savedWidescreen = prefs.getBoolean("widescreen_patches", false);
@@ -187,9 +191,10 @@ public class SettingsDialogFragment extends DialogFragment {
boolean savedHud = prefs.getBoolean("hud_visible", false);
int savedBlending = prefs.getInt("blending_accuracy", 1);
if (savedRenderer == RENDERER_VULKAN) rbVk.setChecked(true);
else if (savedRenderer == RENDERER_SOFTWARE) rbSw.setChecked(true);
else rbGl.setChecked(true);
if (savedRenderer == RENDERER_VULKAN && rbVk != null) rbVk.setChecked(true);
else if (savedRenderer == RENDERER_SOFTWARE && rbSw != null) rbSw.setChecked(true);
else if (savedRenderer == RENDERER_OPENGL && rbGl != null) rbGl.setChecked(true);
else if (rbAuto != null) rbAuto.setChecked(true);
int scaleIndex = scaleToIndex(savedScale);
if (scaleIndex < 0 || scaleIndex >= scaleAdapter.getCount()) scaleIndex = 0;
@@ -216,9 +221,11 @@ public class SettingsDialogFragment extends DialogFragment {
.setView(view)
.setNegativeButton("Cancel", (d, w) -> d.dismiss())
.setPositiveButton("Save", (d, w) -> {
int renderer = RENDERER_OPENGL;
int renderer = RENDERER_AUTO;
int checked = rgRenderer.getCheckedRadioButtonId();
if (checked == R.id.rb_renderer_vk) renderer = RENDERER_VULKAN;
if (checked == R.id.rb_renderer_auto) renderer = RENDERER_AUTO;
else if (checked == R.id.rb_renderer_vk) renderer = RENDERER_VULKAN;
else if (checked == R.id.rb_renderer_gl) renderer = RENDERER_OPENGL;
else if (checked == R.id.rb_renderer_sw) renderer = RENDERER_SOFTWARE;
float scale = indexToScale(spScale.getSelectedItemPosition());
@@ -230,8 +237,8 @@ public class SettingsDialogFragment extends DialogFragment {
boolean hudVisible = (swDevHud != null && swDevHud.isChecked());
// Debug logging
android.util.Log.d("SettingsDialog", "Saving renderer setting: " + renderer +
" (12=OpenGL, 13=Software, 14=Vulkan)");
android.util.Log.d("SettingsDialog", "Saving renderer setting: " + renderer +
" (-1=Auto, 12=OpenGL, 13=Software, 14=Vulkan)");
// Save renderer setting first with commit() to ensure immediate write
prefs.edit().putInt("renderer", renderer).apply();
@@ -59,6 +59,12 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rb_renderer_auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Auto"/>
<RadioButton
android:id="@+id/rb_renderer_vk"
android:layout_width="wrap_content"
+1
View File
@@ -29,6 +29,7 @@
</string-array>
<string-array name="renderer_entries">
<item>Automatic (Default)</item>
<item>Hardware (Vulkan)</item>
<item>Hardware (OpenGL)</item>
<item>Software (Slow, accurate)</item>