OpenGL ES 3.2 doesn't recognize gl_in in geometry shader - opengl-es

I have the following shader code:
#version 320 es
layout(points) in;
layout(points, max_vertices=1) out;
uniform mat4 transform;
void main() {
gl_Position = gl_in[0].gl_Position * transform;
EmitVertex();
EndPrimitive();
}
But when creating the shader program I get the following error:
'gl_in' : undeclared identifier
'gl_in' : left of '[' is not of type array, matrix, or vector
'gl_Position' : field selection requires structure, vector, or matrix on left hand side
'assign' : cannot convert from 'const highp float' to 'Position 4-component vector of highp float
But in https://www.khronos.org/registry/OpenGL/specs/es/3.2/GLSL_ES_Specification_3.20.html it explicitly states the existance of gl_in (as a built-in variable).

It is related to Intel UHD graphics not supporting OpenGLES explictly. When I checked what GLSL version was requested it was requesting OpenGL 2.0 which does not support gl_in as a built in.

Related

CGAL 5.3: Example program to draw a triangulation doesn't work

I've installed the CGAL 5.3 and tried to build and run the example program from this page. That's what I did:
cd $HOME/CGAL-5.3/release/examples/Triangulation_2
cmake -DCMAKE_BUILD_TYPE=Release -DCGAL_DIR=../../lib/cmake/CGAL .
make draw_triangulation_2
./draw_triangulation_2
However, I've got a lot of error messages in the console window - mostly complaints about OpenGL shaders, please see below:
QOpenGLShader::compile(Vertex): 0:3(1): error: `in' qualifier in declaration of `vertex' only valid for function parameters in GLSL 1.10
0:4(1): error: `in' qualifier in declaration of `color' only valid for function parameters in GLSL 1.10
0:9(1): error: `out' qualifier in declaration of `fColor' only valid for function parameters in GLSL 1.10
*** Problematic Vertex shader source code ***
#define lowp
#define mediump
#define highp
#line 1
in highp vec4 vertex;
in highp vec3 color;
uniform highp mat4 mvp_matrix;
uniform highp float point_size;
out highp vec4 fColor;
void main(void)
{
gl_PointSize = point_size;
fColor = vec4(color, 1.0);
gl_Position = mvp_matrix * vertex;
}
***
Compiling vertex source FAILED
QOpenGLShader::link: error: linking with uncompiled/unspecialized shader
linking Program FAILED
QOpenGLShader::compile(Vertex): 0:3(1): error: `in' qualifier in declaration of `vertex' only valid for function parameters in GLSL 1.10
0:4(1): error: `in' qualifier in declaration of `normal' only valid for function parameters in GLSL 1.10
0:5(1): error: `in' qualifier in declaration of `color' only valid for function parameters in GLSL 1.10
0:11(1): error: `out' qualifier in declaration of `fP' only valid for function parameters in GLSL 1.10
0:12(1): error: `out' qualifier in declaration of `fN' only valid for function parameters in GLSL 1.10
0:13(1): error: `out' qualifier in declaration of `fColor' only valid for function parameters in GLSL 1.10
*** Problematic Vertex shader source code ***
#define lowp
#define mediump
#define highp
#line 1
in highp vec4 vertex;
in highp vec3 normal;
in highp vec3 color;
uniform highp mat4 mvp_matrix;
uniform highp mat4 mv_matrix;
uniform highp float point_size;
out highp vec4 fP;
out highp vec3 fN;
out highp vec4 fColor;
void main(void)
{
fP = mv_matrix * vertex;
highp mat3 mv_matrix_3;
mv_matrix_3[0] = mv_matrix[0].xyz;
mv_matrix_3[1] = mv_matrix[1].xyz;
mv_matrix_3[2] = mv_matrix[2].xyz;
fN = mv_matrix_3* normal;
fColor = vec4(color, 1.0);
gl_PointSize = point_size;
gl_Position = mvp_matrix * vertex;
}
***
Compiling vertex source FAILED
QOpenGLShader::link: error: linking with uncompiled/unspecialized shader
linking Program FAILED
QOpenGLShader::link: error: linking with uncompiled/unspecialized shader
QOpenGLShaderProgram::attributeLocation(vertex): shader program is not linked
and so on... The viewer window, however, appeared but was empty:
The exactly same sequence of actions with CGAL 5.2.3 has given me a correct window with the triangulation and no error messages - so the OpenGL and Qt5 installations on my box look correct. The transition from the CGAL 5.2.3 to the CGAL 5.3 might be a culprit (???).
How to overcome this?
(I'm on Ubuntu 20.04.3 LTS, with standard kernel 5.11.0-27, and all the standard versions of OpenGL and Qt5)
UPDATE. I've opened an issue on the CGAL bug tracker.
I'm answering my own question. According to CGAL developers it's a bug in the Qt5-based visualization code, and there is no way to overcome it directly. The bug has been already fixed in the code repository, so the fix will be included in the next CGAL release.

How to use UBO in OpenGL ES2.0 shaders

1.I need to move the shader in opengl to Opengles 2.0.so I have a problem, I don't know how to transfer this structure called UBO.
2.What should I assign to the program if the transfer is successful?
1.1 To transfer to opengles2.0 code:
layout(binding = 0) uniform UniformBufferObject
{
mat4 model;
mat4 normal;
mat4 view;
mat4 proj;
vec3 eyepos;
material_struct material;
light_struct lights[8];
} ubo;
2.1 I want to transform the vertex data. How should I assign this UBO to the program?
//vertex
int mPositionHandle = GLES20.GetAttribLocation(_program, "vPosition");
GLES20.EnableVertexAttribArray(mPositionHandle);
GLES20.VertexAttribPointer(mPositionHandle, 3, GLES20.GL_FLOAT, false, 0, _buffer);
//color
int mColorHandle = GLES20.GetAttribLocation(_program, "aColor");
GLES20.EnableVertexAttribArray(mColorHandle);
GLES20.VertexAttribPointer(mColorHandle, 4, GLES20.GL_FLOAT, false, 0, _color);
//UBO???
At present, the vertex data, index, and color are all there, but the vertex data is too large. I hope to change between (-1~1).
Uniform blocks are not provided in OpenGL ES 2.0. See GLSL ES 1.0 specification.
Uniform blocks are supported by OpenGL ES 3.0 respectively GLSL ES 3.00.
See GLSL ES 3.00 specification - 4.3.7 Interface Blocks; page 43.
But the binding layout qualifier is provided since OpenGL ES 3.1 and GLSL ES 3.10.
See GLSL ES 3.10 specification - 4.4 Layout Qualifiers; page 51.
In OpenGL ES 3.0 the binding of a uniform block can be set by glUniformBlockBinding and the uniform block index of the program can be get by glGetUniformBlockIndex. The program has to be successfully linked before, in both cases. Note that the uniform block index is not to be confused with the uniform location, this are different things.
In OpenGL ES 2.0 the only possibility is to use conventional Uniform variables.

RenderMonkey opengles example compile failed with error C0118: macros prefixed with 'GL_' are reserved

I trying to use RenderMonkey 1.82 on Win10 PC, and graphics card is NVIDIA Geforce 405 v342.01. I cannot use the OpenGL ES examples that comes with it. I remember once I could do this on another machine. Is this an compatibility problem?
Vertex shader:
uniform mat4 view_proj_matrix;
uniform vec4 view_position;
attribute vec4 rm_Vertex;
attribute vec3 rm_Normal;
varying vec3 vNormal;
varying vec3 vViewVec;
void main(void)
{
gl_Position = view_proj_matrix * rm_Vertex;
// World-space lighting
vNormal = rm_Normal;
vViewVec = view_position.xyz - rm_Vertex.xyz;
}
Fragment shader:
precision mediump float;
uniform vec4 color;
varying vec3 vNormal;
varying vec3 vViewVec;
void main(void)
{
float v = 0.5 * (1.0 + dot(normalize(vViewVec), vNormal));
gl_FragColor = v * color;
}
The error message is:
OpenGL ES Preview Window: Compiling vertex shader API(OpenGL ES)
/../Plastic_OpenGL_ES/Single Pass/Vertex Program/ ... failure
0(8) :
error C0118: macros prefixed with 'GL_' are reserved
OpenGL ES Preview
Window: Compiling fragment shader API(OpenGL ES)
/../Plastic_OpenGL_ES/Single Pass/Fragment Program/ ... failure
0(3) :
error C0118: macros prefixed with 'GL_' are reserved
RENDERING
ERROR(s): Vertex program 'Vertex Program' failed to compile in pass
'Single Pass'. See Output window for details Fragment program
'Fragment Program' failed to compile in pass 'Single Pass'. See
Output window for details
RenderMonkey adds a bunch of definitions onto the shaders before sending them to the GLSL compiler. You can verify this by running it through CodeXL, and then inspecting the text of the shaders. For my machine, this seems to be the standard (for vertex shaders, fragment shaders are similar):
#version 120
attribute float _J_K_;
void _VSh();void main()
{
_VSh(); gl_Position += (vec4(_J_K_) - vec4(_J_K_));
}
#define main _VSh
#define GL_ES
#define highp
#define mediump
#define lowp
#define invariant
#define gl_MaxVertexAttribs 15
#define gl_MaxVertexUniformVectors 224
#define gl_MaxVaryingVectors 8
#define gl_MaxVertexTextureImageUnits 0
#define gl_MaxCombinedTextureImageUnits 8
#define gl_MaxTextureImageUnits 8
#define gl_MaxFragmentUniformVectors 256
#define gl_MaxDrawBuffers 1
As you can see, on line 8, #define GL_ES is the error you are hitting (and this occurs on line 3 for fragment shaders).
In the GLSL ES spec, it states:
All macro names prefixed with “GL_” (“GL” followed by a single
underscore) are also reserved, and defining such a name results in a
compile-time error.
Thus, your driver is doing the correct thing, and rejecting this shader because it in fact violates the spec. Likely in very old Nvidia drivers, this error was not reported. You would need to recompile RenderMonkey to property resolve this issue, and the sources are not public.
However, you can hack RenderMonkey to get this to compile these shaders. These extra strings that are prepended are contained in the libGLESv2.dll in plain text, and you can use a hex editor to change them to something that doesn't start with GL_. They occur at offsets 0x16052E and 0x1606A0.
Or, instead just use the GL2 workspaces for developing your shaders, since GLSL and GLSL ES are very similar.

can we use structs for uniforms in GLSL-ES

I am trying to use structs for the uniforms in my vertex shader in ES:
struct temp{
mat4 mvp;
};
uniform temp MP;
in vec2 inPos;
void main() {
vec4 vert = MP.mvp * vec4(inPos.x,inPos.y,0,1);
gl_Position = vert;
}
glGetUniformLocation(program, "MP.mvp");
it does not display any thing on screen, neigther any glerror. is it allowed in glsl es 300?
It works with OpenGL.
From The OpenGL ES Shading Language v3.00, in section 4.3.5 Uniform Variables it states:
The uniform qualifier can be used with any of the basic data types, or when declaring a variable whose type is a structure, or an array of any of these.
If glGetUniformLocation(program, "MP.mvp") is returning 0 or greater then what you've shared so far looks legit. You'll probably have to post more code to get to the bottom of it.
If your struct only has a mat4 in it then I would recommend just eliminating the struct altogether.

Do WebGL fragment shaders support outerProduct?

When compiling this WebGL fragment shader in both Chrome 22 and Firefox 15:
precision mediump float;
uniform vec2 u_resolution;
uniform sampler2D u_tex;
void main() {
vec2 texCoord = gl_FragCoord.xy / u_resolution;
vec4 floatColor = texture2D(u_tex, texCoord);
mat3 outerMat = outerProduct(floatColor.rgb,floatColor.rgb);
gl_FragColor = vec4(outerMat[0], 1);
}
I'm getting this error:
ERROR: 0:8: 'outerProduct' : no matching overloaded function found
ERROR: 0:8: '=' : cannot convert from 'const mediump float' to '3X3 matrix of float'
The OpenGL ES 2.0 GLSL spec indicates that mat3 outerProduct(vec3,vec3) is supported, and the WebGL spec says that it accepts ES shaders, so I'm not sure what's going wrong. Is outerProduct not supported in WebGL fragment shaders, or am I doing something wrong?
There is no outerProduct function in OpenGL ES 2.0 GLSL. Where did you read that there was? (or am I missing it?)
Here's the spec
http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf
Try mat3 outerMat = outerProduct(vec3(floatColor.rgb),vec3(floatColor.rgb));
To expand, maybe giving it an explicit type is better than using .rgb.
it is now available with webGL2.
Check your system here: https://webglreport.com/?v=2

Resources