www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Thomas. on June 30, 2012, 01:58:21 am

Title: Depth buffer texture
Post by: Thomas. on June 30, 2012, 01:58:21 am
What is the best solution for render zbuffer? shader is not problem, but if I have screen resolution 1280*720, do I need texture resolution 2048*1024? I don't know how exactly working GPU with texture, but when I understand correctly power of 2 is needed for mip-mapping?

edit: and what is the best way to implement depth of field? I need three rendering, normal, zbuffer and plane, but how this does intelligently? :D
Title: Re: Depth buffer texture
Post by: EgonOlsen on June 30, 2012, 10:01:46 pm
You have to render the depth buffer into a texture. The actual screen resolution isn't important. To render a depth map into a texture, you can use this method: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Texture.html#setAsShadowMap(boolean) (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Texture.html#setAsShadowMap(boolean)) and make this texture a render target of your frame buffer. However, the resulting texture doesn't contain the depth values directly but packed into ARGB format. The reason is, that i couldn't get depth textures to work on Android at least on my device. So you have to unpack the values before using them.
You can can find the code for this if you unzip the jpct_ae.jar and look at the file defaultFragmentShaderDepth.src. It contains the code to unpack the values within some comments.

About how to do depth of field...i have absolutely no clue how to do this because it never interested me in the slightest... :(

Title: Re: Depth buffer texture
Post by: Thomas. on June 30, 2012, 10:15:55 pm
Ok, I'll try to implement depth of field. Probably I'll have to switch IRenderHook several times on one object in one frame.

edit: And what you mean "The actual screen resolution isn't importan."? how it's working?
Title: Re: Depth buffer texture
Post by: EgonOlsen on June 30, 2012, 10:30:20 pm
I've no idea how it is working, because i don't know how to do depth of field. What i meant was that for rendering into a texture, the screen resolution isn't important because the target texture has a resolution of its own.
Title: Re: Depth buffer texture
Post by: Thomas. on June 30, 2012, 10:44:00 pm
So, if I understood correctly, I can use texture 16x16, but when I'll use it as render target, doesn't matter on it?
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 01, 2012, 09:19:57 am
You will be rendering into a 16*16 texture then. All i was trying to say is that the texture resolution has nothing to do with the screen resolution....
Title: Re: Depth buffer texture
Post by: Thomas. on July 03, 2012, 04:25:08 pm
How can I calculate FOV to degree?

edit: solved, in java doc is formula
Title: Re: Depth buffer texture
Post by: Thomas. on July 03, 2012, 08:43:10 pm
Could you add method for create texture with any dimension, please? I have "out of memory error" with two texture with size 2048*1024. Or no storing copies in main memory.
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 03, 2012, 09:43:01 pm
Just create one with a color of null.

Edit: 2048*1024 is insane on a mobile device anyway IMHO...
Title: Re: Depth buffer texture
Post by: Thomas. on July 03, 2012, 09:52:38 pm
NullPointerException... I agree, but I can not create texture with size 1280*720. I need two textures, first with zbuffer, second with image buffer and in third render is applied effect.
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 03, 2012, 09:58:27 pm
Oops...that used to work. I'll fix it...
Title: Re: Depth buffer texture
Post by: Thomas. on July 03, 2012, 10:11:53 pm
omg, I'm very complicated counted size of plane, that has same size like the screen and I forgot on model view projection matrix in shader :D ok, thanks :)
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 03, 2012, 10:13:51 pm
Anyway, the null pointer might be fixed in the version that i've just uploaded (look the other thread for more info).
Title: Re: Depth buffer texture
Post by: Thomas. on July 03, 2012, 10:29:38 pm
NullPointerException still bother... did you mean "new Texture(512, 256, null);"?
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 03, 2012, 10:32:46 pm
Yes...can you post the exception?
Title: Re: Depth buffer texture
Post by: Thomas. on July 03, 2012, 10:36:59 pm
Code: [Select]
07-03 22:36:12.791: E/AndroidRuntime(14034): FATAL EXCEPTION: GLThread 8591
07-03 22:36:12.791: E/AndroidRuntime(14034): java.lang.NullPointerException
07-03 22:36:12.791: E/AndroidRuntime(14034): at com.threed.jpct.Texture.<init>(Texture.java:273)
07-03 22:36:12.791: E/AndroidRuntime(14034): at cz.chladek.mygame.util.DOFHelper.<init>(DOFHelper.java:30)
07-03 22:36:12.791: E/AndroidRuntime(14034): at cz.chladek.mygame.AppActivity$MyRenderer.onSurfaceChanged(AppActivity.java:471)
07-03 22:36:12.791: E/AndroidRuntime(14034): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1455)
07-03 22:36:12.791: E/AndroidRuntime(14034): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 03, 2012, 10:40:54 pm
Thanks. Looks like i forgot to deploy the fixed version. Please download again.
Title: Re: Depth buffer texture
Post by: Thomas. on July 03, 2012, 10:46:08 pm
NullPointerException is gone, but I can not confirm the functionality, I have bug in my code
Title: Re: Depth buffer texture
Post by: Thomas. on July 03, 2012, 11:19:14 pm
Oh, maybe I get it. I need to send plane to GPU with the same size like the screen size. First problem was frustum culling, because coordinates are in another coordinate system, I didn't realize, that will be discard (and probably if is camera position in 0 and object position in 0, will be also discard). And probably second problem is in building object and merge the vertices? Could you confirm it? If yes, how can I fix it?

Code: [Select]
plane.addTriangle(new SimpleVector(-1, -1, -1), 0, 1, new SimpleVector(-1, 1, 1), 1, 0, new SimpleVector(-1, -1, 1), 0, 0);
plane.addTriangle(new SimpleVector(-1, -1, -1), 0, 1, new SimpleVector(-1, 1, -1), 1, 1, new SimpleVector(-1, -1, 1), 1, 0);
plane.translate(1, 0, 1);
worldDOF.getCamera().lookAt(new SimpleVector(-1,0,0));
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 03, 2012, 11:36:40 pm
Confirm what? That it will be clipped away if it's behind the front plane? Yes, it will...and it has to, because it would be impossible to render it. But you can give it any depth you like as long as you adjust the xy-coordinates accordingly. The Overlay-class does exactly that and you can get the Object3D from it...maybe that helps?
Title: Re: Depth buffer texture
Post by: Thomas. on July 04, 2012, 01:11:44 am
Yes, it's exactly what I need. But I have problem with rendering into texture. If I render normal scene into texture and apply it on a object, object is black. We've deal with rendering into texture, but it must works. I have some demos, that running on SGS1 and SGS3 and game Nova3 uses deep of field effect, which running uses rendering into texture.
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 04, 2012, 08:58:53 am
The fact that some app based on the NDK works fine doesn't say much about the SDK. They should behave similar, but there are differences.
The last time i checked, render targets worked fine on my Nexus S. Make sure that your texture is square. Non-square textures will be rendered all black in OpenGL ES2.0 on some devices. Also try to play around with http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Config.html#renderTargetsAsSubImages (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Config.html#renderTargetsAsSubImages) in case you haven't already. If it still doesn't work: Do you have a SDK(!) based example with source code that works on your device?
And have i mentioned that i hate render-to-texture? This code works on the desktop with all chips that i've tried, it works on my device...it even works on BlackBerry. Why can't it just work on f!"&"&/!'## Mali chipsets? Why does somebody use Mali-GPUs in the first place?
Title: Re: Depth buffer texture
Post by: Thomas. on July 04, 2012, 10:05:10 am
Problem solved, null parameter in texture constructor.

edit: and I need constructor, that will ignore power of 2, please. I can't render into larger texture than is screen.
edit2: replace "defaultFragmentShaderDepth.src" shader probably doesn't work
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 04, 2012, 12:19:03 pm
edit: and I need constructor, that will ignore power of 2, please. I can't render into larger texture than is screen.
It's not that easy. Supporting non-power of two textures puts some heavy restrictions on filter modes, clamping and doesn't work in ES1.x. I can't add a simple contructor for this and all will be fine. I have to modify the whole texture pipeline...it will take some time to add this.

edit2: replace "defaultFragmentShaderDepth.src" shader probably doesn't work
The log should tell you, if the replacement took place or not. Albeit that shader's name isn't mentioned in the docs, there's no restriction on the name. It either works for no shader or for all...and i currently don't see a reason why it shouldn't work. It hasn't changed for ages.

About the "problem solved"...does that mean that render targets are now working?
Title: Re: Depth buffer texture
Post by: Thomas. on July 04, 2012, 12:42:33 pm
Render to targets working if I don't use null as color in texture constructor. On mali is fine, on adreno seems like mip-mapping texture (I think that this happened also on powervr, but I can't test it now).
For replace the shader I used this. Is it right? No output log and also no in debug mode.
Code: [Select]
GLSLShader.addReplacement("defaultFragmentShaderDepth.src","");
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 04, 2012, 12:55:58 pm
You have to add the replacement at the beginning. After creating the FrameBuffer, it'll be too late. However, replacing it with nothing makes no sense anyway. I'll try to find the reason why it doesn't work with the null-color.
Title: Re: Depth buffer texture
Post by: Thomas. on July 04, 2012, 03:41:22 pm
Depth of field working :) for now in 1024*512. But... rendering normal scene without any effects takes 7ms (strange, doesn't matter on count of per-pixel lights :) but even stranger, that also 7 ms takes rendering without any lights (super fast fragment processors?)). When I render exactly same scene to texture (in lower resolution, about 55% of original) and don't use them (so just render, nothing else), render zbuffer takes 20ms, render scene 28ms. If they are also used, rendering scene takes about 60ms... where is problem? textures are copied into internal memory?
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 04, 2012, 04:13:16 pm
No. Nobody copies anything from or into main memory when using render targets. Render to texture is solely done on the GPU. No idea why it's so much slower. I guess the hardware just isn't optimized that much for this application. Or your shaders are not as optimized as they could be.

Screen shot of the result?
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 04, 2012, 04:19:28 pm
No. Nobody copies anything from or into main memory when using render targets.
No, wait...this might not be entirely true. I think i'm not using FBOs for render targets in jPCT-AE...most likely because there is no support for it in ES 1.x. I'll look into ES 2.0 again to see if it's supported there...
Title: Re: Depth buffer texture
Post by: Thomas. on July 04, 2012, 06:12:35 pm
So far it is not ideal, resolution, aspect ratio, I can not control distance, bias,... from application. Support mobile OGL something similar like desktop version for creating depth texture? It can be faster, than user shaders...

Code: [Select]
depthTexture = Utils::CreateTexture(width, height, NULL, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT);
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 04, 2012, 07:39:37 pm
This never worked...at least on my phone. It always caused to phone to hang, so i gave up on it.
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 04, 2012, 09:02:57 pm
No, wait...this might not be entirely true. I think i'm not using FBOs for render targets in jPCT-AE...most likely because there is no support for it in ES 1.x. I'll look into ES 2.0 again to see if it's supported there...
must...recalibrate...brain...i'm already using render buffers when in OpenGL ES 2.0 mode. I just completely forgot about it. It might be possible to improve render buffer management when using multiple buffers in one frame though. I'll look at it and report back...
Title: Re: Depth buffer texture
Post by: Thomas. on July 04, 2012, 09:14:44 pm
Ok, thanks. Now I'm doing UV's for monastery ;)
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 04, 2012, 09:47:37 pm
I've updated the jpct_ae.jar. The new version should handle multiple buffers faster and is also able to deal with color=null. Please give it a try.
Title: Re: Depth buffer texture
Post by: Thomas. on July 05, 2012, 12:27:09 pm
You do miracles, render depth texture takes 6ms, render scene 4ms (I don't call method renderScene() again), DOF effect 0.3ms :) But fps is 26... Do you know when render thread sleep for vsync? Is it fb.display()?
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 05, 2012, 12:43:56 pm
I would expect vsync to kick in after onDrawFrame(). FrameBuffer.display() doesn't do this in jPCT-AE (it does so in the desktop version). The frame switching is solely handled by Android itself. I don't have any influence on that.

Keep in mind that the GPU can delay tasks, i.e. the call may already have returned but the GPU is still drawing things.
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 05, 2012, 09:39:33 pm
The jar has been updated again. I've added a static factory method to Texture to create nPot-textures (public static Texture creatNPotTexture(int width, int height, RGBColor col)).
Title: Re: Depth buffer texture
Post by: Thomas. on July 05, 2012, 10:44:06 pm
It's working ;) I'm going to look for some optimization...
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 06, 2012, 10:07:33 am
It's working ;) I'm going to look for some optimization...
It's time for a screen shot then... ;)
Title: Re: Depth buffer texture
Post by: Thomas. on July 06, 2012, 10:15:21 am
I just save my map and models to OBJ file and export to SER, this afternoon here will be ;)
Title: Re: Depth buffer texture
Post by: Thomas. on July 06, 2012, 04:53:31 pm
The most expensive is DOF effect. If I render depth buffer and scene, game running 56fps (from 60), but with applied DOF effect, fps drop down to 23... Now I take 16 samples of surrounding pixels. It is 16.5 million times of reading color from texture. I'll try to reduce this number to minimum.

Here it is, but without textures it is bad...
(http://s18.postimage.org/ics9ynjwl/device_2012_07_06_164234.jpg) (http://postimage.org/image/ics9ynjwl/)
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 06, 2012, 08:21:01 pm
Looks nice. Why are you doing everything without texture btw? I've never seen a screen shot of that game with textures...or have i?

I do understand that the color buffer target has to have screen size, but does the depth buffer target has to have it? Isn't it sufficient to render it at a quarter of the screen resolution and save some fill rate that way?
Title: Re: Depth buffer texture
Post by: Thomas. on July 06, 2012, 08:40:33 pm
Before, I'm was lazy to do textures, but if I didn't them immediately, I don't ever :D So, every new model what I do has texture, these models are more than year old. Yes, I'll try it, it'll be definitely faster. And it seems, that anti-aliasing is not applied on the render target...
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 06, 2012, 09:58:43 pm
And it seems, that anti-aliasing is not applied on the render target...
Yes. Because that's not possible.
Title: Re: Depth buffer texture
Post by: Thomas. on July 06, 2012, 10:25:20 pm
And it seems, that anti-aliasing is not applied on the render target...
Yes. Because that's not possible.

Could you explain it? I reduce depth resolution to quarter, it brought 3fps. And also reduce samples from 16 to 8 and fps is now 55, satisfaction 8)

edit: Accumulation buffer, which is needed for anti-aliasing, is not defined in FBO.
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 06, 2012, 10:56:37 pm
Why not just render into a larger texture and let the gpu scale it down?
Title: Re: Depth buffer texture
Post by: Thomas. on July 06, 2012, 11:42:29 pm
I tried the texture enlarged by 50, but result seems be same... It's not high priority for me
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 06, 2012, 11:55:06 pm
I can't find anything for Android that shows how this can be enabled. I found some extenstions, but the mentioned calls are not present in the SDK. You can do something like FXAA in your shader though.
Title: Re: Depth buffer texture
Post by: Thomas. on July 10, 2012, 10:55:23 pm
Now, I need depth buffer from previous rendering. I render scene to texture and I have to use this depth buffer to next "normal" rendering. FOB has its depth buffer, I need it for normal rendering. Is it possible?
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 10, 2012, 11:37:16 pm
The depth buffer will be rendered into a render buffer, the color buffer into a FBO. You can write, just like it happens when you set a texture as shadow map, the depth values into the color buffer, but you can't access the actual render buffer (by design of a render buffer). However, i'm not sure if i really get what you want to do...
Title: Re: Depth buffer texture
Post by: Thomas. on July 10, 2012, 11:47:03 pm
I have two worlds, in both are objects. I render first world into texture and second world normal. I need to use depth buffer from first world while is rendering second world.
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 11, 2012, 07:10:34 am
I don't see how this should work that way. Like you can't access the color buffer in the fragment shader, you can't access the depth buffer either...especially not if it's not even a part of the current render setup but of some past rendering. The only way i see is to use a texture that contains this buffer, but even then i'm unsure how to map it onto the scene so that it matches the actual depth buffer.

Why not render both worlds into the same texture without clearing. That way, the depth buffer would be evaluated automatically by the rendering process.
Title: Re: Depth buffer texture
Post by: Thomas. on July 11, 2012, 09:56:14 am
Why not render both worlds into the same texture without clearing. That way, the depth buffer would be evaluated automatically by the rendering process.

Yes, this is what I talking about, but I need render one to texture and second to screen, when I just skip fb.clear(), nothing happened (because FBO has its depthbuffer and normal rendering has another). I want to know if I can somehow mix it, use depthbuffer (internal, no texture) from first render while is rendered second. I hope that we already understand.
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 11, 2012, 10:14:20 am
Yes, i did get that. But i don't see a way how to accomplish that... ???
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 11, 2012, 01:53:09 pm
Maybe this will work: I can add a method to FrameBuffer to create a render buffer for the depth buffer. I then can make the render target logic reuse this buffer if the render target has the same size as the frame buffer instead of creating its own.
You then have to clear the frame buffer first, then assign the render target and clear it again. Then render into your texture. The depth should be written into the render buffer. Then remove the render target and render directly into the frame buffer. This rendering should use the same render buffer as a depth buffer. However, you still won't be able to access the data directly (just like with the color buffer). Would that help?
Title: Re: Depth buffer texture
Post by: Thomas. on July 11, 2012, 04:12:38 pm
Yes, this is exactly what I need :)
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 11, 2012, 04:20:54 pm
I'll try it and see if it actually works...
Title: Re: Depth buffer texture
Post by: Thomas. on July 11, 2012, 04:42:10 pm
Has this solution any performance loss? I can also set the render target > render > somehow clear image buffer only (could you add method for this, please?)> render with effect > remove render target > render/blit texture... but this need one extra rendering
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 11, 2012, 05:50:04 pm
I've updated the jpct_ae.jar. It includes two new methods in FrameBuffer, createRenderBuffer() and clearColorBufferOnly(RGBColor); The latter one is self-explanatory. The former one does more complicated stuff:


Hope this helps. I've tested the basic functionality but i haven't tested if the depth values rely persist between renderings. I'm not doing anything to prevent them from doing so, but you never know what the driver thinks of this...
Title: Re: Depth buffer texture
Post by: Thomas. on July 11, 2012, 07:09:56 pm
It seems, that depth buffer is not used in second rendering. Texture has same resolution as framebuffer and LogCat says "Using frame buffer's render buffer!". This is my code...

in constructor fb.createRenderBuffer();

Code: [Select]
fb.clear();
fb.setRenderTarget(imageBufferID);
fb.clear();
world.renderScene(fb);
world.draw(fb);
fb.display();
fb.removeRenderTarget();

fb.clearColorBufferOnly(RGBColor.BLACK);
ifWorld.renderScene(fb);
ifWorld.draw(fb);
                // blit
                fb.display();
Title: Re: Depth buffer texture
Post by: Thomas. on July 11, 2012, 08:10:10 pm
Here is simple test app. This app says "Creating render buffer in depth mode!", I don't know where the method should be.

http://dl.dropbox.com/u/26148874/TestProject.zip (http://dl.dropbox.com/u/26148874/TestProject.zip)
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 11, 2012, 08:21:23 pm
The problem seems to be (according to some sparse information on the web), that you can't attach a render buffer to the default frame buffer. You always have to create a FBO to do this.
So what might work instead is this:

Instead of rendering directly into the frame buffer, create an additional render target with the size of the frame buffer, call createRenderBuffer() on the frame buffer and assign the target. Render into that instead of the frame buffer and blit or "overlay" the result into the actual frame buffer. If that works, i'll somehow rework the current API design because it comes down to sharing render buffers between render targets in that case.
Title: Re: Depth buffer texture
Post by: Thomas. on July 11, 2012, 08:48:31 pm
I think that problem with my understanding persists (black screen) :-[ Could you edit test app, please?
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 11, 2012, 09:18:05 pm
I fail to see any relation between the TestProject and the actual problem, but the test case wasn't correct anyway, because it didn't use the static factory-method to create the NPOT-texture. It tried to do that directly in the constructor, which isn't supported. Anyway, i've changed two things in the API:


I've modified your code to reflect this:

Code: [Select]
renderTarget = new NPOTTexture(fb.getWidth(), fb.getHeight(), null);
tm.addTexture("renderTarget", renderTarget);

depthBuffer=new DepthBuffer(fb.getWidth(), fb.getHeight());
renderTarget.setDepthBuffer(depthBuffer);

Setting the depth buffer here has no real purpose though, because your code doesn't use multiple render targets anyway...but i guess that's just because it's a test case.

The jar has been updated as well, of course.
Title: Re: Depth buffer texture
Post by: Thomas. on July 11, 2012, 09:46:09 pm
Oh sorry, I forgot on NPOT texture. I do not know if we are understand in this problem. First render is to texture, second (here I need depth buffer) to "screen". Is needed to render both to the texture and in extra third rendering just blit it?
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 11, 2012, 09:53:47 pm
Yes. You will end up with two render targets of the same size, one depth buffer assigned to them and a final stage where you blit/overlay the result onto screen. No idea if that actually works, but if it doesn't, i don't know what will.
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 11, 2012, 09:59:55 pm
I've updated the jar again with a version that includes a small fix that lets the DepthBuffer survice a context change.
Title: Re: Depth buffer texture
Post by: Thomas. on July 11, 2012, 11:02:29 pm
Something is wrong (green plane would be shaded), but depth really working. And it is very slow, just 39 fps on xperia neo.

(http://s15.postimage.org/d1clffdd3/Screenshot_2012_07_11_22_52_01.jpg) (http://postimage.org/image/d1clffdd3/)

updated test app
http://dl.dropbox.com/u/26148874/TestProject.zip (http://dl.dropbox.com/u/26148874/TestProject.zip)
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 11, 2012, 11:36:54 pm
What am i supposed to see in that test app? It doesn't look like the one on the screen shot!? Nothing is green in it and can't spot any intersections...? Anyway, i don't see a relation between shading and a depth buffer. They have nothing to do with each other. Are you sure that your setup is correct to get this thing shaded?

Regarding performance: That's what you ask for, i'm afraid. You are rendering the screen 3 times per frame. That alone eats fillrate. Combine that with the large NPOT textures you are using and the additional power needed to process the (albeit simple) shaders as well as the state switched needed to change the fbos and that's the result. The code that sets the shared depth buffer is the exact same one as before with the only difference that it uses a different variable to store the render buffer in. It's not performance critical. Apart from that, 39 fps on a Snapdragon device is NOT very slow. 3.9 fps would be very slow.
Title: Re: Depth buffer texture
Post by: Thomas. on July 11, 2012, 11:44:50 pm
By menu button you can switch between objects, in screenshot is second one. Colors are bad. Color of object in second world is from "fb.clearColorBufferOnly(RGBColor.GREEN);" if you call "fb.clearColorBufferOnly(RGBColor.WHITE);", object be white, wtf?
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 11, 2012, 11:46:16 pm
BTW: Don't let these simple test cases fool you. If you are not taxing the cpu much (which you don't do here), the device might clock down. I can see this in the test app on my phone...as long as i make the cube spinning around, performance is around 40-45 fps. But when i stop doing so, it drops to ~30fps...simply because the energy saving kicks in and clocks things down.
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 11, 2012, 11:50:32 pm
By menu button you can switch between objects, in screenshot is second one. Colors are bad. Color of object in second world is from "fb.clearColorBufferOnly(RGBColor.GREEN);" if you call "fb.clearColorBufferOnly(RGBColor.WHITE);", object be white, wtf?
I can't verify this. I've no intersection of that blue plane with any other object. The blue plane is always in front of everything no matter how i turn the objects. And the shading on the objects looks fine to me. Are you sure the download points to the right test case?
Title: Re: Depth buffer texture
Post by: Thomas. on July 12, 2012, 12:00:30 am
On my device it is shaded about 0.5sec. Object in first world has color from fb.clearColorB... When you change this code

Code: [Select]
fb.clear();
fb.setRenderTarget(renderTarget);
fb.clear();
world.renderScene(fb);
world.draw(fb);
fb.display();
fb.removeRenderTarget();

fb.setRenderTarget(renderTarget2);
fb.clearColorBufferOnly(RGBColor.GREEN);
secWorld.renderScene(fb);
secWorld.draw(fb);
fb.display();
fb.removeRenderTarget();

fb.clear();
fb.blit(renderTarget2, 0, 0, 0, 0, fb.getWidth(), fb.getHeight(), FrameBuffer.OPAQUE_BLITTING);

to this
Code: [Select]
fb.clear();
world.renderScene(fb);
world.draw(fb);
secWorld.renderScene(fb);
secWorld.draw(fb);

it is what I want
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 12, 2012, 12:31:24 am
I see...there was a little problem in the buffer sharing code, but i don't think that this has caused it. I've updated the jar anyway, you might want to try it.

On my phone, shading works fine, but the depth buffer doesn't...maybe time still hasn't come for this stuff on current devices. Seems like asking for compatibility problems all the way...
Title: Re: Depth buffer texture
Post by: Thomas. on July 12, 2012, 12:47:07 am
It is same on my phone :(

edit: and what fb.clearColorBufferOnly(...) method? when I replace it by fb.clear(), colors are fine, but of course depth is also cleared...
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 12, 2012, 07:08:25 am
It's the exact same method with the only difference that one sets the flag to clean the depth buffer in addition to the color buffer and the other one doesn't.
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 12, 2012, 07:28:09 am
It is same on my phone :(
Is that so? I thought that on your phone, depth is correct and colors are wrong? On mine, it's the opposite.

...maybe these chips are optimizing away the depth buffer output or something like this so that the render buffer doesn't get filled at all. According to the documentation from PowerVR, this shouldn't be the case, but you never know. The chip itself doesn't need a zbuffer at all because it does it all internally.
Title: Re: Depth buffer texture
Post by: Thomas. on July 12, 2012, 12:23:34 pm
In my test app on my device is immediately after start, and if I rotate teapot, first rendering fine like layer under bad colored rendering, depth working?, second rendering is fine. After a while (max 1sec) is first "fine rendering" gone, depth working and also second rendering working.

(http://s17.postimage.org/dztbq15t7/Screenshot_2012_07_12_12_08_22.jpg) (http://postimage.org/image/dztbq15t7/)

Is there any other solution to preserve the depth buffer?
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 12, 2012, 12:51:18 pm
Judging from the screen shot, your depth buffer never gets cleared (that's why everything is green...it simply doesn't render anything with equal or higher depth at these parts so that the background color is visible)...in comparison to mine, which gets cleared for each render (or never filled...i don't know). I'll add some debug code later today to see, if i've some flaw in the buffer handling. But if not, i would say that it simply doesn't work on current drivers at least for these two architectures.
Title: Re: Depth buffer texture
Post by: Thomas. on July 12, 2012, 01:37:17 pm
I did some testing...
This code show green and also shaded teapot and blinking green/shaded. On screen shot is not visible.
Code: [Select]
fb.clear();
fb.setRenderTarget(renderTarget);
fb.clear();
world.renderScene(fb);
world.draw(fb);
fb.display();
fb.removeRenderTarget();

fb.setRenderTarget(renderTarget2);
fb.clearColorBufferOnly(RGBColor.GREEN);
secWorld.renderScene(fb);
secWorld.draw(fb);
fb.display();
fb.clearZBufferOnly();
fb.removeRenderTarget();

When I press home button and back to app, first and second rendering are fine, but depth buffer doesn't work.
What stencil buffer? Can it collide with depth?
Title: Re: Depth buffer texture
Post by: Thomas. on July 12, 2012, 09:57:20 pm
What differences are among SDK and native code for controlling GPU? In native somehow working sharing depth buffer. I thing that it is used in Nova2 and Nova3.

Left effect (distortion image) can not be done without depth buffer (I think, it is not true, it is excellent, say me how :) ). And it is fast, I played it on Galaxy S.
(http://a4.mzstatic.com/us/r1000/006/Purple/cb/c5/f8/mzl.ohmiddcf.320x480-75.jpg)
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 12, 2012, 10:15:52 pm
I've no idea what they are doing as i've no idea what strange ways might exist to create that effect...and i actually don't care, to be honest. I'm trying to get this depth buffer sharing working because i think it's a useful feature, but if it doesn't work out, i'll disable it and leave it for now. Too much time has already been spend on this IMHO...
Title: Re: Depth buffer texture
Post by: Thomas. on July 12, 2012, 10:53:49 pm
For me it is important, it allows a lot of effects. I can also check depth myself (from depth buffer texture, that is needed for depth of field) but it needs condition and will be slow... so I accept any other solution.
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 12, 2012, 11:16:02 pm
For me it is important, it allows a lot of effects.
I know...that's the only reason why i'm still bothering with it...i've spend the whole evening trying all kinds of things and reading a lot of stuff. I've also modified your test case to get rid of the Overlay and make depth buffer usage more obvious...but on my phone, it all comes down to: The second render pass doesn't use the depth data from the first render pass. It always starts off with an empty depth buffer no matter what i do. It even does this, if i don't bind the render buffer for the depth at all...just because the PowerVRs actually don't need a depth buffer. IMHO, the driver doesn't give a rat's ass about this buffer and it pretty happy with the internal buffer.
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 12, 2012, 11:36:46 pm
I've updated the jar again with latest version. It still doesn't work on my phone, but for the sake of completeness, please give it a try. I don't even know anymore if it really differs from the last one after reverting all my pointless tries...at least it has more debug log output if you enable that.

This is the modified test case that i was using:

Code: [Select]
package cz.chladek.shadertest;

import java.lang.reflect.Field;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.res.Resources;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;

import com.threed.jpct.Camera;
import com.threed.jpct.Config;
import com.threed.jpct.DepthBuffer;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.GLSLShader;
import com.threed.jpct.Light;
import com.threed.jpct.Loader;
import com.threed.jpct.Logger;
import com.threed.jpct.NPOTTexture;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.RGBColor;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;

public class ShaderTest extends Activity {

// Used to handle pause and resume...
private static ShaderTest master = null;

private GLSurfaceView mGLView;
private MyRenderer renderer = null;
private FrameBuffer fb = null;
private World world = null;

private World secWorld;

private World dummyWorld=new World();

private float touchTurn = 0;
private float touchTurnUp = 0;

private float xpos = -1;
private float ypos = -1;

private Texture font = null;

private Object3D[] objects;
private Light light;

private int selectedObject;

private Texture renderTarget;
private Texture renderTarget2;

protected void onCreate(Bundle savedInstanceState) {
Logger.log("onCreate");
//Logger.setLogLevel(Logger.LL_DEBUG);

Logger.setLogLevel(Logger.LL_DEBUG);

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);

if (master != null) {
copy(master);
}

super.onCreate(savedInstanceState);
mGLView = new GLSurfaceView(getApplication());

// Enable the OpenGL ES2.0 context
mGLView.setEGLContextClientVersion(2);

renderer = new MyRenderer();
mGLView.setRenderer(renderer);
setContentView(mGLView);
}

@Override
protected void onPause() {
Logger.log("onPause");
super.onPause();
mGLView.onPause();
}

@Override
protected void onResume() {
Logger.log("onResume");
super.onResume();
mGLView.onResume();
}

@Override
protected void onStop() {
Logger.log("onStop");
super.onStop();
}

private void copy(Object src) {
try {
Logger.log("Copying data from master Activity!");
Field[] fs = src.getClass().getDeclaredFields();
for (Field f : fs) {
f.setAccessible(true);
f.set(this, f.get(src));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public boolean onTouchEvent(MotionEvent me) {
if (me.getAction() == MotionEvent.ACTION_DOWN) {
xpos = me.getX();
ypos = me.getY();
return true;
}

if (me.getAction() == MotionEvent.ACTION_UP) {
xpos = -1;
ypos = -1;
touchTurn = 0;
touchTurnUp = 0;
return true;
}

if (me.getAction() == MotionEvent.ACTION_MOVE) {
float xd = me.getX() - xpos;
float yd = me.getY() - ypos;

xpos = me.getX();
ypos = me.getY();

touchTurn = xd / -100f;
touchTurnUp = yd / -100f;
return true;
}

try {
Thread.sleep(15);
} catch (Exception e) {
// No need for this...
}

return super.onTouchEvent(me);
}

public boolean onKeyDown(int keyCode, KeyEvent msg) {

if (keyCode == KeyEvent.KEYCODE_MENU) {
selectedObject = (selectedObject + 1 == objects.length) ? 0 : selectedObject + 1;
renderer.showObjectIndex(selectedObject);
return true;
}

return super.onKeyDown(keyCode, msg);
}

protected boolean isFullscreenOpaque() {
return true;
}

class MyRenderer implements GLSurfaceView.Renderer {

private int fps = 0;
private int lfps = 0;

private long time = System.currentTimeMillis();

private Resources res;
private GLSLShader pointLightShader;
private TextureManager tm;

public MyRenderer() {
Config.farPlane = 2000;
Config.useNormalsFromOBJ = true;
Texture.defaultToMipmapping(true);
Texture.defaultTo4bpp(true);
}

public void onSurfaceChanged(GL10 gl, int w, int h) {
if (fb != null)
fb.dispose();

fb = new FrameBuffer(w, h);

if (master == null) {
world = new World();
res = getResources();
tm = TextureManager.getInstance();

font = new Texture(res.openRawResource(R.raw.numbers));
font.setMipmap(false);

pointLightShader = new GLSLShader(Loader.loadTextFile(res.openRawResource(R.raw.pixel_light_vertex)),
Loader.loadTextFile(res.openRawResource(R.raw.pixel_light_fragment_1)));

loadObjects();

light = new Light(world);
light.setIntensity(50, 50, 50);
light.setPosition(new SimpleVector(0, 0, -10));

Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 3);
cam.lookAt(objects[selectedObject].getTransformedCenter());

Object3D sp=Primitives.getSphere(2);
sp.translate(-2, 0, 0);
world.addObject(sp);

world.setAmbientLight(100, 100, 100);
world.compileAllObjects();

renderTarget = new NPOTTexture(fb.getWidth(), fb.getHeight(), null);
tm.addTexture("renderTarget", renderTarget);

renderTarget2 = new NPOTTexture(fb.getWidth(), fb.getHeight(), null);
tm.addTexture("renderTarget2", renderTarget2);

DepthBuffer depthBuffer = new DepthBuffer(fb.getWidth(), fb.getHeight());
renderTarget.setDepthBuffer(depthBuffer);
renderTarget2.setDepthBuffer(depthBuffer);

secWorld = new World();

Object3D sp2=Primitives.getSphere(2);
sp2.translate(2, 0, 0);
secWorld.addObject(sp2);

Object3D plane = Primitives.getPlane(1, 2f);
plane.setAdditionalColor(RGBColor.BLUE);
plane.rotateX(0.5f);
plane.build();
secWorld.addObject(plane);
secWorld.getCamera().moveCamera(Camera.CAMERA_MOVEOUT, 3);

if (master == null) {
Logger.log("Saving master Activity!");
master = ShaderTest.this;
}
}
}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
Logger.log("onSurfaceCreated");
}

public void loadObjects() {
world.removeAllObjects();

objects = new Object3D[1];
objects[0] = Loader.loadOBJ(res.openRawResource(R.raw.box_o), res.openRawResource(R.raw.box_m), 1.5f)[0];
/*
objects[1] = Loader.loadOBJ(res.openRawResource(R.raw.plane_o), res.openRawResource(R.raw.plane_m), 2)[0];
objects[2] = Loader.loadOBJ(res.openRawResource(R.raw.teapot_o), res.openRawResource(R.raw.teapot_m), 2)[0];
objects[3] = Loader.loadOBJ(res.openRawResource(R.raw.airplane_o), res.openRawResource(R.raw.airplane_m), 0.013f)[0];
objects[4] = Loader.loadOBJ(res.openRawResource(R.raw.car_o), res.openRawResource(R.raw.car_m), 0.02f)[0];
objects[5] = Loader.loadOBJ(res.openRawResource(R.raw.car2_o), res.openRawResource(R.raw.car2_m), 0.03f)[0];
*/
for (Object3D object : objects)
object.setShader(pointLightShader);

showObjectIndex(selectedObject);

world.addObjects(objects);
}

public void showObjectIndex(int index) {
for (int i = 0; i < objects.length; i++)
if (i != index)
objects[i].setVisibility(false);
else
objects[i].setVisibility(true);
}

public void onDrawFrame(GL10 gl) {
if (touchTurn != 0) {
objects[selectedObject].rotateY(touchTurn);
touchTurn = 0;
}

if (touchTurnUp != 0) {
objects[selectedObject].rotateX(touchTurnUp);
touchTurnUp = 0;
}

fb.setRenderTarget(renderTarget);
fb.clear(RGBColor.RED);
world.renderScene(fb);
world.draw(fb);
fb.display();
fb.removeRenderTarget();

fb.setRenderTarget(renderTarget2);
fb.blit(renderTarget, 0, 0, 0, 0, fb.getWidth(), fb.getHeight(), FrameBuffer.OPAQUE_BLITTING);
secWorld.renderScene(fb);
secWorld.draw(fb);
fb.display();
fb.removeRenderTarget();

fb.blit(renderTarget2, 0, 0, 0, 0, fb.getWidth(), fb.getHeight(), FrameBuffer.OPAQUE_BLITTING);

blitNumber(lfps, 5, 5);
fb.display();

if (System.currentTimeMillis() - time >= 1000) {
lfps = fps;
fps = 0;
time = System.currentTimeMillis();
}
fps++;
}

private void blitNumber(float number, int x, int y) {
if (font != null) {
String sNum = Float.toString(number);

for (int i = 0; i < sNum.length(); i++) {
char cNum = sNum.charAt(i);
int iNum = cNum - 48;
fb.blit(font, iNum * 5, 0, x, y, 5, 9, 5, 9, 10, true, null);
x += 5;
}
}
}
}
}

Title: Re: Depth buffer texture
Post by: Thomas. on July 13, 2012, 01:36:32 am
I see that blit is working when is rendered to target, now. Texture from render to target is flipped. When I fixed it, first render is fine, second render is find, depth is fine :) but... When I'm rotating a object in second rendering, object's blinking (rotating a object in first one is fine).

With this code are everything OK, but blinks part of second object, that should be hidden (discard by depth buffer).
Code: [Select]
fb.setRenderTarget(renderTarget);
fb.clear();
world.renderScene(fb);
world.draw(fb);
fb.display();
fb.removeRenderTarget();

fb.setRenderTarget(renderTarget2);
fb.blit(renderTarget, 0, 0, 0, fb.getHeight(), fb.getWidth(), fb.getHeight(), fb.getWidth(), -fb.getHeight(), -1, false, null);
secWorld.renderScene(fb);
secWorld.draw(fb);
fb.display();
fb.clearZBufferOnly();
fb.removeRenderTarget();

fb.blit(renderTarget2, 0, 0, 0, fb.getHeight(), fb.getWidth(), fb.getHeight(), fb.getWidth(), -fb.getHeight(), -1, false, null);

I know, you got sick of preservation depth, but is there any chance to fix blinking? And is it all right on your device, when you flip texture from the rendering?
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 13, 2012, 09:53:02 am
Can you catch this blinking in some screen shots? Just to get a feel for this. I'll try at home with correct blitting, but i'm 99.999999999% sure that it won't help anything. My phone simply resists to write depth into that buffer or clears it each time it gets bound (which is documented behaviour for the FIRST bind...too bad that the specs say nothing about subsequent binds...).
Title: Re: Depth buffer texture
Post by: Thomas. on July 13, 2012, 02:06:31 pm
Good news, on xperia neo is everything fine. In screenshot is not visible blinking, I took video. When thread is slept for some milliseconds, blinking are gone.

Teapot is in the first render, plane in the second. After 15 second in video, I'm clearing depth buffer in second rendering after is  displayed frame buffer.
http://youtu.be/XtpX2eDIY6A (http://youtu.be/XtpX2eDIY6A)

Log
Code: [Select]
07-13 13:56:40.094: I/jPCT-AE(23604): Binding buffers (1/1)!
07-13 13:56:40.094: I/jPCT-AE(23604): Unbinding buffers (1)!
07-13 13:56:40.094: I/jPCT-AE(23604): Binding buffers (2/1)!
07-13 13:56:40.094: I/jPCT-AE(23604): Unbinding buffers (2)!
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 13, 2012, 09:42:12 pm
...it didn't help anything...as expected. I did some further testing and it is pretty obvious: On my device, the depth buffer somehow gets clear each time i bind the render buffer. This is not supposed to happen, but it does...and i have no idea how to prevent this. I consider it to be a driver bug or at least a weak spot of the GL specs. Because the docs state that this happens for the first bind but don't make any predicates about subsequent binds.

Your video is strange too. It shows some artifacts, but i'm not sure if they come from the rendering or a faulty video compression. If you delay the frames (i.e. add a long sleep at the end), is the image correct at the end of the frame, i.e. does the flickering happen during the rendering process or does it happen because different final frames show different results?
Have you tried if it changes something if you omit the inbetween call to removeRenderTarget(), i.e. simply replace the first with the second?
Title: Re: Depth buffer texture
Post by: Thomas. on July 13, 2012, 11:02:03 pm
Lighter lines is bad video compression (from xperia neo), blinking part of red plane is fault, that I want to show. If I delay the frame (20 millis) and use blit method, all is well (correct rendering, no blinking).
Plane is blinking (if object is rotated), when I blit texture from first rendering in second rendering in full resolution. I set in blit method, that source width and height are half and it is fine.
When plane is blinking, it seems like first texture is showed on screen and after little delayed second texture with artefacts. With delayed frames this doesn't happened.
When I use overlay, texture from first rendering is black (from clear color buffer), but depth working. When I'm rotating objects, teapot is correct, but little bit rotated and like layer under black teapot. So, black or correct teapot is one frame delayed...

Have you tried if it changes something if you omit the inbetween call to removeRenderTarget(), i.e. simply replace the first with the second?

Nothing happened (some as before)

Is there possibility for send mail to ARM and ask for help?
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 14, 2012, 10:39:53 am
To be honest, i've completely lost track of what blinks when and when not. The only thing that i really got is, that it seems to stop blinking when you add some delay. This makes me want to try one more thing....i've updated the jar. FrameBuffer now has a sync()-method. Please add that instead of your delay and see if that helps. If it doesn't, try to clutter the whole code with sync()-calls to see if any of these might help.

About asking in the dev forums (not that i found one for Mali chips at first try...)...i'll try that if nothing else helps, but after visiting the PowerVR-forums yesterday, i wouldn't bet a single penny on that... :(
Title: Re: Depth buffer texture
Post by: Thomas. on July 14, 2012, 01:27:18 pm
With fb.sync() and blit texture from first render is the same result. If I used overlay, correct teapot under black one is not visible, so it something does, but it no help in this case.
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 14, 2012, 02:02:17 pm
Have you tried to add it on other locations in the code too?
Title: Re: Depth buffer texture
Post by: Thomas. on July 14, 2012, 02:11:14 pm
Yes yes, every time I'm trying all options
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 15, 2012, 10:13:10 am
Well...so, because i'm slightly confused about the current state: Do you have any version (with some delay or whatever) that does work? If so, i would like to see the code for that. Or does non of the variants really works in all cases?
Title: Re: Depth buffer texture
Post by: Thomas. on July 15, 2012, 11:19:20 am
With this code is it fine, but only if I'm blitting texture from the first render. When I use overlay, the first texture is black.

Code: [Select]
package cz.chladek.shadertest;

import java.lang.reflect.Field;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.res.Resources;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;

import com.threed.jpct.Camera;
import com.threed.jpct.Config;
import com.threed.jpct.DepthBuffer;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.GLSLShader;
import com.threed.jpct.Light;
import com.threed.jpct.Loader;
import com.threed.jpct.Logger;
import com.threed.jpct.NPOTTexture;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.RGBColor;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;
import com.threed.jpct.util.Overlay;

import cz.chladek.shadertest.R;

public class ShaderTest extends Activity {

// Used to handle pause and resume...
private static ShaderTest master = null;

private GLSurfaceView mGLView;
private MyRenderer renderer = null;
private FrameBuffer fb = null;
private World world = null;

private World secWorld;

private float touchTurn = 0;
private float touchTurnUp = 0;

private float xpos = -1;
private float ypos = -1;

private Texture font = null;

private Object3D[] objects;
private Light light;

private int selectedObject = 0;

private Texture renderTarget;
private Texture renderTarget2;

private Overlay overlay;
private boolean useOverlay;
private boolean clearZBuffer;

protected void onCreate(Bundle savedInstanceState) {
Logger.log("onCreate");
Logger.setLogLevel(Logger.LL_DEBUG);

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);

if (master != null) {
copy(master);
}

super.onCreate(savedInstanceState);
mGLView = new GLSurfaceView(getApplication());

// Enable the OpenGL ES2.0 context
mGLView.setEGLContextClientVersion(2);

renderer = new MyRenderer();
mGLView.setRenderer(renderer);
setContentView(mGLView);
}

@Override
protected void onPause() {
Logger.log("onPause");
super.onPause();
mGLView.onPause();
}

@Override
protected void onResume() {
Logger.log("onResume");
super.onResume();
mGLView.onResume();
}

@Override
protected void onStop() {
Logger.log("onStop");
super.onStop();
}

private void copy(Object src) {
try {
Logger.log("Copying data from master Activity!");
Field[] fs = src.getClass().getDeclaredFields();
for (Field f : fs) {
f.setAccessible(true);
f.set(this, f.get(src));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public boolean onTouchEvent(MotionEvent me) {
if (me.getAction() == MotionEvent.ACTION_DOWN) {
xpos = me.getX();
ypos = me.getY();
return true;
}

if (me.getAction() == MotionEvent.ACTION_UP) {
xpos = -1;
ypos = -1;
touchTurn = 0;
touchTurnUp = 0;
return true;
}

if (me.getAction() == MotionEvent.ACTION_MOVE) {
float xd = me.getX() - xpos;
float yd = me.getY() - ypos;

xpos = me.getX();
ypos = me.getY();

touchTurn = xd / -100f;
touchTurnUp = yd / -100f;
return true;
}

try {
Thread.sleep(15);
} catch (Exception e) {
// No need for this...
}

return super.onTouchEvent(me);
}

public boolean onKeyDown(int keyCode, KeyEvent msg) {

if (keyCode == KeyEvent.KEYCODE_MENU) {
/*
* selectedObject = (selectedObject + 1 == objects.length) ? 0 : selectedObject + 1; renderer.showObjectIndex(selectedObject);
*/

if (useOverlay) {
useOverlay = false;
overlay.setVisibility(false);
} else {
useOverlay = true;
overlay.setVisibility(true);
}

return true;
}
if (keyCode == KeyEvent.KEYCODE_BACK) {
clearZBuffer = clearZBuffer ? false : true;
return true;
}

return super.onKeyDown(keyCode, msg);
}

protected boolean isFullscreenOpaque() {
return true;
}

class MyRenderer implements GLSurfaceView.Renderer {

private int fps = 0;
private int lfps = 0;

private long time = System.currentTimeMillis();

private Resources res;
private GLSLShader pointLightShader;
private TextureManager tm;

private Object3D plane2;

public MyRenderer() {
Config.farPlane = 2000;
Config.useNormalsFromOBJ = true;
Texture.defaultToMipmapping(true);
Texture.defaultTo4bpp(true);
}

public void onSurfaceChanged(GL10 gl, int w, int h) {
if (fb != null)
fb.dispose();

fb = new FrameBuffer(w, h);

if (master == null) {
world = new World();
res = getResources();
tm = TextureManager.getInstance();

font = new Texture(res.openRawResource(R.raw.numbers));
font.setMipmap(false);

pointLightShader = new GLSLShader(Loader.loadTextFile(res.openRawResource(R.raw.pixel_light_vertex)),
Loader.loadTextFile(res.openRawResource(R.raw.pixel_light_fragment_1)));

loadObjects();

light = new Light(world);
light.setIntensity(50, 50, 50);
light.setPosition(new SimpleVector(0, 0, -10));

Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 3);
cam.lookAt(objects[selectedObject].getTransformedCenter());

world.setAmbientLight(0, 0, 0);
world.compileAllObjects();

renderTarget = new NPOTTexture(fb.getWidth(), fb.getHeight(), null);
tm.addTexture("renderTarget", renderTarget);

renderTarget2 = new NPOTTexture(fb.getWidth(), fb.getHeight(), null);
tm.addTexture("renderTarget2", renderTarget2);

DepthBuffer depthBuffer = new DepthBuffer(fb.getWidth(), fb.getHeight());
renderTarget.setDepthBuffer(depthBuffer);
renderTarget2.setDepthBuffer(depthBuffer);

secWorld = new World();

plane2 = Primitives.getPlane(1, 1.5f);
plane2.build();
plane2.setName("object");
// plane2.setShader(pointLightShader);
plane2.setAdditionalColor(new RGBColor(50, 10, 10));
plane2.setCulling(false);
secWorld.addObject(plane2);
Light light2 = new Light(secWorld);
light2.setIntensity(50, 50, 50);
light2.setPosition(new SimpleVector(3, 3, -10));
secWorld.getCamera().moveCamera(Camera.CAMERA_MOVEOUT, 3);

overlay = new Overlay(secWorld, 0, fb.getHeight(), fb.getWidth(), 0, "renderTarget");
overlay.getObject3D().setCulling(false);
overlay.setDepth(1000);

if (master == null) {
Logger.log("Saving master Activity!");
master = ShaderTest.this;
}
}
}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
Logger.log("onSurfaceCreated");
}

public void loadObjects() {
world.removeAllObjects();

objects = new Object3D[1];
objects[0] = Loader.loadOBJ(res.openRawResource(R.raw.teapot_o), res.openRawResource(R.raw.teapot_m), 1.5f)[0];
// objects[1] = Loader.loadOBJ(res.openRawResource(R.raw.plane_o), res.openRawResource(R.raw.plane_m), 2)[0];
// objects[2] = Loader.loadOBJ(res.openRawResource(R.raw.box_o), res.openRawResource(R.raw.box_m), 2)[0];
// objects[3] = Loader.loadOBJ(res.openRawResource(R.raw.airplane_o), res.openRawResource(R.raw.airplane_m), 0.013f)[0];
// objects[4] = Loader.loadOBJ(res.openRawResource(R.raw.car_o), res.openRawResource(R.raw.car_m), 0.02f)[0];
// objects[5] = Loader.loadOBJ(res.openRawResource(R.raw.car2_o), res.openRawResource(R.raw.car2_m), 0.03f)[0];

for (Object3D object : objects) {
object.setShader(pointLightShader);
object.setAdditionalColor(new RGBColor(10, 50, 10));
}

showObjectIndex(selectedObject);

world.addObjects(objects);
}

public void showObjectIndex(int index) {
for (int i = 0; i < objects.length; i++)
if (i != index)
objects[i].setVisibility(false);
else
objects[i].setVisibility(true);
}

public void onDrawFrame(GL10 gl) {
if (touchTurn != 0) {
objects[selectedObject].rotateY(touchTurn);
plane2.rotateY(-touchTurn);
touchTurn = 0;
}

if (touchTurnUp != 0) {
objects[selectedObject].rotateX(touchTurnUp);
plane2.rotateX(-touchTurnUp);
touchTurnUp = 0;
}

fb.clear();
fb.setRenderTarget(renderTarget);
fb.clear();
world.renderScene(fb);
world.draw(fb);
fb.display();
fb.removeRenderTarget();

fb.setRenderTarget(renderTarget2);
fb.clearColorBufferOnly(RGBColor.BLACK);
if (!useOverlay)
fb.blit(renderTarget, 0, 0, 0, fb.getHeight(), fb.getWidth(), fb.getHeight(), fb.getWidth(), -fb.getHeight(), -1, false,
null);
secWorld.renderScene(fb);
secWorld.draw(fb);
fb.display();
if (clearZBuffer)
fb.clearZBufferOnly();
fb.removeRenderTarget();

fb.blit(renderTarget2, 0, 0, 0, fb.getHeight(), fb.getWidth(), fb.getHeight(), fb.getWidth(), -fb.getHeight(), -1, false, null);

/*
* fb.clear(); world.renderScene(fb); world.draw(fb); secWorld.renderScene(fb); secWorld.draw(fb);
*/

blitNumber(lfps, 5, 5);
fb.display();

try {
Thread.sleep(20);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

if (System.currentTimeMillis() - time >= 1000) {
lfps = fps;
fps = 0;
time = System.currentTimeMillis();
}
fps++;

}

private void blitNumber(float number, int x, int y) {
if (font != null) {
String sNum = Float.toString(number);

for (int i = 0; i < sNum.length(); i++) {
char cNum = sNum.charAt(i);
int iNum = cNum - 48;
fb.blit(font, iNum * 5, 0, x, y, 5, 9, 5, 9, 10, true, null);
x += 5;
}
}
}
}
}
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 15, 2012, 11:25:44 am
...and if i remove the Thread.sleep(20); it's no longer working?
Title: Re: Depth buffer texture
Post by: Thomas. on July 15, 2012, 11:32:14 am
Yes, but wait, I added fb.sync() after every method in onDrawFrame method. Blit of first texture is fine. Overlay is rendered correct, but without depth (the first render is not black as before). Now I'm removing fb.sync() and looking for the best combination.
Title: Re: Depth buffer texture
Post by: Thomas. on July 15, 2012, 11:55:59 am
This is next working combination but only if you use blit method. It feels like a lottery. And it is very slow, just 31fps.

Code: [Select]
public void onDrawFrame(GL10 gl) {
if (touchTurn != 0) {
objects[selectedObject].rotateY(touchTurn);
plane2.rotateY(-touchTurn);
touchTurn = 0;
}

if (touchTurnUp != 0) {
objects[selectedObject].rotateX(touchTurnUp);
plane2.rotateX(-touchTurnUp);
touchTurnUp = 0;
}

fb.clear();
fb.setRenderTarget(renderTarget);
fb.clear();
world.renderScene(fb);
world.draw(fb);
fb.display();
fb.removeRenderTarget();
fb.setRenderTarget(renderTarget2);
fb.clearColorBufferOnly(RGBColor.BLACK);
if (!useOverlay)
fb.blit(renderTarget, 0, 0, 0, fb.getHeight(), fb.getWidth(), fb.getHeight(), fb.getWidth(), -fb.getHeight(), -1, false,
null);
fb.sync(); // if you remove it, clearZBuffer has to be true
secWorld.renderScene(fb);
fb.sync(); // if you remove it, clearZBuffer has to be true
secWorld.draw(fb);
fb.display();
if (clearZBuffer)
fb.clearZBufferOnly();
fb.removeRenderTarget();
fb.blit(renderTarget2, 0, 0, 0, fb.getHeight(), fb.getWidth(), fb.getHeight(), fb.getWidth(), -fb.getHeight(), -1, false, null);

/*
* fb.clear(); world.renderScene(fb); world.draw(fb); secWorld.renderScene(fb); secWorld.draw(fb);
*/

blitNumber(lfps, 5, 5);
fb.display();

/*
* try { Thread.sleep(20); } catch (InterruptedException e) { }
*/

if (System.currentTimeMillis() - time >= 1000) {
lfps = fps;
fps = 0;
time = System.currentTimeMillis();
}
fps++;

}
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 15, 2012, 09:12:00 pm
I've just noticed that sync wasn't exactly doing what it was supposed to be doing. Please re-download and start again by replacing the delay with sync and if that doesn't help...well, you know what to do... ;)

In addition, there's a new flush() method in FrameBuffer. If you managed to get a combination working with sync(), try to replace some of the sync()-calls with flush() and see what happens then.
Title: Re: Depth buffer texture
Post by: Thomas. on July 15, 2012, 09:57:27 pm
I just added sync() after last display() method and blinking is gone :) but only if I use blit method, overlay is still showing black nothing. Replace sync() by flush() returns old problem with blinking... and fps is about 45, without sync() it is 60...

edit: and overlay... it seems, that texture from first rendering is usable, but is not applied on overlay...
By red lines is indicated plane with applied texture from first rendering
(http://s9.postimage.org/8zz2lwlmz/device_2012_07_15_222039.jpg) (http://postimage.org/image/8zz2lwlmz/)
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 16, 2012, 09:35:16 am
I wouldn't care about the Overlay stuff. If it works with blitting, all is well. It's the more efficient way anyway.
sync() makes the cpu wait for the gpu to finish. Usually, this isn't needed for anything but in this case and on this chips, it seems to be.
Title: Re: Depth buffer texture
Post by: Thomas. on July 16, 2012, 11:39:41 am
I don't think, that using sync() is well solution. Just 22 fps with DOF and image post effects. If I turn on DOF only, I have 58 fps, it is render depth buffer, normal scene and render plane with effect (I did optimization of depth texture in comparison with previous results).
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 16, 2012, 12:14:28 pm
It's the only solution as far as i can see. Obviously, your gpu or driver continues rendering the next image based on incomplete data because the former image hasn't been fully processed (and it doesn't notice that) if you omit it. You might want to try to move it up, i.e. do the first renderScene()-call, then do the sync() and then do the clear and the draw and stuff...i'm not sure if that will work though but if it does, it might help to get some parallel processing back.
Title: Re: Depth buffer texture
Post by: Thomas. on July 20, 2012, 05:07:48 pm
Any idea where is problem? I'm using 3 texture layers. When I comment last adding of texture as REPLACE is it fine.

Code: [Select]
Config.maxTextureLayers = 4;

...

ti = new TextureInfo(tm.getTextureID(getTextureName(texture)));
ti.add(tm.getTextureID("PPH_image_buffer_first"), TextureInfo.MODE_ADD);
ti.add(tm.getTextureID("PPH_depth_buffer"), TextureInfo.MODE_REPLACE);
object.setTexture(ti);

Code: [Select]
07-20 16:59:47.446: E/AndroidRuntime(16220): FATAL EXCEPTION: GLThread 1760
07-20 16:59:47.446: E/AndroidRuntime(16220): java.lang.RuntimeException: [ 1342796387234 ] - ERROR: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
07-20 16:59:47.446: E/AndroidRuntime(16220): at com.threed.jpct.GLRenderer.setTextures(GLRenderer.java:2319)
07-20 16:59:47.446: E/AndroidRuntime(16220): at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:2226)
07-20 16:59:47.446: E/AndroidRuntime(16220): at com.threed.jpct.World.draw(World.java:1319)
07-20 16:59:47.446: E/AndroidRuntime(16220): at com.threed.jpct.World.draw(World.java:1081)
07-20 16:59:47.446: E/AndroidRuntime(16220): at cz.chladek.mygame.post_effects.PostEffectsHelper.renderScene(PostEffectsHelper.java:140)
07-20 16:59:47.446: E/AndroidRuntime(16220): at cz.chladek.mygame.AppActivity$MyRenderer.onDrawFrame(AppActivity.java:632)
07-20 16:59:47.446: E/AndroidRuntime(16220): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1462)
07-20 16:59:47.446: E/AndroidRuntime(16220): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
07-20 16:59:47.446: E/AndroidRuntime(16220): at com.threed.jpct.Logger.log(Logger.java:189)
07-20 16:59:47.446: E/AndroidRuntime(16220): at com.threed.jpct.Logger.log(Logger.java:148)
07-20 16:59:47.446: E/AndroidRuntime(16220): at cz.chladek.mygame.AppActivity$MyRenderer.onDrawFrame(AppActivity.java:654)
07-20 16:59:47.446: E/AndroidRuntime(16220): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1462)
07-20 16:59:47.446: E/AndroidRuntime(16220): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 20, 2012, 05:37:38 pm
Try to set Config.maxTextureLayers to a higher value. Default on Android is 2 IIRC. If that helps, i should add a check to that method to provide better feedback than an array out of bounds....
Title: Re: Depth buffer texture
Post by: Thomas. on July 20, 2012, 05:46:52 pm
I set Config.maxTextureLayers to 4 layers and it wrote to me this error. Default wrote, that I have to set higher value...
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 20, 2012, 05:52:33 pm
Has the object been rendered with with less texture layers before?
Title: Re: Depth buffer texture
Post by: Thomas. on July 20, 2012, 06:13:50 pm
No, it was invisible, added to world and at running showed.
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 20, 2012, 08:00:19 pm
That's strange...i've an idea what might cause it, but i'm not sure...i've updated the beta-jar. Could you please download it and give it a try? If it doesn't help, try without calling strip() on the object (in case you are doing that).
Title: Re: Depth buffer texture
Post by: Thomas. on July 20, 2012, 08:19:17 pm
Still crashes... Textures are NPOTTextures, object is created by addTriangle(...) methods, has VertexController and is compiled by compile(true)

this doesn't working:
Code: [Select]
TextureInfo ti = new TextureInfo(tm.getTextureID(getTextureName(texture)));
ti.add(tm.getTextureID("PPH_image_buffer_first"), TextureInfo.MODE_ADD);
ti.add(tm.getTextureID("PPH_depth_buffer"), TextureInfo.MODE_REPLACE); // <- comment this and everything are fine !!!
object.setTexture(ti);
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 20, 2012, 08:28:23 pm
Have you tried to use the TextureInfo in the addTriangle()-call instead? Or at least a TextureInfo with the same number of layers? I think it's not possible to change the number of layers on an already created object that way...
Title: Re: Depth buffer texture
Post by: Thomas. on July 20, 2012, 08:46:33 pm
Original texture layers count is one, increase to two is fine, to three not.  For me will be better, if I can change texture layers during the game for changing details without restart or rebuilding. But I going to try use the TextureInfo in the addTriangle() method tomorrow.
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 20, 2012, 08:49:48 pm
I'll see if i can reproduce this...if two work fine, actually three should do too...
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 20, 2012, 08:52:22 pm
BTW: You have changed the Config-setting before creating the object, have you?
Title: Re: Depth buffer texture
Post by: Thomas. on July 20, 2012, 09:03:33 pm
Yes, in constructor of MyRenderer
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 20, 2012, 09:04:00 pm
I can't reproduce this...if nothing else helps, i need a test case. I did this and it works fine:

Code: [Select]
Object3D test2=new Object3D(10);
test2.addTriangle(new SimpleVector(0,0,0), new SimpleVector(1,0,0), new SimpleVector(0,1,0));
test2.addTriangle(new SimpleVector(0,1,0), new SimpleVector(-1,0,0), new SimpleVector(0,-1,0));
test2.setCulling(false);

TextureInfo ti2=new TextureInfo(TextureManager.getInstance().getTextureID("grassy"));
ti2.add(TextureManager.getInstance().getTextureID("leaves"), TextureInfo.MODE_BLEND);
ti2.add(TextureManager.getInstance().getTextureID("rock"), TextureInfo.MODE_REPLACE);

test2.setTexture(ti2);
Title: Re: Depth buffer texture
Post by: Thomas. on July 21, 2012, 02:47:05 pm
I have no idea, where is problem, I also can't reproduce this. And even stranger is, that object with the TextureInfo is in another World, than the one, that causes the error :-\
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 21, 2012, 03:36:25 pm
...that object with the TextureInfo is in another World, than the one, that causes the error :-\
Makes no sense to me. The crashing part references the texture coordinates of the current object. I don't see any chance how this should happen on some different object... ???
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 21, 2012, 03:44:31 pm
Have you tried without calling strip()?
Title: Re: Depth buffer texture
Post by: Thomas. on July 21, 2012, 04:02:16 pm
Makes no sense to me. The crashing part references the texture coordinates of the current object. I don't see any chance how this should happen on some different object... ???

Me too, I'm looking at the code for three hours and without any result... What exactly do the code in GLRenderer class on 2319 line? For what is the array operation?

I used for ex. this method to create the object
Code: [Select]
addTriangle(new SimpleVector(), 0, 0, new SimpleVector(width, 0, 0), 1, 0, new SimpleVector(0, 0, length), 0, 1);
Have you tried without calling strip()?

I wasn't calling strip() method...
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 21, 2012, 04:08:53 pm
It's this:

Code: [Select]
int tt = obj.multiTex[texInd][number];

It gets the internal texture id for the polygon number at stage texInd. For stripped objects, this array can be [<something>][1], which made me think that you were using a stripped object and jPCT-AE somehow forgot about this and tried to access a higher polygon number...but if you don't strip...
Title: Re: Depth buffer texture
Post by: Thomas. on July 21, 2012, 04:57:59 pm
I checked whole code and strip() is nowhere. I set IRenderHook for all objects in both worlds for writing names of objects. Last displayed object has one texture layer.

This is complete log from rendering. All objects within "water 2" use one texture layer. Object named "water 2" has three texture layers.
Code: [Select]
07-21 16:50:28.884: I/jPCT-AE(4027): NEW FRAME
07-21 16:50:28.889: I/jPCT-AE(4027): Creating render buffer in depth mode!
07-21 16:50:28.919: I/jPCT-AE(4027): Render buffer created: 1
07-21 16:50:28.924: I/jPCT-AE(4027): Cylinder00_jPCT-2
07-21 16:50:28.924: I/jPCT-AE(4027): Creating buffers...
07-21 16:50:28.924: I/jPCT-AE(4027): VBO created for object 'Cylinder00_jPCT-2'
07-21 16:50:28.924: I/jPCT-AE(4027): room02_jPCT19
07-21 16:50:28.924: I/jPCT-AE(4027): Creating buffers...
07-21 16:50:28.924: I/jPCT-AE(4027): VBO created for object 'room02_jPCT19'
07-21 16:50:28.929: I/jPCT-AE(4027): pipe01_jPCT9
07-21 16:50:28.929: I/jPCT-AE(4027): Creating buffers...
07-21 16:50:28.929: I/jPCT-AE(4027): VBO created for object 'pipe01_jPCT9'
07-21 16:50:28.929: I/jPCT-AE(4027): room01_jPCT8
07-21 16:50:28.929: I/jPCT-AE(4027): Creating buffers...
07-21 16:50:28.929: I/jPCT-AE(4027): VBO created for object 'room01_jPCT8'
07-21 16:50:28.929: I/jPCT-AE(4027): Unbinding buffers (1)!
07-21 16:50:28.929: I/jPCT-AE(4027): Using vm based buffer copies!
07-21 16:50:28.929: I/jPCT-AE(4027): Checking for triangle strip...
07-21 16:50:28.929: I/jPCT-AE(4027): Not a triangle strip at position 1!
07-21 16:50:28.929: I/jPCT-AE(4027): Remapping 4 vertex indices!
07-21 16:50:28.929: I/jPCT-AE(4027): Creating vertex cache (96 bytes)!
07-21 16:50:28.929: I/jPCT-AE(4027): Vertex indices will be accessed directly!
07-21 16:50:28.934: I/jPCT-AE(4027): Subobject of object 202/__overlay plane 0__ compiled to indexed fixed point data using 6/6 vertices in 1ms!
07-21 16:50:28.934: I/jPCT-AE(4027): Processing and uploading vertices of subobject of object 202/__overlay plane 0__ took 1ms
07-21 16:50:28.934: I/jPCT-AE(4027): Object 202/__overlay plane 0__ compiled to 1 subobjects in 1ms!
07-21 16:50:28.934: I/jPCT-AE(4027): Checking for triangle strip...
07-21 16:50:28.934: I/jPCT-AE(4027): Not a triangle strip at position 1!
07-21 16:50:28.934: I/jPCT-AE(4027): Remapping 4 vertex indices!
07-21 16:50:28.934: I/jPCT-AE(4027): Creating vertex cache (96 bytes)!
07-21 16:50:28.934: I/jPCT-AE(4027): Vertex indices will be accessed directly!
07-21 16:50:28.934: I/jPCT-AE(4027): Subobject of object 205/__overlay plane 1__ compiled to indexed fixed point data using 6/6 vertices in 1ms!
07-21 16:50:28.934: I/jPCT-AE(4027): Processing and uploading vertices of subobject of object 205/__overlay plane 1__ took 1ms
07-21 16:50:28.934: I/jPCT-AE(4027): Object 205/__overlay plane 1__ compiled to 1 subobjects in 1ms!
07-21 16:50:28.934: I/jPCT-AE(4027): Checking for triangle strip...
07-21 16:50:28.934: I/jPCT-AE(4027): Not a triangle strip at position 1!
07-21 16:50:28.934: I/jPCT-AE(4027): Subobject of object 255/water 2 compiled to indexed fixed point data using 6/4 vertices in 0ms!
07-21 16:50:28.934: I/jPCT-AE(4027): Processing and uploading vertices of subobject of object 255/water 2 took 1ms
07-21 16:50:28.934: I/jPCT-AE(4027): Object 255/water 2 compiled to 1 subobjects in 1ms!
07-21 16:50:28.934: I/jPCT-AE(4027): Processing and uploading vertices of subobject of object 205/__overlay plane 1__ took 0ms
07-21 16:50:28.934: I/jPCT-AE(4027): Compiling shader program!
07-21 16:50:28.939: I/jPCT-AE(4027): Handles of 27: 0/0
07-21 16:50:28.939: I/jPCT-AE(4027): __overlay plane 1__
07-21 16:50:28.939: I/jPCT-AE(4027): Creating buffers...
07-21 16:50:28.939: I/jPCT-AE(4027): VBO created for object '__overlay plane 1__'
07-21 16:50:28.939: I/jPCT-AE(4027): Compiling shader program!
07-21 16:50:28.944: I/jPCT-AE(4027): Handles of 30: 0/0
07-21 16:50:28.944: I/jPCT-AE(4027): water 2 <!!!!!! object with three texture layers !!!!!!
07-21 16:50:28.944: I/jPCT-AE(4027): Creating buffers...
07-21 16:50:28.944: I/jPCT-AE(4027): VBO created for object 'water 2'
07-21 16:50:28.944: I/jPCT-AE(4027): RENDERING IS DONE
07-21 16:50:28.944: I/jPCT-AE(4027): BLIT GUI
07-21 16:50:28.949: I/jPCT-AE(4027): [ 1342882228953 ] - WARNING: Texture's size is 128/64, but textures should be square for OpenGL ES2.0! This may result in a black texture!
07-21 16:50:28.949: I/jPCT-AE(4027): Allocating native memory for 128*64 texture(false/false/false/false/): 32768 bytes!
07-21 16:50:28.949: I/jPCT-AE(4027): New texture's id is: 36
07-21 16:50:28.949: I/jPCT-AE(4027): New texture uploaded: com.threed.jpct.Texture@41c55568 in thread Thread[GLThread 7517,5,main]
07-21 16:50:28.949: I/jPCT-AE(4027): FRAME IS DISPLAYED
07-21 16:50:28.949: I/jPCT-AE(4027): Polygons checked: 154
07-21 16:50:28.949: I/jPCT-AE(4027): NEW FRAME
07-21 16:50:28.954: I/jPCT-AE(4027): Binding buffers (1/1)!
07-21 16:50:28.954: I/jPCT-AE(4027): Cylinder00_jPCT-2
07-21 16:50:28.959: I/jPCT-AE(4027): room02_jPCT19
07-21 16:50:28.959: I/jPCT-AE(4027): pipe01_jPCT9
07-21 16:50:28.959: I/jPCT-AE(4027): Drawing thread terminated!
07-21 16:50:28.964: I/jPCT-AE(4027): [ 1342882228968 ] - ERROR: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
07-21 16:50:28.964: I/jPCT-AE(4027): at com.threed.jpct.GLRenderer.setTextures(GLRenderer.java:2319)
07-21 16:50:28.964: I/jPCT-AE(4027): at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:2226)
07-21 16:50:28.964: I/jPCT-AE(4027): at com.threed.jpct.World.draw(World.java:1319)
07-21 16:50:28.964: I/jPCT-AE(4027): at com.threed.jpct.World.draw(World.java:1081)
07-21 16:50:28.964: I/jPCT-AE(4027): at cz.chladek.mygame.post_effects.PostEffectsHelper.renderScene(PostEffectsHelper.java:150)
07-21 16:50:28.964: I/jPCT-AE(4027): at cz.chladek.mygame.AppActivity$MyRenderer.onDrawFrame(AppActivity.java:566)
07-21 16:50:28.964: I/jPCT-AE(4027): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1462)
07-21 16:50:28.964: I/jPCT-AE(4027): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 21, 2012, 05:36:49 pm
I've updated the beta-jar with a version that catches the exception and prints out some debug info. Please run it and post the debug output.
Title: Re: Depth buffer texture
Post by: Thomas. on July 21, 2012, 05:47:04 pm
Is it what you want? What does it mean? This object has one texture layer.
Code: [Select]
07-21 17:42:30.104: I/jPCT-AE(4981): [ 1342885350109 ] - WARNING: Debug: 3/2/4 - 1/0 - room01_jPCT8/220 - com.threed.jpct.World@418a79c8
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 21, 2012, 06:00:11 pm
That output means:

Currently, 3 texture stages are active (that seems reasonable, because you have rendered an object with 3 stages before). 4 is max (as reported by the driver) and the object uses 2...the rest doesn't help here. The code expects each object that use multi-texturing to have the maximum number of stages (4 in this case) even if they aren't used. This doesn't seem to be the case here...and i've no idea why, but i'll try to fix it anyway.
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 21, 2012, 06:06:27 pm
I've updated the beta jar. Please check it out to see if that helps.
Title: Re: Depth buffer texture
Post by: Thomas. on July 21, 2012, 06:15:03 pm
Yes, now it is fine ;) ... How is it possible, that you didn't get this error before? (if you use 4 layers for terrain and probably one for everything else)
Title: Re: Depth buffer texture
Post by: EgonOlsen on July 21, 2012, 07:21:44 pm
How is it possible, that you didn't get this error before? (if you use 4 layers for terrain and probably one for everything else)
It can only happen if you create objects using different settings for Config.maxTextureLayers. If you set it before creating any other object, it won't show up.
Title: Re: Depth buffer texture
Post by: Thomas. on October 09, 2012, 06:29:45 pm
I have problem with render targets performance. I have two main textures into which I render and swapping among them and one additional for depth. For ex. I want to render scene with image distortions and DOF. I render depth into "depth" texture, scene into "texture1", after is rendered image distortion into "texture2" by using "depth" and "texture1", after is rendered DOF into "texture1" by using "depth" and "texture2". If is rendered scene with DOF only - 60fps, scene with image distortion only - 60 fps, scene with DOF and distortion (all distortion objects are out off viewing frustum) - 47fps! So only one additional blitting rendered into texture takes 13 fps...

And second question. I render depth without particles, after same scene in normal way. Javadoc says, here is done all transforms, so it is same for both rendering. Is possible to modify FrameBuffer.renderScene(...), to I could skip second renderScene(...) method?
Title: Re: Depth buffer texture
Post by: EgonOlsen on October 09, 2012, 08:31:38 pm
The issue that caused jPCT-AE to slow down when using multiple render targets is long gone...i don't see any reason inside the engine for this. IMHO, your "calculations" are misleading...60fps is the device cap anyway, so if you, for example, can render each pass in 10ms, each will be able to output 100fps, i.e. 60fps with the cap. Both combined will take 20ms, i.e. you'll get 50fps as a result. I don't see the actual issue here... ???

About the second question: Please elaborate a bit more on this...i don't get what "skip second renderScene()" means in this context!?