Skip to content

Commit

Permalink
Pass sample count
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 committed Feb 15, 2024
1 parent 127a842 commit 97abdb0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
9 changes: 7 additions & 2 deletions Celestia/src/main/cpp/CelestiaRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class CelestiaRenderer
EGLContext context = EGL_NO_CONTEXT;
EGLConfig config {};
EGLint format {};
int sampleCount { 0 };

static JavaVM *jvm;
static jmethodID flushTasksMethod;
Expand Down Expand Up @@ -147,6 +148,10 @@ bool CelestiaRenderer::initialize()
destroy();
return false;
}

EGLint numSamples;
if (eglGetConfigAttrib(display, config, EGL_SAMPLES, &numSamples) && numSamples > 1)
sampleCount = numSamples;
} else {
if (!eglChooseConfig(display, attribs, &config, 1, &numConfigs)) {
LOG_ERROR("eglChooseConfig() returned error %d", eglGetError());
Expand Down Expand Up @@ -377,7 +382,7 @@ void *CelestiaRenderer::threadCallback(void *self)
{
if (renderer->surface != EGL_NO_SURFACE && !renderer->engineStartedCalled)
{
bool started = static_cast<bool>(newEnv->CallBooleanMethod(renderer->javaObject, CelestiaRenderer::engineStartedMethod));
bool started = static_cast<bool>(newEnv->CallBooleanMethod(renderer->javaObject, CelestiaRenderer::engineStartedMethod, static_cast<jint>(renderer->sampleCount)));
if (!started)
break;
renderer->engineStartedCalled = true;
Expand Down Expand Up @@ -431,7 +436,7 @@ Java_space_celestia_celestia_Renderer_c_1initialize(JNIEnv *env, jobject thiz, j
auto renderer = (CelestiaRenderer *)ptr;
renderer->javaObject = env->NewGlobalRef(thiz);
jclass clazz = env->GetObjectClass(thiz);
CelestiaRenderer::engineStartedMethod = env->GetMethodID(clazz, "engineStarted", "()Z");
CelestiaRenderer::engineStartedMethod = env->GetMethodID(clazz, "engineStarted", "(I)Z");
CelestiaRenderer::flushTasksMethod = env->GetMethodID(clazz, "flushTasks", "()V");

env->GetJavaVM(&CelestiaRenderer::jvm);
Expand Down
6 changes: 3 additions & 3 deletions Celestia/src/main/java/space/celestia/celestia/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ public void setSurfaceSize(int width, int height) {
}

public interface EngineStartedListener {
boolean onEngineStarted();
boolean onEngineStarted(int samples);
}

public void setEngineStartedListener(EngineStartedListener engineStartedListener) {
this.engineStartedListener = engineStartedListener;
}

private boolean engineStarted() {
private boolean engineStarted(int samples) {
boolean result = false;
if (engineStartedListener != null)
result = engineStartedListener.onEngineStarted();
result = engineStartedListener.onEngineStarted(samples);
engineStartedListener = null;
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto"
android:versionCode="499"
android:versionCode="500"
android:versionName="1.6.9">

<uses-feature android:name="android.hardware.type.pc" android:required="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ class CelestiaFragment: Fragment(), SurfaceHolder.Callback, CelestiaControlView.

if (!hasSetRenderer) {
appCore.setRenderer(renderer)
renderer.setEngineStartedListener {
loadCelestia()
renderer.setEngineStartedListener { samples ->
loadCelestia(samples)
}
hasSetRenderer = true
}
Expand Down Expand Up @@ -296,7 +296,7 @@ class CelestiaFragment: Fragment(), SurfaceHolder.Callback, CelestiaControlView.
}

@SuppressLint("ClickableViewAccessibility")
private fun loadCelestia(): Boolean {
private fun loadCelestia(samples: Int): Boolean {
val data = pathToLoad
val cfg = cfgToLoad
val addonDirs = addonDirsToLoad.toTypedArray()
Expand Down

0 comments on commit 97abdb0

Please sign in to comment.