Login  Register

Re: Can someone go over the mechanics of rendering shaders and texture objects

Posted by elect on Feb 12, 2016; 1:59pm
URL: https://forum.jogamp.org/Can-someone-go-over-the-mechanics-of-rendering-shaders-and-texture-objects-tp4036186p4036189.html

ElvJOGL wrote
I hope you don't mind @elect I forked you helloTriangle project.

I will read on it as much as possible.

Thank you.
How dare you...


I can only be happy, cmon


ElvJOGL wrote
But one question, for rendering a model one only calls the shaders and the texture binding once right? and then just continue displaying the image.
there is no shader binding and the texture has to be bound at the creation/generation of the texture itself and everytime you want to execute a draw call where the texture has to rendered, that is the texture is one of the inputs

ElvJOGL wrote
Or the shaders and texture binding continue to happen as much as you continue to render the model?
I guess I got it what you mean, Opengl is a state machine, so when you render you have n states, each of them with a specific value bound/set.

This means, if you are about to execute a drawing call to render the texture Wall, that Wall texture has to be bound. If later you render just pure geometry without any texture, you can leave wall bound, it won't interfere

In general all the calls that reset states to 0, such as

gl4.glBindBuffer(GL4.GL_ARRAY_BUFFER, 0);

gl4.glBindVertexArray(0);

and so on, are totally useless by a practical point of view, and harmful by a performance one..

The only important 0 call is

gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);

in case you are done rendering one a framebuffer you created and you want to switch back the default one

ElvJOGL wrote
In other words, does calling the shader to compile and binding it to the program and running the program as well for the texture, does that happen in the Init(GLAutoDrawable) method and then the transformation of the viewport happens in the render(...) method?
I am not sure what you mean..

init() is called once at begin, then there is a reshape(), then all displays(), unless you resize the window -> reshape() or close it -> dispose()

in the init you create the shaders, and the program, add the shaders to the program and compile it. Once compiled it can be used to render.
If you have any texture, you have to init it just once, when you need it during runtime or at the startup of your program, depending on your needs.

the viewport, normally, should be performed in the reshape() since it affects the window space/image

the transformation of the matrices, mvp, usually at the begin of the the display or, if you don't change them, do it once and then again once one of them get dirty