1

I am developing an OpenGL app for android. The app is now pretty much ready so it was time to get the UI done.

I decided to have the OpenGL app on the left, and the UI on the right (it really doesn't need to be pretty, it's more a demonstration thing).

When it was just the app, it ran flawlessly. 60FPS with no drops whatsoever, smooth movement when controlling the camera. In fact, the app itself still runs flawlessly, but the UI is horrible. I can't scroll without the UI skipping frames like crazy.

I'm new to android, so I imagine something in the way I'm doing the layout is causing some weird recursion bogging down the whole thing.

Here is my layout. Keep in mind the app is locked to landscape at all times.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearlayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <PedroFernandes.NSS.OpenGLView
        android:id="@+id/openGLView3"
        android:layout_width="551dp"
        android:layout_height="match_parent" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <SeekBar
                    android:id="@+id/Time"
                    style="@style/Widget.AppCompat.SeekBar.Discrete"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:minHeight="45dp"
                    android:layout_weight="2"
                    android:max="2399"
                    android:progress="1200" />

                <TextView
                    android:id="@+id/textTime"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="3" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/Year"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:minHeight="45dp"
                    android:layout_weight="2"
                    android:ems="2022"
                    android:inputType="number" />

                <TextView
                    android:id="@+id/textYear"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="3" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/Month"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:minHeight="45dp"
                    android:layout_weight="2"
                    android:ems="9"
                    android:inputType="number" />

                <TextView
                    android:id="@+id/textMonth"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="3" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/Day"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="2"
                    android:minHeight="45dp"
                    android:ems="20"
                    android:inputType="number" />

                <TextView
                    android:id="@+id/textDay"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="3" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/Latitude"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="2"
                    android:minHeight="45dp"
                    android:ems="0"
                    android:inputType="number" />

                <TextView
                    android:id="@+id/textLatitude"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="3" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/Longitude"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="2"
                    android:minHeight="45dp"
                    android:ems="0"
                    android:inputType="number" />

                <TextView
                    android:id="@+id/textLongitude"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="3" />
            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <SeekBar
                    android:id="@+id/G"
                    style="@style/Widget.AppCompat.SeekBar.Discrete"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:minHeight="45dp"
                    android:layout_weight="2"
                    android:min="-999"
                    android:max="999"
                    android:progress="900" />

                <TextView
                    android:id="@+id/textG"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="3" />
            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/AtmPressure"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="2"
                    android:minHeight="45dp"
                    android:ems="101325"
                    android:inputType="number" />

                <TextView
                    android:id="@+id/textAtmPressure"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="3" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/Temperature"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="2"
                    android:minHeight="45dp"
                    android:ems="20"
                    android:inputType="number" />

                <TextView
                    android:id="@+id/textTemperature"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="3" />
            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:minHeight="50dp"
                android:orientation="horizontal">

                <SeekBar
                    android:id="@+id/IndexRefraction"
                    style="@style/Widget.AppCompat.SeekBar.Discrete"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="2"
                    android:minHeight="45dp"
                    android:min="100000"
                    android:max="120000"
                    android:progress="100200" />

                <TextView
                    android:id="@+id/textIndexRefraction"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="3" />
            </LinearLayout>

            <TextView
                android:id="@+id/WaveTitle"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/WaveR"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:minHeight="45dp"
                    android:ems="700"
                    android:inputType="number" />

                <EditText
                    android:id="@+id/WaveG"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:minHeight="45dp"
                    android:ems="530"
                    android:inputType="number" />

                <EditText
                    android:id="@+id/WaveB"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:minHeight="45dp"
                    android:ems="470"
                    android:inputType="number" />

            </LinearLayout>





        </LinearLayout>
    </ScrollView>


</LinearLayout>

It's essentially a scrollable list of slider/input on the left, legend on the right. Is there something in this causing the poor performance? Tested on both a pixel 5 emulator and a S21 ultra.

Thanks

Pedro Fernandes
  • 216
  • 1
  • 12
  • would guess it's poor opengl performance rather than that layout. It's not that long and not dynamic except for that OpenGLView which maybe reinitialize each time you scroll or something like that. https://developer.android.com/studio/profile/android-profiler – zapl Sep 27 '22 at 22:32
  • It's not the opengl. When just sitting there CPU is sitting at 10-12%. As soon as I move the UI it spikes to 60-70% – Pedro Fernandes Sep 27 '22 at 22:39
  • Did you access Android UI components that need to be invalidated inside the OpenGL thread? Then, you need to make sure the UI components are inside the UI thread with `getActivity().runUIThread(()->{ /*UI component code here*/ });`. Include `getActivity()` if they are inside the OpenGL thread in a fragment; otherwise, straight call `runUIThread()` inside the OpenGL thread in an activity. – ecle Sep 28 '22 at 02:27
  • https://stackoverflow.com/questions/51170642/how-runonuithread-is-working-in-the-following-code-without-effecting-the-existin – ecle Sep 28 '22 at 02:37
  • @ecle I'm sorry for the very late reply, but I had some personal problems that kept me away. The thing is, the performace is really bad even without accessing the UI elements at all. Just the fact that they exist makes them super inneficent, making scrolling the ScrollView a nightmare. These UI components, as of right now, exist on the layout xml and no where else – Pedro Fernandes Oct 07 '22 at 12:00

0 Answers0