Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (542)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (604)
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  
  Shaders & Programs - validation, info log...  (Read 1663 times)
0 Members and 1 Guest are viewing this topic.
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Posted 2014-01-31 19:01:12 »

I've always set up shaders like so:
1  
2  
3  
4  
5  
6  
7  
handle = GL.glCreateShader(type);
     
GL.glShaderSource(handle, source);      
     
GL.glCompileShader(handle);
if (GL.glGetShaderiv(handle, ShaderState.COMPILE_STATUS) == GL.FALSE)
   throw new OpenGLException("Error compiling shader: " + handle);

And I've always set up program objects like so:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
handle = GL.glCreateProgram();

for (ShaderObject shaderObj : shaderObjs)
   GL.glAttachShader(handle, shaderObj.getHandle());

GL.glLinkProgram(handle);
if (GL.glGetProgramiv(handle, ProgramState.LINK_STATUS) == GL.FALSE)
   throw new OpenGLException("Error linking program: " + handle);

for (ShaderObject shaderObj : shaderObjs)
   GL.glDetachShader(handle, shaderObj.getHandle());

I'm not exactly sure what else I should do; I've previously seen the use of glValidateProgram and checking that the program is validated. However, I'm not sure if it's necessary. If it's compiled and linked successfully, won't that mean that it's validated for use? Also I've known about the use of info-logs and I'm not exactly sure how I should use them and what to use them for. On top of that, is there anything else I should known about?

Oh and I nearly forgot, should I always detach shader objects from the program after the program is linked? Is there any reason that you'd keep them attached?

Why are all OpenGL tutorials written in Brainf**k?
Offline opiop65

JGO Kernel


Medals: 161
Projects: 7
Exp: 4 years


JumpButton Studios


« Reply #1 - Posted 2014-01-31 19:33:04 »

Yes, you should detach the objects. There's no need to keep them around after the shader program is compiled.

Offline HeroesGraveDev

JGO Kernel


Medals: 325
Projects: 11
Exp: 3 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #2 - Posted 2014-01-31 19:33:16 »

Info logs are useful for finding errors in your shaders.

Not using them is like having a compiler with no output. You can use it perfectly fine, but if you have an error, it's a nightmare to track down.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #3 - Posted 2014-01-31 19:36:07 »

How about validation, and how should I use info logs?

Why are all OpenGL tutorials written in Brainf**k?
Offline HeroesGraveDev

JGO Kernel


Medals: 325
Projects: 11
Exp: 3 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #4 - Posted 2014-01-31 20:46:46 »

I'm a bit busy so I can't give you Java code, but here's some snippets from my Rust libraries:

Shaders:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
let shader = gl::CreateShader(ty);
unsafe
{
    // Compile shader
    src.with_c_str(|ptr| gl::ShaderSource(shader, 1, &ptr, ptr::null()));

    // Error Checking
    gl::CompileShader(shader);
   
    let mut status = gl::FALSE as GLint;
    gl::GetShaderiv(shader, gl::COMPILE_STATUS, &mut status);
   
    if status != (gl::TRUE as GLint)
    {
        /*The following calculates the length of the log so I can pass an appropriately sized buffer.
LWJGL should let you skip this part*/

        let mut len = 0;
        gl::GetShaderiv(shader, gl::INFO_LOG_LENGTH, &mut len);
        let mut buf = vec::from_elem(len as uint - 1, 0u8);
        gl::GetShaderInfoLog(shader, len, ptr::mut_null(), buf.as_mut_ptr() as *mut GLchar);
        fail!("Error compiling shader:\n{}\n", str::raw::from_utf8(buf));
    }
}


Programs:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
let program = gl::CreateProgram();

gl::AttachShader(program, vs);
gl::AttachShader(program, fs);

gl::LinkProgram(program);

gl::DeleteShader(vs);
gl::DeleteShader(fs);
// Error Checking
unsafe
{
    let mut status = gl::FALSE as GLint;
    gl::GetProgramiv(program, gl::LINK_STATUS, &mut status);
   
    if status != (gl::TRUE as GLint)
    {
        /*The following calculates the length of the log so I can pass an appropriately sized buffer.
LWJGL should let you skip this part*/

        let mut len: GLint = 0;
        gl::GetProgramiv(program, gl::INFO_LOG_LENGTH, &mut len);
        let mut buf = vec::from_elem(len as uint - 1, 0u8);
        gl::GetProgramInfoLog(program, len, ptr::mut_null(), buf.as_mut_ptr() as *mut GLchar);
        fail!("Error linking shader program:\n{}\n", str::raw::from_utf8(buf));
    }
}


Hopefully you can convert it to Java code easily enough. LWJGL versions should be a bit simpler.

Offline Danny02
« Reply #5 - Posted 2014-01-31 21:46:45 »

I do similar things, compiling and checking for errors. I also do parse the error text to get the offending line in the shader, problem is of course that there are differences between Nvidia AMD ...

I also just read that one can speed up shader compilation by allowing the driver to do it in parallel.
Offline Gef
« Reply #6 - Posted 2014-02-01 02:55:54 »

This is a pastebin of a complete class that I'm using to manage (load, validate...) a shader, if you want to compare. You will find infolog by example.
I'm sorry comments are in french Shocked, (if needed, I can translate !)

Offline theagentd

« JGO Bitwise Duke »


Medals: 366
Projects: 2
Exp: 8 years



« Reply #7 - Posted 2014-02-01 15:47:41 »

I do similar things, compiling and checking for errors. I also do parse the error text to get the offending line in the shader, problem is of course that there are differences between Nvidia AMD ...

I also just read that one can speed up shader compilation by allowing the driver to do it in parallel.
Don't forget Intel. Using arrays with the Intel GLSL compiler is a nightmare.

The parallel compiling and linking code is just a concept. If you were to compile and link your shader/shader programs but don't query the compilation results or do anything that requires the compilation to complete (query uniforms and attributes), IN THEORY the driver could compile the GLSL shader in a separate thread and the driver would only need to block if the compilation wasn't complete by the first time the shader is actually needed. I'm not aware of any driver that actually does that in the first place, and I doubt the gains would noticeable when you compare shader compilation to texture loading and 3D model loading in an actual game. It might also make debugging shaders slightly harder since a compilation error would not be detected until the shader was actually used, which could leave a bug in a rarely used shader to explode to some unfortunate user. Well, not likely, but still.

Myomyomyo.
Offline davedes
« Reply #8 - Posted 2014-02-01 16:32:31 »

I haven't seen too many uses for glValidateProgram, since you can just try to compile and see the error logs. There are some issues with Macs and NVIDIA cards around validating:
https://bugzilla.mozilla.org/show_bug.cgi?id=657201
https://bugzilla.mozilla.org/show_bug.cgi?id=593867

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.

BurntPizza (15 views)
2014-12-27 22:38:51

Mr.CodeIt (13 views)
2014-12-27 04:03:04

TheDudeFromCI (17 views)
2014-12-27 02:14:49

Mr.CodeIt (25 views)
2014-12-23 03:34:11

rwatson462 (56 views)
2014-12-15 09:26:44

Mr.CodeIt (46 views)
2014-12-14 19:50:38

BurntPizza (92 views)
2014-12-09 22:41:13

BurntPizza (113 views)
2014-12-08 04:46:31

JscottyBieshaar (86 views)
2014-12-05 12:39:02

SHC (97 views)
2014-12-03 16:27:13
How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!