assign a GL texture to an Object3D

Started by raft, January 23, 2014, 03:20:53 PM

Previous topic - Next topic

raft

is it possible to assign an Object3D a GL texture which is created outside of jPCT?

with this code i can create a special texture to which i can redirect Android's Camera or MediaPlayer output, kind of render to texture. if i can assign that texture to an Object3d, i can play perspectively correct videos inside jPCT world.

is it possible?

EgonOlsen

#1
Not by default, but it might be if i would expose the GL id of a texture. It would be 100% up to you then to setup the texture, manage context changes and such. I'll look into it.

raft


EgonOlsen

Ok, here you go: http://jpct.de/download/beta/jpct_ae.jar...i've no idea if this works, it's 100% untested. I've added a method


Texture.setExternalId(<int>);


In your case, that would be the value that


GLES20.glGenTextures(1, textures, 0);


returns. Setting this value should override everything else, i.e. the renderer will use this id regardless of the current context or if it exists or not. So it's up to you to keep this id fresh. Other settings on the texture like mip mapping, compression etc. will have no effect anymore.

Please let me know if it works or not.

raft

thanks :)

well, i have a view. for a fast start, i first tried to redirect camera view to texture. below is a screenshot. an UV adjustment was needed since as can be expected the created texture has a 2^n size.



the camera view on the back is a texture blitted by jPCT. the debug text in black is part of the texture (printed by OpenCV before image is converted to texture) so it's also blitted.

the red rectangles, axes arrows and and the plane are all 3d objects in jPCT world. the plane uses the new external texture so it also displays the camera view.

the weird thing is, plane also displays the debug text. i cant understand how and why :o

also I had a repeating GL error 0x502 at SurfaceTexture.updateTexImage() in logs. after some googling I've found this is caused by an error happening before SurfaceTexture.updateTexImage(). so I call before updateTexImage:

int error = GLES20.glGetError();
if (error != 0) {
    System.out.println("GL error " + error + ": " + GLU.gluErrorString(error));
}


and got:

GL error 1282: invalid operation

if I dont assign this texture to plane but still call SurfaceTexture.updateTexImage(), the error goes away. i cant see inside of updateTexImage since it's a native method.

any ideas?

raft

i've skipped blitting generated camera texture to back of the scene and the result is as below:



this is the texture generated by GLFont. if i skip using GLFont the plane uses the texture of axis arrows. in short seems as plane uses the last texture used.

should I use this external texture like a regular texture? or should i activate it with something like:

GL10.glBindTexture(..)

raft

and as a reminder, this is not a regular texture but an external texture, maybe that requires special processing?

EgonOlsen

That might be an indicator that the ID that you've set as external texture id is not (or no longer) valid. There shouldn't be any need to do some special treatment. It will harm more than it helps.

EgonOlsen

At which stage, i.e. in which GL context are you creating the external texture?

raft

argh :-[ you're right. texture was never initialized.

after fixing that, and forcibly switching to GL 2, same error code is detected and thrown by jPCT. this happens just after the plane is created and added to world.

FATAL EXCEPTION: GLThread 52706
java.lang.RuntimeException: [ 1390575883177 ] - ERROR: before: glError 1282
        at com.threed.jpct.Logger.log(Logger.java:193)
        at com.threed.jpct.GL20.checkError(GL20.java:152)
        at com.threed.jpct.GL20.glGenBuffers(GL20.java:1362)
        at com.threed.jpct.CompiledInstance.compileToVBO(CompiledInstance.java:1455)
        at com.threed.jpct.CompiledInstance.render(CompiledInstance.java:593)
        at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:2289)
        at com.threed.jpct.World.draw(World.java:1361)
        at com.threed.jpct.World.draw(World.java:1099)


Quote from: EgonOlsen on January 24, 2014, 04:10:05 PM
At which stage, i.e. in which GL context are you creating the external texture?
at onSurfaceCreated(..) method

raft

Quoteat onSurfaceCreated(..) method
this is where the shaders are compiled and glGenTextures is called. the plane and external jPCT texture is created later in UI-Thread, not in the GL-thread.

raft

same happens when plane and texture is created in GL-thread

EgonOlsen

jPCT just detects the error at that stage. It might or might not have caused it itself. It might be a problem with the current GL state. You have to make sure that after setting up the texture, the state is 'clean' i.e. it should be like as if you have never done anything to it.

EgonOlsen

Quote from: raft on January 24, 2014, 03:18:36 PM
and as a reminder, this is not a regular texture but an external texture, maybe that requires special processing?
I'm not sure about this...as long you can bind it in a normal way and as long as a shader can access it in a normal way, i don't see why that should be a problem.

EgonOlsen

Have you checked what actually causes this error? The problem with gl errors is that they persist until somebody reads them. They might have happened waaaaay before they surface. You can only be sure if you check for a gl error after each and every gl call.