diff --git a/gl/src/lib.rs b/gl/src/lib.rs index 030f63f9..aa08233a 100644 --- a/gl/src/lib.rs +++ b/gl/src/lib.rs @@ -304,12 +304,16 @@ impl Device for GLDevice { } } - fn get_vertex_attr(&self, program: &Self::Program, name: &str) -> GLVertexAttr { + fn get_vertex_attr(&self, program: &Self::Program, name: &str) -> Option { let name = CString::new(format!("a{}", name)).unwrap(); let attr = unsafe { - gl::GetAttribLocation(program.gl_program, name.as_ptr() as *const GLchar) as GLuint + gl::GetAttribLocation(program.gl_program, name.as_ptr() as *const GLchar) }; ck(); - GLVertexAttr { attr } + if attr < 0 { + None + } else { + Some(GLVertexAttr { attr: attr as GLuint }) + } } fn get_uniform(&self, program: &GLProgram, name: &str) -> GLUniform { diff --git a/gpu/src/lib.rs b/gpu/src/lib.rs index cfe4b4ee..7d1fde49 100644 --- a/gpu/src/lib.rs +++ b/gpu/src/lib.rs @@ -44,7 +44,7 @@ pub trait Device { vertex_shader: Self::Shader, fragment_shader: Self::Shader, ) -> Self::Program; - fn get_vertex_attr(&self, program: &Self::Program, name: &str) -> Self::VertexAttr; + fn get_vertex_attr(&self, program: &Self::Program, name: &str) -> Option; fn get_uniform(&self, program: &Self::Program, name: &str) -> Self::Uniform; fn use_program(&self, program: &Self::Program); fn configure_vertex_attr(&self, attr: &Self::VertexAttr, descriptor: &VertexAttrDescriptor); diff --git a/renderer/src/gpu/renderer.rs b/renderer/src/gpu/renderer.rs index 0579d0f2..80bdc477 100644 --- a/renderer/src/gpu/renderer.rs +++ b/renderer/src/gpu/renderer.rs @@ -944,12 +944,12 @@ where BufferUploadMode::Dynamic, ); - let tess_coord_attr = device.get_vertex_attr(&fill_program.program, "TessCoord"); - let from_px_attr = device.get_vertex_attr(&fill_program.program, "FromPx"); - let to_px_attr = device.get_vertex_attr(&fill_program.program, "ToPx"); - let from_subpx_attr = device.get_vertex_attr(&fill_program.program, "FromSubpx"); - let to_subpx_attr = device.get_vertex_attr(&fill_program.program, "ToSubpx"); - let tile_index_attr = device.get_vertex_attr(&fill_program.program, "TileIndex"); + let tess_coord_attr = device.get_vertex_attr(&fill_program.program, "TessCoord").unwrap(); + let from_px_attr = device.get_vertex_attr(&fill_program.program, "FromPx").unwrap(); + let to_px_attr = device.get_vertex_attr(&fill_program.program, "ToPx").unwrap(); + let from_subpx_attr = device.get_vertex_attr(&fill_program.program, "FromSubpx").unwrap(); + let to_subpx_attr = device.get_vertex_attr(&fill_program.program, "ToSubpx").unwrap(); + let tile_index_attr = device.get_vertex_attr(&fill_program.program, "TileIndex").unwrap(); device.bind_vertex_array(&vertex_array); device.use_program(&fill_program.program); @@ -1029,10 +1029,14 @@ where ) -> AlphaTileVertexArray { let (vertex_array, vertex_buffer) = (device.create_vertex_array(), device.create_buffer()); - let tess_coord_attr = device.get_vertex_attr(&alpha_tile_program.program, "TessCoord"); - let tile_origin_attr = device.get_vertex_attr(&alpha_tile_program.program, "TileOrigin"); - let backdrop_attr = device.get_vertex_attr(&alpha_tile_program.program, "Backdrop"); - let tile_index_attr = device.get_vertex_attr(&alpha_tile_program.program, "TileIndex"); + let tess_coord_attr = device.get_vertex_attr(&alpha_tile_program.program, "TessCoord") + .unwrap(); + let tile_origin_attr = device.get_vertex_attr(&alpha_tile_program.program, "TileOrigin") + .unwrap(); + let backdrop_attr = device.get_vertex_attr(&alpha_tile_program.program, "Backdrop") + .unwrap(); + let tile_index_attr = device.get_vertex_attr(&alpha_tile_program.program, "TileIndex") + .unwrap(); let color_tex_coord_attr = device.get_vertex_attr(&alpha_tile_program.program, "ColorTexCoord"); @@ -1074,14 +1078,16 @@ where offset: 6, divisor: 1, }); - device.configure_vertex_attr(&color_tex_coord_attr, &VertexAttrDescriptor { - size: 2, - class: VertexAttrClass::FloatNorm, - attr_type: VertexAttrType::U16, - stride: MASK_TILE_INSTANCE_SIZE, - offset: 8, - divisor: 1, - }); + if let Some(color_tex_coord_attr) = color_tex_coord_attr { + device.configure_vertex_attr(&color_tex_coord_attr, &VertexAttrDescriptor { + size: 2, + class: VertexAttrClass::FloatNorm, + attr_type: VertexAttrType::U16, + stride: MASK_TILE_INSTANCE_SIZE, + offset: 8, + divisor: 1, + }); + } device.bind_buffer(quad_vertex_indices_buffer, BufferTarget::Index); AlphaTileVertexArray { vertex_array, vertex_buffer } @@ -1108,8 +1114,10 @@ where ) -> SolidTileVertexArray { let (vertex_array, vertex_buffer) = (device.create_vertex_array(), device.create_buffer()); - let tess_coord_attr = device.get_vertex_attr(&solid_tile_program.program, "TessCoord"); - let tile_origin_attr = device.get_vertex_attr(&solid_tile_program.program, "TileOrigin"); + let tess_coord_attr = device.get_vertex_attr(&solid_tile_program.program, "TessCoord") + .unwrap(); + let tile_origin_attr = device.get_vertex_attr(&solid_tile_program.program, "TileOrigin") + .unwrap(); let color_tex_coord_attr = device.get_vertex_attr(&solid_tile_program.program, "ColorTexCoord"); @@ -1135,14 +1143,16 @@ where offset: 0, divisor: 1, }); - device.configure_vertex_attr(&color_tex_coord_attr, &VertexAttrDescriptor { - size: 2, - class: VertexAttrClass::FloatNorm, - attr_type: VertexAttrType::U16, - stride: SOLID_TILE_INSTANCE_SIZE, - offset: 4, - divisor: 1, - }); + if let Some(color_tex_coord_attr) = color_tex_coord_attr { + device.configure_vertex_attr(&color_tex_coord_attr, &VertexAttrDescriptor { + size: 2, + class: VertexAttrClass::FloatNorm, + attr_type: VertexAttrType::U16, + stride: SOLID_TILE_INSTANCE_SIZE, + offset: 4, + divisor: 1, + }); + } device.bind_buffer(quad_vertex_indices_buffer, BufferTarget::Index); SolidTileVertexArray { vertex_array, vertex_buffer } @@ -1409,7 +1419,8 @@ where quad_vertex_indices_buffer: &D::Buffer, ) -> PostprocessVertexArray { let vertex_array = device.create_vertex_array(); - let position_attr = device.get_vertex_attr(&postprocess_program.program, "Position"); + let position_attr = device.get_vertex_attr(&postprocess_program.program, "Position") + .unwrap(); device.bind_vertex_array(&vertex_array); device.use_program(&postprocess_program.program); @@ -1462,8 +1473,7 @@ where let vertex_array = device.create_vertex_array(); let (vertex_buffer, index_buffer) = (device.create_buffer(), device.create_buffer()); - let position_attr = device.get_vertex_attr(&stencil_program.program, "Position"); - + let position_attr = device.get_vertex_attr(&stencil_program.program, "Position").unwrap(); device.bind_vertex_array(&vertex_array); device.use_program(&stencil_program.program); device.bind_buffer(&vertex_buffer, BufferTarget::Vertex); @@ -1529,8 +1539,8 @@ where ) -> ReprojectionVertexArray { let vertex_array = device.create_vertex_array(); - let position_attr = device.get_vertex_attr(&reprojection_program.program, "Position"); - + let position_attr = device.get_vertex_attr(&reprojection_program.program, "Position") + .unwrap(); device.bind_vertex_array(&vertex_array); device.use_program(&reprojection_program.program); device.bind_buffer(quad_vertex_positions_buffer, BufferTarget::Vertex); diff --git a/ui/src/lib.rs b/ui/src/lib.rs index 0955dbf7..794e5839 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -585,8 +585,10 @@ impl DebugTextureVertexArray where D: Device { let (vertex_buffer, index_buffer) = (device.create_buffer(), device.create_buffer()); let vertex_array = device.create_vertex_array(); - let position_attr = device.get_vertex_attr(&debug_texture_program.program, "Position"); - let tex_coord_attr = device.get_vertex_attr(&debug_texture_program.program, "TexCoord"); + let position_attr = device.get_vertex_attr(&debug_texture_program.program, "Position") + .unwrap(); + let tex_coord_attr = device.get_vertex_attr(&debug_texture_program.program, "TexCoord") + .unwrap(); device.bind_vertex_array(&vertex_array); device.use_program(&debug_texture_program.program); @@ -624,7 +626,8 @@ impl DebugSolidVertexArray where D: Device { let (vertex_buffer, index_buffer) = (device.create_buffer(), device.create_buffer()); let vertex_array = device.create_vertex_array(); - let position_attr = device.get_vertex_attr(&debug_solid_program.program, "Position"); + let position_attr = device.get_vertex_attr(&debug_solid_program.program, "Position") + .unwrap(); device.bind_vertex_array(&vertex_array); device.use_program(&debug_solid_program.program); device.bind_buffer(&vertex_buffer, BufferTarget::Vertex);