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.
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.
I also see object-orientation, because of the dot.
That's not what "object orientation" means. The dot is merely the "member access operator", and for all intents and purposes is a combination of some sort of "typecast", "pointer dereferencing" and "pointer arithmetic". All in quotes, because there are not actual pointers involved as far as language and compiler are concerned, but on the silicon level it really boils down to address offsets.
Object orientation means that you can derive classes from other classes, overload and overwrite methods, and so on. Like this (pseudocode)
class A begin
var foo
var bar
method spam()
endclass
class B inherits A begin
var eggs
var bacon
var mixture
method spam() begin
eggs -= bacon
A::spam()
end
method mix(seasoning) begin
mixture = eggs * bacon + seasoning
spam()
end
endclass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With