Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  JOGL Texture API, multiple texture units, & GLSL Samplers  (Read 2811 times)
0 Members and 1 Guest are viewing this topic.
Offline AI Guy

Senior Newbie





« Posted 2007-11-15 21:10:22 »

I am doing a number of things, which by themselves I can find examples for, but I am not sure how they fit together combined.  Here is some psuedo code.  Is this how to fit it all?  Thanks in advance.

TextureData td0 = new TextureData(...);
TextureData td1 = new TextureData(...);
Texture tex0;
Texture tex1;
int loc0;
int loc1;


later in GLEventListener init():
tex0 = TextureIO.newTexture(td0);
tex0.enable();
tex1 = TextureIO.newTexture(td1);
tex1.enable();

compile & linking code for programObject

loc0 = gl.glGetUniformLocationARB(programObject, "db_table");
loc1 = gl.glGetUniformLocationARB(programObject, "db_index");


in Display():
glActiveTexture(GL.GL_TEXTURE0);
tex0.bind();
gl.glUniform1iARB(loc0, 0);

glActiveTexture(GL.GL_TEXTURE1);
tex1.bind();
gl.glUniform1iARB(loc1, 1);

gl.glUseProgramObjectARB(programObject);

gl.glBegin(GL.GL_QUADS);
...
gl.glEnd();


In the shader itself:
uniform sampler2D db_table;
uniform sampler2D db_index;

void main(){...}
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #1 - Posted 2007-11-15 22:06:55 »

I think you need the Texture.enable() calls after the glActiveTexture() calls in addition to the Texture.bind()s, so that you enable each of the texture units.
Offline Chris61182

Junior Duke





« Reply #2 - Posted 2007-11-15 22:57:13 »

I think you need the Texture.enable() calls after the glActiveTexture() calls in addition to the Texture.bind()s, so that you enable each of the texture units.

I'm not 100% certain, but I'm fairly sure that you don't need to call glEnable(GL_TEXTURE_nD) when using GLSL. It's just a remnant from controlling the various units when using stuff like the original fixed function pipeline and arb_texture_env_combine and the likes.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Chris61182

Junior Duke





« Reply #3 - Posted 2007-11-15 22:58:31 »

Oh and to the original poster, as far as I can see everything looks pretty good. The only suggestion I'd make is that if your texture units don't change, set the uniform variables in the init() function.
Offline AI Guy

Senior Newbie





« Reply #4 - Posted 2007-11-15 23:16:00 »

Thanks guys:

It is going to be days before I can get all the parts together to try this.  Really needed to know I was on the right track.  Will report back when up & running.

Chris, your 2 comments are exactly what I was thinking.  I have even seen a GLSL example with all these glTexParameteri() calls, and I am wondering why?  Same with the enable().  I thought my glUseProgramObjectARB() call was my enable(), but was afraid not to put at least 1 in init() anyway.  If OpenGL is a state system, then I should be able to set my uniforms in init(), if they are not going to change.

But never actually building one of these before, I was kind of gun shy to try, when GLSL posts have this stuff.
Offline Chris61182

Junior Duke





« Reply #5 - Posted 2007-11-15 23:48:20 »

I have even seen a GLSL example with all these glTexParameteri() calls, and I am wondering why?

I hope you mean glTexEnv() calls. The glTexParameter() calls are going to stick around for a fair while longer, as texture addressing and filtering are two operations which specialized hardware give an order of magnitude or more speedup for.

Now hopefully GL 3.0 will clear up a lot of the confusion and ambiguity that a couple of decades of legacy has left in the spec.
Offline AI Guy

Senior Newbie





« Reply #6 - Posted 2007-11-16 17:47:23 »

I did mean and see glTexParameteri()  calls in a fragment GLSL example called "helloGPGPU for JOGL".  Strange URL, since japanese.

http://m-forest.ddo.jp/wiki_college/wiki.cgi?page=%A5%B7%A5%A7%A1%BC%A5%C0(GLSL)%A4%CE%A5%B5%A5%F3%A5%D7%A5%EB%A5%D7%A5%ED%A5%B0%A5%E9%A5%E0

I was only implying that I thought glTexParameteri() calls were un-neccessary & ignored (unless being use to set the textures priority) when a fragment shader, itself, directly addressed the texture with texture*D() calls.  They can exist forever for fixed pipeline rendering for all I care, but it is confusing seeing examples like this.

My assumptions about un-neccessary & ignored are correct, right?
Offline AI Guy

Senior Newbie





« Reply #7 - Posted 2007-11-16 18:14:26 »

After I hit the Post button, I thought I could have just commented them out and see what happens, so I did.  With them a teapot is surrounded by loops with some visual garbage at the top shows, which I assumed was the real output.  Comment them out and you just get white.

So, does it not work because the shader needs it, or is it because of this pointless teapot?  My psuedo code example of a database table and index seem infinitely better as a GPGPU helloworld example.
Offline Chris61182

Junior Duke





« Reply #8 - Posted 2007-11-16 20:50:01 »

I did mean and see glTexParameteri()  calls in a fragment GLSL example called "helloGPGPU for JOGL".  Strange URL, since japanese.

http://m-forest.ddo.jp/wiki_college/wiki.cgi?page=%A5%B7%A5%A7%A1%BC%A5%C0(GLSL)%A4%CE%A5%B5%A5%F3%A5%D7%A5%EB%A5%D7%A5%ED%A5%B0%A5%E9%A5%E0

I was only implying that I thought glTexParameteri() calls were un-neccessary & ignored (unless being use to set the textures priority) when a fragment shader, itself, directly addressed the texture with texture*D() calls.  They can exist forever for fixed pipeline rendering for all I care, but it is confusing seeing examples like this.

My assumptions about un-neccessary & ignored are correct, right?

1  
2  
3  
4  
drawable.getGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); 
drawable.getGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
drawable.getGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
drawable.getGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP);


I guess you could actually state that they are unnecessary as you can duplicate the effects in the shader, though you wouldn't want to. Additionally they are not ignored, with the possible exception of the priority (the driver and OS tend to think they know better than the app these days).

To duplicate setting the filter to GL_LINEAR you would have to make 4 texture*D() calls, compute the weight and then perform the interpolation yourself. Where as setting glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); sets-up the hardware to perform this operation for you in a single texture*D() call and does all the weight computation and interpolation effectively for free. Things get even uglier when you start to take mipmapping (GL_LINEAR_MIPMAP_LINEAR) into account, the number of interpolations increases, and an lod is needed. And all of that only takes into account the arithmetic of doing texture filtering, the hardware also does some nifty things with caching and prefetching that makes doing those operations in the shader a not so terribly fantastic idea.

As for the wrap s and t modes, that might not cost much performance to do in the shader, but the hardware to implement that is also quite tiny and doesn't cost much.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (66 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!