提示コードのGLSL
シェーダーですがバージョンの誤差?によるものなのかわからないのですがコンパイルエラー/リンクエラーになります。これはなぜでしょうか?エラーメッセージの通り下記の試した事を試しましたがどれもうまく実行出来ません。何が原因なのでしょうか?
試したこと
#GL_EXT_separate_shader_objects : require
をバージョン表記の下の挿入
#extension GL_ARB_explicit_uniform_location : require
をバージョン表記の下の挿入
様々なバージョンで実行
Openglのバージョンを確認
参考サイト
スタックオーバーフロー: https://stackoverflow.com/questions/38144148/error-when-compiling-shaders-glsl-3-30
OpenGLバージョン:https://ugarailog.blogspot.com/2012/06/linuxopengl.html
環境
OS: ubuntu
IDE: Vscode
gnu make g++
OpenGL バージョン
shigurechan@shigurechan-System-Product-Name:~/Program/ShaderTest$ glxinfo | grep OpenGL
OpenGL vendor string: Intel
OpenGL renderer string: Mesa Intel(R) HD Graphics 4000 (IVB GT2)
OpenGL core profile version string: 4.2 (Core Profile) Mesa 22.3.0-devel (git-37dfa4e 2022-08-10 jammy-oibaf-ppa)
OpenGL core profile shading language version string: 4.20
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.2 (Compatibility Profile) Mesa 22.3.0-devel (git-37dfa4e 2022-08-10 jammy-oibaf-ppa)
OpenGL shading language version string: 4.20
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 22.3.0-devel (git-37dfa4e 2022-08-10 jammy-oibaf-ppa)
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00
OpenGL ES profile extensions:
コンソールログ
shigurechan@shigurechan-System-Product-Name:~/Program/ShaderTest$ ./test
Complie Error: Vertex Shader
0:10(1): error: shader output explicit location requires GL_EXT_separate_shader_objects extension or GLSL ES 3.10
Complie Error: Fragment Shader
0:7(1): error: No precision specified in this scope for type `vec4'
0:7(1): error: shader input explicit location requires GL_EXT_separate_shader_objects extension or GLSL ES 3.10
0:10(1): error: No precision specified in this scope for type `vec4'
Program Info Log: error: linking with uncompiled/unspecialized shadererror: linking with uncompiled/unspecialized shader
プログラムリンク失敗
test: src/Shader.cpp:174: GLuint Shader::CreateProgram(GLchar*, GLchar*): Assertion `0' failed.
中止 (コアダンプ)
以下の1行をバージョン表記の下に追記した時のエラー
#GL_EXT_separate_shader_objects : require
shigurechan@shigurechan-System-Product-Name:~/Program/ShaderTest$ ./test
Complie Error: Vertex Shader
0:6(1): preprocessor error: Illegal non-directive after #
Complie Error: Fragment Shader
0:7(1): preprocessor error: Illegal non-directive after #
Program Info Log: error: linking with uncompiled/unspecialized shadererror: linking with uncompiled/unspecialized shader
プログラムリンク失敗
test: src/Shader.cpp:174: GLuint Shader::CreateProgram(GLchar*, GLchar*): Assertion `0' failed.
中止 (コアダンプ)
以下の1行をバージョン表記の下に追記した時のエラー
#extension GL_ARB_explicit_uniform_location : require
shigurechan@shigurechan-System-Product-Name:~/Program/ShaderTest$ ./test
Complie Error: Vertex Shader
0:7(12): error: extension `GL_ARB_explicit_uniform_location' unsupported in vertex shader
Complie Error: Fragment Shader
0:8(12): error: extension `GL_ARB_explicit_uniform_location' unsupported in fragment shader
Program Info Log: error: linking with uncompiled/unspecialized shadererror: linking with uncompiled/unspecialized shader
プログラムリンク失敗
test: src/Shader.cpp:174: GLuint Shader::CreateProgram(GLchar*, GLchar*): Assertion `0' failed.
中止 (コアダンプ)
GLSLシェーダー
/*#########################################################################
# 単色の二次元描画 頂点シェーダー
###########################################################################*/
//#version 420 core
#version 300 es
//#GL_EXT_separate_shader_objects : require
// ###################### ######################
layout(location = 0) in vec2 vertexPosition; //
// ###################### ######################
layout(location = 2) out vec4 vFragment; //
// ###################### Uniform ######################
uniform mat4 uScale; //
uniform mat4 uRotate; //
uniform mat4 uTranslate; //
uniform mat4 uViewProjection; //
uniform vec4 uFragment; //
void main()
{
vec4 vertex = vec4(vertexPosition,0.0,1.0); //
mat4 model = uTranslate * uRotate * uScale; //
gl_Position = (uViewProjection * model) * vertex;
vFragment = uFragment; //
}
/*#########################################################################
# 単色の二次元描画 フラグメントシェーダー
###########################################################################*/
//#version 420 core
#version 300 es
//#GL_EXT_separate_shader_objects : require
// ###################### 入力 ######################
layout(location = 2) in vec4 vfragment; //カラー
// ###################### 出力 ######################
out vec4 fragment;
void main()
{
fragment = vfragment;
}
OpenGL バージョン
// OpenGL Verison 4.5 Core Profile を選択する
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);