Skip to content

Commit d6ac796

Browse files
authored
Merge branch 'main' into pf/android-render-val-add-info
2 parents ad3c38e + 5007b4e commit d6ac796

File tree

15 files changed

+116
-36
lines changed

15 files changed

+116
-36
lines changed

android/filament-utils-android/src/main/java/com/google/android/filament/utils/ModelViewer.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,35 @@ class ModelViewer(
266266
}
267267
}
268268

269+
/**
270+
* Resets the model's transform, animation, and camera state to defaults.
271+
* Call this when reusing the same model across multiple tests.
272+
*/
273+
fun resetToDefaultState() {
274+
// 1. Reset Camera parameters
275+
cameraFocalLength = 28f
276+
cameraNear = kNearPlane
277+
cameraFar = kFarPlane
278+
updateCameraProjection()
279+
280+
// 2. Reset the manipulator's look-at vectors to initial state
281+
cameraManipulator?.let { cm ->
282+
cm.jumpToBookmark(cm.homeBookmark)
283+
}
284+
285+
// 3. Reset Animations
286+
animator?.let {
287+
if (it.animationCount > 0) {
288+
it.applyAnimation(0, 0.0f)
289+
}
290+
it.updateBoneMatrices()
291+
}
292+
293+
// 4. Re-apply the unit cube transform to clear custom scaling/translation
294+
clearRootTransform()
295+
transformToUnitCube()
296+
}
297+
269298
/**
270299
* Frees all entities associated with the most recently-loaded model.
271300
*/

android/samples/sample-render-validation/src/main/java/com/google/android/filament/validation/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class MainActivity : Activity(), ValidationRunner.Callback {
175175
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
176176

177177
choreographer = Choreographer.getInstance()
178-
modelViewer = ModelViewer(surfaceView)
178+
modelViewer = ModelViewer(surfaceView=surfaceView, manipulator=null)
179179
inputManager = ValidationInputManager(this)
180180

181181
// Initialize IBL

android/samples/sample-render-validation/src/main/java/com/google/android/filament/validation/ValidationRunner.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ class ValidationRunner(
8383
}
8484

8585
private fun startModel(modelName: String) {
86+
if (currentModelName == modelName) {
87+
Log.i("ValidationRunner", "Reusing model $modelName")
88+
callback?.onStatusChanged("Reusing $modelName for ${currentTestConfig?.name}")
89+
90+
modelViewer.resetToDefaultState()
91+
92+
frameCounter = 0
93+
currentState = State.WARMUP
94+
return
95+
}
96+
8697
currentModelName = modelName
8798
val modelPath = config.models[modelName]
8899
if (modelPath == null) {

filament/backend/include/backend/platforms/PlatformEGLAndroid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class PlatformEGLAndroid : public PlatformEGL, public AndroidNdk {
185185
};
186186

187187
int mOSVersion;
188-
ExternalStreamManagerAndroid& mExternalStreamManager;
188+
ExternalStreamManagerAndroid* mExternalStreamManager = nullptr;
189189
AndroidDetails& mAndroidDetails;
190190
utils::PerformanceHintManager mPerformanceHintManager;
191191
utils::PerformanceHintManager::Session mPerformanceHintSession;

filament/backend/src/opengl/OpenGLContext.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,15 @@ OpenGLContext::OpenGLContext(OpenGLPlatform& platform,
222222
#endif
223223
#endif
224224

225+
#if defined(BACKEND_OPENGL_VERSION_GL) || defined(GL_EXT_disjoint_timer_query)
226+
if (ext.EXT_disjoint_timer_query) {
227+
mGpuTimeSupported = true;
228+
} else
229+
#endif
230+
if (platform.canCreateFence()) {
231+
mGpuTimeSupported = true;
232+
}
233+
225234
// in practice KHR_Debug has never been useful, and actually is confusing. We keep this
226235
// only for our own debugging, in case we need it some day.
227236
#if false && !defined(NDEBUG) && defined(GL_KHR_debug)

filament/backend/src/opengl/OpenGLContext.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,10 @@ class OpenGLContext final : public TimerQueryFactoryInterface {
158158
constexpr static inline size_t getIndexForBufferTarget(GLenum target) noexcept;
159159

160160
ShaderModel getShaderModel() const noexcept { return mShaderModel; }
161-
161+
162162
void resetState() noexcept;
163+
164+
bool isGpuTimeSupported() const noexcept { return mGpuTimeSupported; }
163165

164166
inline void useProgram(GLuint program) noexcept;
165167

@@ -542,6 +544,8 @@ class OpenGLContext final : public TimerQueryFactoryInterface {
542544

543545
Platform::DriverConfig const mDriverConfig;
544546

547+
bool mGpuTimeSupported = false;
548+
545549
void bindFramebufferResolved(GLenum target, GLuint buffer) noexcept;
546550

547551
const std::array<std::tuple<bool const&, char const*, char const*>, sizeof(bugs)> mBugDatabase{{

filament/backend/src/opengl/OpenGLDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2859,7 +2859,7 @@ bool OpenGLDriver::isFrameBufferFetchMultiSampleSupported() {
28592859
}
28602860

28612861
bool OpenGLDriver::isFrameTimeSupported() {
2862-
return TimerQueryFactory::isGpuTimeSupported();
2862+
return mContext.isGpuTimeSupported();
28632863
}
28642864

28652865
bool OpenGLDriver::isAutoDepthResolveSupported() {

filament/backend/src/opengl/OpenGLTimerQuery.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class OpenGLDriver;
4848

4949
// ------------------------------------------------------------------------------------------------
5050

51-
bool TimerQueryFactory::mGpuTimeSupported = false;
51+
5252

5353
TimerQueryFactoryInterface* TimerQueryFactory::init(
5454
OpenGLPlatform& platform, OpenGLContext& context) {
@@ -65,17 +65,14 @@ TimerQueryFactoryInterface* TimerQueryFactory::init(
6565
} else {
6666
impl = new(std::nothrow) TimerQueryNativeFactory(context);
6767
}
68-
mGpuTimeSupported = true;
6968
} else
7069
#endif
7170
if (platform.canCreateFence()) {
7271
// no timer queries, but we can use fences
7372
impl = new(std::nothrow) TimerQueryFenceFactory(platform);
74-
mGpuTimeSupported = true;
7573
} else {
7674
// no queries, no fences -- that's a problem
7775
impl = new(std::nothrow) TimerQueryFallbackFactory();
78-
mGpuTimeSupported = false;
7976
}
8077
assert_invariant(impl);
8178
return impl;

filament/backend/src/opengl/OpenGLTimerQuery.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,9 @@ struct GLTimerQuery : public HwTimerQuery {
6161
*/
6262

6363
class TimerQueryFactory {
64-
static bool mGpuTimeSupported;
6564
public:
6665
static TimerQueryFactoryInterface* init(
6766
OpenGLPlatform& platform, OpenGLContext& context);
68-
69-
static bool isGpuTimeSupported() noexcept {
70-
return mGpuTimeSupported;
71-
}
7267
};
7368

7469
class TimerQueryFactoryInterface {

filament/backend/src/opengl/platforms/ExternalStreamManagerAndroid.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ JNIEnv* ExternalStreamManagerAndroid::getEnvironmentSlow() noexcept {
8080

8181
Stream* ExternalStreamManagerAndroid::acquire(jobject surfaceTexture) noexcept {
8282
// note: This is called on the application thread (not the GL thread)
83+
// The application thread *MUST* be attached to the JVM to pass the java 'surfaceTexture' down
84+
// to filament natively, so we are guaranteed to get a valid JNIEnv from getThreadEnvironment()
85+
// without needing AttachCurrentThread.
8386
JNIEnv* env = VirtualMachineEnv::getThreadEnvironment();
8487
if (!env) {
8588
return nullptr; // this should not happen

0 commit comments

Comments
 (0)