Questions about GLSL

Dear everyone

I have two questions about GLSL

May I ask

  1. How many versions are there?
    #version 460 (for example)
    I want to know how many such versions, and which version I should write down there

  2. What is std140 ?
    I wanna know how many std140 kind things and which std140 stuff I should use

Below is such sample shader statements

#version 460
layout (location = 0) in vec3 vPosition;
layout (location = 1) in vec3 vNormal;
layout (location = 2) in vec3 vColor;

layout (location = 0) out vec3 outColor;

layout(set = 0, binding = 0) uniform  CameraBuffer{
	mat4 view;
	mat4 proj;
	mat4 viewproj;
} cameraData;

struct ObjectData{
	mat4 model;
};

//all object matrices
layout(std140,set = 1, binding = 0) readonly buffer ObjectBuffer{

	ObjectData objects[];
} objectBuffer;

What does that matter? You’re using Vulkan; the only version that matters to you is the one defined by the extension KHR_vulkan_glsl. You’re not going to be able to write a viable GLSL shader that can compile to Vulkan without at least GLSL version 4.20 (which permits the use of binding in interface blocks and opaque uniforms).

So just set the version to 4.60 and move on.

But, as a matter of interest, there are 13 extant versions of GLSL (not counting the 4 OpenGL ES versions). This doesn’t include 1.00, as this is not exposed by any core version of OpenGL; it only exists as an extension.

What is std140 ?

This is one of the standard layouts that you can apply to buffer-backed interface blocks. These define the byte offset and alignment of every scalar type stored in such a block.

Dear Alfonse:
Thank you so much for your help and kindness.
I understand now.

May I ask one more question?

Could you please introduce a nice GLSL reference book or website to me?
I need a good GLSL reference manual

Thank you again and have a great weekend, Alfonse
Take care

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.