dronus
dronus

Reputation: 11272

WebGL differs from OpenGL preprocessor on same graphics stack

I just come upon an interesting effect by Chrome's use of the GLSL compiler. The statement

#define addf(index) if(weights[i+index]>0.) r+=weights[i+index]*f##index(p);

does not compile stating

preprocessor command must not be preceded by any other statement in that line

It seems that the ## syntax is unsupported. However, on the same platform (eg. Linux 64bit, Nvidia GPU) the same shader compiles and runs fine. Why this? I thought the shader compiler is part of the GPUs driver stack and would be used in both cases. So why this different experience?

Upvotes: 2

Views: 1920

Answers (3)

Nicolas Capens
Nicolas Capens

Reputation: 840

That's because on Windows, Chrome does not use the OpenGL driver by default. It uses Direct3D, and the translation from OpenGL to Direct3D is done by the ANGLE project.

ANGLE has its own shader validator and preprocessor. And hence you can see differences between Windows and other operating systems even though you're using the same hardware. ANGLE was created because on Windows the Direct3D support is typically much better than the OpenGL support, and because it allows more control over the implementation and its conformance.

Upvotes: 1

dronus
dronus

Reputation: 11272

WebGL implementations needs to conform the WebGL specifications. Many restrictions are needed for security issues. The ## issue is not, but anyway not correct by the WebGL specs.

To conform, they can either use a graphics stack that fully conform (for example by providing a wrapper to an unextended OpenGL ES profile if the driver exhibits those) or by prechecking the GLSL shader code and WebGL state itself to ensure conformity before passing the comamnds to some full OpenGL implementation.

So the WebGL behaviour may differ from the native OpenGL behaviour on the same machine.

Upvotes: 1

Tobias Schlegel
Tobias Schlegel

Reputation: 3970

Actually WebGL is also quoted as "OpenGL ES 2.0 for the Web", so there are some differences to OpenGL.

The WebGL spec ( https://www.khronos.org/registry/webgl/specs/1.0/ ) tells us: "A WebGL implementation must only accept shaders which conform to The OpenGL ES Shading Language, Version 1.00."

Looking into the GLSL ES 1.0 spec ( https://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf ) I found:

Section 3.4 defines the preprocessor and also states "There are no number sign based operators (no #, #@, ##, etc.), nor is there a sizeof operator."

So whatever the browser's implementation does internally, it follows the standard :)

Upvotes: 11

Related Questions