From 8aa54d4ebadefdd9d85d8caefa84d08eb187ff07 Mon Sep 17 00:00:00 2001 From: Dan Spencer Date: Mon, 26 Jan 2015 22:30:11 -0700 Subject: [PATCH] Remove return values from `gl_(un)bind_texture()`, change f64 to f32 If either `gl_bind_texture()` or `gl_unbind_texture()` fails, it means OpenGL is not supported for the renderer. --- src/sdl2/render.rs | 51 ++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/sdl2/render.rs b/src/sdl2/render.rs index 3844daec..0304088a 100644 --- a/src/sdl2/render.rs +++ b/src/sdl2/render.rs @@ -703,33 +703,44 @@ impl<'renderer> Texture<'renderer> { } } - pub unsafe fn gl_bind_texture(&mut self) -> SdlResult<(f64, f64)> { - let texw: c_float = 0.0; - let texh: c_float = 0.0; + pub unsafe fn gl_bind_texture(&mut self) -> (f32, f32) { + unsafe { + let texw = 0.0; + let texh = 0.0; - let result = unsafe { - ll::SDL_GL_BindTexture(self.raw, &texw, &texh) == 0 - }; - - if result { - Ok((texw as f64, texh as f64)) - } else { - Err("Operation not supported".to_owned()) + if ll::SDL_GL_BindTexture(self.raw, &texw, &texh) == 0 { + (texw, texh) + } else { + panic!("OpenGL texture binding not supported"); + } } } - pub unsafe fn gl_unbind_texture(&mut self) -> bool { - unsafe { ll::SDL_GL_UnbindTexture(self.raw) == 0 } + pub unsafe fn gl_unbind_texture(&mut self) { + unsafe { + if ll::SDL_GL_UnbindTexture(self.raw) != 0 { + panic!("OpenGL texture unbinding not supported"); + } + } } - pub fn gl_with_bind R>(&mut self, f: F) -> R { + pub fn gl_with_bind R>(&mut self, f: F) -> R { unsafe { - let texw: c_float = 0.0; - let texh: c_float = 0.0; - if ll::SDL_GL_BindTexture(self.raw, &texw, &texh) != 0 { panic!("could not bind texture"); } - let rv = f(texw as f64, texh as f64); - ll::SDL_GL_UnbindTexture(self.raw); - rv + let texw = 0.0; + let texh = 0.0; + + if ll::SDL_GL_BindTexture(self.raw, &texw, &texh) == 0 { + let return_value = f(texw, texh); + + if ll::SDL_GL_UnbindTexture(self.raw) == 0 { + return_value + } else { + // This should never happen... + panic!(); + } + } else { + panic!("OpenGL texture binding not supported"); + } } } }