최근 활동으로 인해이 오래된 질문이 떠올랐다. 문제가 해결되었음을 알게되었습니다. 쉽지는 않지만 성공적인 솔루션입니다.이 솔루션은 쉐이더 소스를 컴파일하는 드라이버의 수와 그에 기반한 많은 쉐이더에 의해 입증되었습니다.
기본적으로, 나는 GL_ARB_shading_language_include 확장자를 사용하는 (그리고 나는 또한 그것을 구현하지 않습니다 그 시스템의 소스 처리기를 구현 한), 나는 소스에는 다음이 포함 쉐이더를 정의하는 데 결국 :
// Copyright (C) 2011-2013 Luca Piccioni
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// @BeginInterface
// Shader renderer
// Symbol defined if running on NVIDIA renderer.
#define DS_VENDOR_NVIDIA 1
// Symbol defined if running on ATI/AMD renderer.
#define DS_VENDOR_AMD 2
// Symbol defined if running on INTEL renderer
#define DS_VENDOR_INTEL 3
// Shader inputs and outputs keywords
//
// - ATTRIBUTE: used to mark a vertex shader inputs
// - SHADER_IN: used to mark a non-vertex shader inputs
// - SHADER_OUT: used to mark a non-fragment shader output
// - OUT: used to mark a fragment shader output
#if __VERSION__ >= 130
#define ATTRIBUTE in
#define SHADER_IN in
#define SHADER_OUT out
#define OUT out
#else
#define ATTRIBUTE attribute
#define SHADER_IN varying
#define SHADER_OUT varying
#define OUT
#endif
// Support array attributes
#if __VERSION__ >= 130
#define ARRAY_ATTRIBUTE(name, size) name[size]
#else
#define ARRAY_ATTRIBUTE(name, size) name[size]
#endif
// Uniform blocks
#if __VERSION__ >= 130
#define BEGIN_UNIFORM_BLOCK(name) uniform name {
#define END_UNIFORM_BLOCK() };
#else
#define BEGIN_UNIFORM_BLOCK(name)
#define END_UNIFORM_BLOCK()
#endif
// Input and output blocks
#if __VERSION__ >= 150
#define BEGIN_INPUT_BLOCK(name) in name {
#define END_INPUT_BLOCK() };
#define BEGIN_OUTPUT_BLOCK(name) out name {
#define END_OUTPUT_BLOCK() };
#else
#define BEGIN_INPUT_BLOCK(name)
#define END_INPUT_BLOCK()
#define BEGIN_OUTPUT_BLOCK(name)
#define END_OUTPUT_BLOCK()
#endif
// Texturing functions
#if __VERSION__ >= 130
#define TEXTURE_2D texture
#define TEXTURE_3D texture
#define TEXTURE_RECT texture
#define TEXTURE_CUBE texture
#if __VERSION__ >= 150
#define TEXTURE_SIZE(sampler) textureSize(sampler)
#else
#define TEXTURE_SIZE(sampler) sampler ## _Size
#endif
#else
#define TEXTURE_2D texture2D
#define TEXTURE_3D texture3D
#define TEXTURE_RECT texture2DRect
#define TEXTURE_CUBE textureCube
#endif
// Invariance
#if __VERSION__ >= 120
#define INVARIANT invariant
#else
#define INVARIANT
#endif
// Attribute location
#if defined(GL_ARB_explicit_attrib_location)
#define LOCATION(loc) layout(location = loc)
#else
#define LOCATION(loc)
#endif
// Geometry shader layout
#if __VERSION__ >= 150
#define GEOMETRY_LAYOUT_IN(from) layout (from) in
#define GEOMETRY_LAYOUT(to, max) layout (to, max_vertices = max) out
#else
#define GEOMETRY_LAYOUT_IN(from)
#define GEOMETRY_LAYOUT(to, max)
#endif
// @EndInterface
사실 셰이더 소스를 포함하기 전에 셰이더를 포함하면 다양한 컴파일러에서 프레임 워크를 컴파일 할 수 있습니다. 물론 프레임 워크는 실제 시스템 기능을 감지하고 컴파일러 매개 변수를 정의하여 작업을 올바르게 수행해야합니다 (선 두께가 1.0보다 작아서 선 쉐이더를 생각해보십시오).
물론 셰이더 인프라에서 최소 요구 사항을 정의 할 수 있습니다. 셰이더가 GLSL 1.50 또는 그 이후의 코어 프로파일을 필요로하면 더 이상 셰이더를 포함 할 필요가 없습니다.
고맙지 만, 전처리기만 사용하여 다른 버전의 셰이더 소스 코드를 컴파일 할 수있게함으로써 호환성 플래그를 피하려고합니다. – Luca