openglglsl

General Question: Are Shading Languages/shaders object-oriented?


I am currently in an apprenticeship and one of the trainers said "Shaders are object-oriented" as an example for object-orientated programming. To me it means HLSL & GLSL are object-oriented languages. I never thought of shaders as object-oriented.

But now when I look at this: https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)

vec4 someVec;
someVec.x + someVec.y;

I also see object-orientation, because of the dot. Now I am confused.

I started doing OpenGL and GLSL 2 years ago, it never came to my mind that GLSL is object-oriented. So I kind of missed out a major point.

I know that these shader-languages HLSL/GLSL derive from their assembly-predecessors.

Can somebody please state if GLSL is indeed object-oriented.


Solution

  • No, OpenGL Shading Language is not object orientated. There are no methods (or even inheritance and polymorphism) in glsl.
    The data types behave more like a struct in C, than a class in C++. But of course there a additional options to Constructors and initialize the glsl data types respectively some special Vector and Matrix Operations and components can be accessed by Swizzling.
    But that makes the language not to an Object-oriented language, because the concept of objects requires fields of data and procedures (methods) contained in an object. In glsl the general concept of methods is missing.