Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Precision identifiers in GLSL Fragment shader code generate errors

Precision identifiers in GLSL Fragment shader code generate errors

Scheduled Pinned Locked Moved Game Development
2 Posts 2 Posters 4.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Ferobles92
    wrote on last edited by
    #1

    Hello all,

    I am developing an application using the QWindow. In doing so, I started learning OpenGL ES 2.0. I have been learning about shaders and precision. I have the following code for a fragment shader:

    @
    #ifdef GL_FRAGMENT_PRECISION_HIGH
    precision highp float;
    #else
    precision mediump float;
    #endif

    varying vec4 color;
    void main()
    {
    gl_FragColor = color;
    }
    @

    I get the following error when I compile this shader code:

    QOpenGLShader::compile(Fragment): ERROR: 0:7: 'precision' : syntax error syntax error

    Can anyone explain why? According to a book on this type of OpenGL, that is valid code (as a matter of fact, I am borrowing from that book).

    Thanks in advance.

    1 Reply Last reply
    0
    • slettaS Offline
      slettaS Offline
      sletta
      wrote on last edited by
      #2

      Be aware of that QOpenGLShader will insert

      @#define highp
      #define mediump
      #define lowp@

      at the top of your glsl code when you are compiling for desktop. And on desktop, 'precision' is not a valid token until one of the later versions (exactly which one I can't remember right now).

      So based on that, I'd say that you are compiling for desktop and it fails on line 4 (7 - 3 inserted lines) of your code because 'precision' is not a valid keyword.

      QOpenGLShaderProgram tries to help in this regard by defining the precision specifiers to empty on desktop, so if you change your code to:

      @lowp varying vec4 color;
      void main() {
      gl_FragColor = color;
      }@

      it will compile for both desktop and es.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved