Author Topic: Rendering into two different view at the same time  (Read 2533 times)

Offline Kumaraswamy

  • byte
  • *
  • Posts: 15
    • View Profile
Rendering into two different view at the same time
« on: October 16, 2021, 11:41:40 am »
hi, i am new here, I am using JPTC for android, its working good, but when i load the second another model and Add it to a view, it makes it behave weirdly, can you please help me
« Last Edit: October 16, 2021, 03:59:33 pm by EgonOlsen »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: Vertices only visible in certain camera angles
« Reply #1 on: October 16, 2021, 11:46:43 am »
"It behaves weirdly" doesn't really mean much. I can't possibly help based on this alone. Can you provide more details about what's going on exactly?

Offline Kumaraswamy

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Re: Vertices only visible in certain camera angles
« Reply #2 on: October 16, 2021, 11:48:49 am »
I will attach a screen recording of it in 10 mins.

Offline Kumaraswamy

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Re: Vertices only visible in certain camera angles
« Reply #3 on: October 16, 2021, 11:55:11 am »
Here is the link to the video uploaded in Google Drive:

https://drive.google.com/file/d/1PGnwLQDILIysXZe89jL-w-wKuhy6AkYd/view?usp=sharing

Offline Kumaraswamy

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Re: Vertices only visible in certain camera angles
« Reply #4 on: October 16, 2021, 11:56:40 am »
When I click button 2 to load the second model, it moves by itself and sometimes i also crashes

Offline Kumaraswamy

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Re: Vertices only visible in certain camera angles
« Reply #5 on: October 16, 2021, 11:59:09 am »
here by loading model I mean, the model is loaded correctly from the file (3ds object) but adding it to view using GLSurfaceView creates this behaviour

Offline Kumaraswamy

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Re: Vertices only visible in certain camera angles
« Reply #6 on: October 16, 2021, 02:38:31 pm »
Hi can you please help me with this?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: Vertices only visible in certain camera angles
« Reply #7 on: October 16, 2021, 03:59:05 pm »
I see. jPCT-AE isn't thread safe in a way that it can render into multiple views from different threads at the same time. The reason for this dates back to the early days of Android where performance was largely hindered by the JIT-less Dalvik VM and it's awful garbage collection behaviour. You might want to try to add a static sync object to your class, like

Code: [Select]
private final static Object SYNC = new Object();

and then wrap your rendering code into a synchronized block like so:

Code: [Select]
synchronized(SYNC) {
            if (touchTurn != 0) {
                object3D.rotateY(touchTurn);
                touchTurn = 0;
            }

            if (touchTurnUp != 0) {
                object3D.rotateX(touchTurnUp);
                touchTurnUp = 0;
            }

            buffer.clear(back);
            world.renderScene(buffer);
            world.draw(buffer);
            buffer.display();
}

Yes, that's an awful hack and it might not even work properly, but there's no other chance to make jPCT-AE behave when you are doing the rendering in parallel. Another option is to use one view and either only display one model at a time or render them both into a texture and blit the result onto the screen to simulate the two different views. But that leaves you with managing touch events and such for both simulated views and such annoyances.
« Last Edit: October 16, 2021, 11:26:41 pm by EgonOlsen »

Offline Kumaraswamy

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Rendering into two different view at the same time
« Reply #8 on: October 17, 2021, 07:52:46 am »
thanks, I will try that out!

Offline Kumaraswamy

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Rendering into two different view at the same time
« Reply #9 on: October 17, 2021, 08:09:45 am »
This works perfectly, thank you very much :)