Precision qualifier throws an error for OpenGL 3.0 under Mesa 9.2.1

久未见 提交于 2019-12-08 01:20:43

问题


A strange issue with OpenGL 3.0 under Mesa 9.2.1 on Ubuntu 13.10 (64-bit) is observed. Variable definition with explicit precision (like this: highp vec2 v;) produces an error:

syntax error, unexpected VEC2, expecting ',' or ';'

It seems like precision qualifier is disabled there for some reasons. Mesa Release Notes doesn't clear the situation -- not bugs, nor notifications are relative to the topic.

P.S. with OpenGL ES 3.0 precision qualifier works correctly.


回答1:


Make sure you specify #version 130.

Without a #version directive OpenGL will default to #version 110 where precision qualifiers are most certainly not valid.

P.S. with OpenGL ES 3.0 precision qualifier works correctly.

Unsurprising. Precision qualifiers work in both OpenGL ES GLSL #versions.




回答2:


highp is actually undefined in fragment shaders by default, so it really comes as no surprise that this generates a parse error.

I feel like a broken record, but the proper way to use highp in a fragment shader is to first check for the pre-processor definition: GL_FRAGMENT_PRECISION_HIGH. This pre-processor definition is defined in all stages since you need to know when outputting something in a vertex shader whether the fragment shader will support highp.

Consider the following GLSL snippet:

#ifdef GL_FRAGMENT_PRECISION_HIGH
# define maxfragp highp
#else
# define maxfragp medp
#endif

Since you need to match precision between vertex and fragment shaders for I/O, you might use something like this (for both the fragment and vertex shader):

maxfragp varying vec2 tex_st;

Vertex shaders always support highp, by the way. This only applies to fragment shaders.


With that out of the way, you should be aware that in desktop GLSL, while version 1.30 defines precision qualifiers they do not actually do anything. They are there simply to make porting shaders from GLSL ES easier.

The OpenGL Shading Language (Version 1.3) - 4.5 Precision Qualifiers - pp. 35

Precision qualifiers are added for code portability with OpenGL ES, not for functionality. They have the same syntax as in OpenGL ES, as described below, but they have no semantic meaning, which includes no effect on the precision used to store or operate on variables.

If an extension adds in the same semantics and functionality in the OpenGL ES 2.0 specification for precision qualifiers, then the extension is allowed to reuse the keywords below for that purpose.

  

The only types of precision desktop GLSL deals with are single- and double-precision (GL 4.0+ / ARB_gpu_shader_fp64) floating-point. And these variables are distinguished using different data types (e.g. dvec2 vs. vec2) rather than a precision qualifier.



来源:https://stackoverflow.com/questions/20126918/precision-qualifier-throws-an-error-for-opengl-3-0-under-mesa-9-2-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!