@@ -62,11 +62,57 @@ lazy_static! {
62
62
static ref COMPILER_GLOBAL_LOCK : Mutex <( ) > = Mutex :: new( ( ) ) ;
63
63
}
64
64
65
+ /// Used in ProgramCreationError::CompilationError to explain which shader stage failed compilation
66
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
67
+ pub enum ShaderType {
68
+ /// Vertex shader, maps to gl::VERTEX_SHADER
69
+ Vertex ,
70
+ /// Geometry shader, maps to gl::GEOMETRY_SHADER
71
+ Geometry ,
72
+ /// Fragment shader, maps to gl::FRAGMENT_SHADER
73
+ Fragment ,
74
+ /// Tesselation control shader, maps to gl::TESS_CONTROL_SHADER
75
+ TesselationControl ,
76
+ /// Tesselation evaluation shader, maps to gl::TESS_EVALUATION_SHADER
77
+ TesselationEvaluation ,
78
+ /// Compute shader, maps to gl::COMPUTE_SHADER
79
+ Compute ,
80
+ }
81
+
82
+ impl ShaderType {
83
+ /// Creates an instance of gl::types::GLenum corresponding to the given ShaderType
84
+ pub fn to_opengl_type ( self ) -> gl:: types:: GLenum {
85
+ match self {
86
+ ShaderType :: Vertex => gl:: VERTEX_SHADER ,
87
+ ShaderType :: Geometry => gl:: GEOMETRY_SHADER ,
88
+ ShaderType :: Fragment => gl:: FRAGMENT_SHADER ,
89
+ ShaderType :: TesselationControl => gl:: TESS_CONTROL_SHADER ,
90
+ ShaderType :: TesselationEvaluation => gl:: TESS_EVALUATION_SHADER ,
91
+ ShaderType :: Compute => gl:: COMPUTE_SHADER ,
92
+ }
93
+ }
94
+ /// Creates an instance of ShaderType corresponding to the given gl::types::GLenum.
95
+ /// This routine will panic if the given shadertype is not supported by glium.
96
+ pub fn from_opengl_type ( gl_type : gl:: types:: GLenum ) -> Self {
97
+ match gl_type {
98
+ gl:: VERTEX_SHADER => ShaderType :: Vertex ,
99
+ gl:: GEOMETRY_SHADER => ShaderType :: Geometry ,
100
+ gl:: FRAGMENT_SHADER => ShaderType :: Fragment ,
101
+ gl:: TESS_CONTROL_SHADER => ShaderType :: TesselationControl ,
102
+ gl:: TESS_EVALUATION_SHADER => ShaderType :: TesselationEvaluation ,
103
+ gl:: COMPUTE_SHADER => ShaderType :: Compute ,
104
+ _ => {
105
+ panic ! ( "Unsupported shader type" )
106
+ }
107
+ }
108
+ }
109
+ }
110
+
65
111
/// Error that can be triggered when creating a `Program`.
66
112
#[ derive( Clone , Debug ) ]
67
113
pub enum ProgramCreationError {
68
114
/// Error while compiling one of the shaders.
69
- CompilationError ( String ) ,
115
+ CompilationError ( String , ShaderType ) ,
70
116
71
117
/// Error while linking the program.
72
118
LinkingError ( String ) ,
@@ -95,7 +141,7 @@ impl fmt::Display for ProgramCreationError {
95
141
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> Result < ( ) , fmt:: Error > {
96
142
use self :: ProgramCreationError :: * ;
97
143
match * self {
98
- CompilationError ( ref s) =>
144
+ CompilationError ( ref s, _ ) =>
99
145
write ! ( fmt, "{}: {}" , self . description( ) , s) ,
100
146
LinkingError ( ref s) =>
101
147
write ! ( fmt, "{}: {}" , self . description( ) , s) ,
@@ -109,8 +155,16 @@ impl Error for ProgramCreationError {
109
155
fn description ( & self ) -> & str {
110
156
use self :: ProgramCreationError :: * ;
111
157
match * self {
112
- CompilationError ( _) =>
113
- "Compilation error in one of the shaders" ,
158
+ CompilationError ( _, typ) => {
159
+ match typ {
160
+ ShaderType :: Vertex => "Compilation error in vertex shader" ,
161
+ ShaderType :: Geometry => "Compilation error in geometry shader" ,
162
+ ShaderType :: Fragment => "Compilation error in fragment shader" ,
163
+ ShaderType :: TesselationControl => "Compilation error in tesselation control shader" ,
164
+ ShaderType :: TesselationEvaluation => "Compilation error in tesselation evaluation shader" ,
165
+ ShaderType :: Compute => "Compilation error in compute shader"
166
+ }
167
+ } ,
114
168
LinkingError ( _) =>
115
169
"Error while linking shaders together" ,
116
170
ShaderTypeNotSupported =>
0 commit comments