Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 23

Thread: Modern GLSL style

  1. #11
    Super Moderator Frequent Contributor Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    936
    lol, +1 on the popcorns.

  2. #12
    Advanced Member Frequent Contributor
    Join Date
    Jan 2007
    Posts
    964
    Just for the OP's info, here are the worthwhile features that should be added to GLSL:


    • Explicit uniform locations.
      Yes, UBOs go a long way here, but sometimes all you want to do is just set a single vec4. GLSL has had explicit attribute locations for ages, why not for uniforms too? This isn't a hardware limitation (HLSL could always let you set ": register(c0)" for example), it's a design flaw. Add "layout (location=" qualifiers to uniform declarations.
    • Default values allowed for sampler uniforms.
      This is daft - why can't you declare "uniform sampler2D myTexture = 3;" and then just bind the texture object to GL_TEXTURE3 without having to query the uniform location and set it's value after compilation? Sure, it's a one-time-only op, but it just needlessly adds to the boilerplate supporting infrastructure you must write before you can actually start doing interesting and fun things.
    • User-specified entry-points.
      Again, it's daft that you must always use main () as your entry-point for every shader. If you have many shaders that all share the same inputs, outputs and uniforms, you might want to combine them all into a single source file. Same with shared subroutines. YES Alfonse, I know about the const GLchar ** param to glShaderSource, but that means having to split your shader sources across multiple files, load and verify each file individually, and build up the array each time. A new version of glShaderSource that accepts a const GLchar *entrypoint param.


    Something of a personal wish-list I admit, but get this stuff fixed and then maybe we can start talking about bolting on OOP pretties.

  3. #13
    Intern Contributor
    Join Date
    May 2012
    Posts
    98
    Understood. Then what I was asking for is somehow can be accomplished with performance penalty using something like OpenCL or CUDA...

  4. #14
    Member Regular Contributor
    Join Date
    Mar 2001
    Posts
    466
    Quote Originally Posted by mhagain View Post
    Just for the OP's info, here are the worthwhile features that should be added to GLSL:


    • Explicit uniform locations.
      Yes, UBOs go a long way here, but sometimes all you want to do is just set a single vec4. GLSL has had explicit attribute locations for ages, why not for uniforms too? This isn't a hardware limitation (HLSL could always let you set ": register(c0)" for example), it's a design flaw. Add "layout (location=" qualifiers to uniform declarations.
    • Default values allowed for sampler uniforms.
      This is daft - why can't you declare "uniform sampler2D myTexture = 3;" and then just bind the texture object to GL_TEXTURE3 without having to query the uniform location and set it's value after compilation? Sure, it's a one-time-only op, but it just needlessly adds to the boilerplate supporting infrastructure you must write before you can actually start doing interesting and fun things.
    • User-specified entry-points.
      Again, it's daft that you must always use main () as your entry-point for every shader. If you have many shaders that all share the same inputs, outputs and uniforms, you might want to combine them all into a single source file. Same with shared subroutines. YES Alfonse, I know about the const GLchar ** param to glShaderSource, but that means having to split your shader sources across multiple files, load and verify each file individually, and build up the array each time. A new version of glShaderSource that accepts a const GLchar *entrypoint param.


    Something of a personal wish-list I admit, but get this stuff fixed and then maybe we can start talking about bolting on OOP pretties.
    For point 3, just prefix your shader code with "#define phong_fragment_shader main" as a workaround.

  5. #15
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,714
    Default values allowed for sampler uniforms.
    This is daft - why can't you declare "uniform sampler2D myTexture = 3;" and then just bind the texture object to GL_TEXTURE3 without having to query the uniform location and set it's value after compilation? Sure, it's a one-time-only op, but it just needlessly adds to the boilerplate supporting infrastructure you must write before you can actually start doing interesting and fun things.
    We already have that. Welcome to 2011; glad you could make it.

  6. #16
    Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Germany
    Posts
    289
    Quote Originally Posted by mhagain View Post
    Just for the OP's info, here are the worthwhile features that should be added to GLSL:


    • ...
    • Default values allowed for sampler uniforms.
      This is daft - why can't you declare "uniform sampler2D myTexture = 3;" and then just bind the texture object to GL_TEXTURE3 without having to query the uniform location and set it's value after compilation? Sure, it's a one-time-only op, but it just needlessly adds to the boilerplate supporting infrastructure you must write before you can actually start doing interesting and fun things.
    • ...
    Code :
    layout(binding = 3) uniform sampler2D myTexture;
    is already valid since OpenGL 4.2.

    edit: Alfonses post just appeared here. sorry for the double post then...

  7. #17
    Advanced Member Frequent Contributor
    Join Date
    Jan 2007
    Posts
    964
    Granted that; not up to speed with the full 4.2 spec.

  8. #18
    Junior Member Regular Contributor
    Join Date
    Apr 2004
    Posts
    205
    Quote Originally Posted by mhagain View Post
    Just for the OP's info, here are the worthwhile features that should be added to GLSL:


    • Explicit uniform locations.
      Yes, UBOs go a long way here, but sometimes all you want to do is just set a single vec4. GLSL has had explicit attribute locations for ages, why not for uniforms too? This isn't a hardware limitation (HLSL could always let you set ": register(c0)" for example), it's a design flaw. Add "layout (location=" qualifiers to uniform declarations.
    • Default values allowed for sampler uniforms.
      This is daft - why can't you declare "uniform sampler2D myTexture = 3;" and then just bind the texture object to GL_TEXTURE3 without having to query the uniform location and set it's value after compilation? Sure, it's a one-time-only op, but it just needlessly adds to the boilerplate supporting infrastructure you must write before you can actually start doing interesting and fun things.
    • User-specified entry-points.
      Again, it's daft that you must always use main () as your entry-point for every shader. If you have many shaders that all share the same inputs, outputs and uniforms, you might want to combine them all into a single source file. Same with shared subroutines. YES Alfonse, I know about the const GLchar ** param to glShaderSource, but that means having to split your shader sources across multiple files, load and verify each file individually, and build up the array each time. A new version of glShaderSource that accepts a const GLchar *entrypoint param.


    Something of a personal wish-list I admit, but get this stuff fixed and then maybe we can start talking about bolting on OOP pretties.
    I would like to see support for #include too. this means you must be able to specify a callback function to be called on each #include which will fetch the included file's text to the GLSL compiler.
    currently, if you want to use includes, you have to run your own preprocessor beforehand.

  9. #19
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882
    Quote Originally Posted by l_belev View Post
    I would like to see support for #include too. this means you must be able to specify a callback function to be called on each #include which will fetch the included file's text to the GLSL compiler.
    currently, if you want to use includes, you have to run your own preprocessor beforehand.
    An slightly better solution for this is what Cg supports. It provides APIs for you to give it the text content of included files beforehand (cgSetCompilerIncludeString) as well as a callback (as you describe) to be called if a #include is seen for a file you haven't given it already (cgSetCompilerIncludeCallback).

    As a side-note, it also provides cgSetCompilerIncludeFile, where you can provide a disk pathname to the content for a specific include file (instead of the already-loaded content string directly), but GL wouldn't want to support that (since GL doesn't access the filesystem. the server may be running on a completely different host than the client.).

    In fact, if we had this (#include support) as well as what I describe here (i.e. using const values and normal GLSL conditional expressions to define "shader permutations", and having the compiler automatically cut-away unreachable code), I think that'd totally eliminate my needs for "sprintf"ing of GLSL shaders together (which is necessary now).
    Last edited by Dark Photon; 07-16-2012 at 08:16 AM.

  10. #20
    Junior Member Regular Contributor malexander's Avatar
    Join Date
    Aug 2009
    Location
    Ontario
    Posts
    246
    I would like to see support for #include too. this means you must be able to specify a callback function to be called on each #include which will fetch the included file's text to the GLSL compiler.
    There is http://www.opengl.org/registry/specs...ge_include.txt, though the developer is responsible for loading the include files themselves and linking the file to the contents in GL. I haven't used it myself though, as we have a preprocessor class in our project.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •