From 644079e612a00253533a6ce6c8b28e52b0160684 Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Thu, 7 Jan 2016 23:19:49 +0100 Subject: [PATCH] New GLLimits struct to access GL "limit values". --- src/gl_context.rs | 8 ++++++++ src/gl_limits.rs | 15 +++++++++++++++ src/lib.rs | 3 +++ src/tests.rs | 10 ++++++++++ 4 files changed, 36 insertions(+) create mode 100644 src/gl_limits.rs diff --git a/src/gl_context.rs b/src/gl_context.rs index 672159bb..23db5e51 100644 --- a/src/gl_context.rs +++ b/src/gl_context.rs @@ -6,6 +6,7 @@ use NativeGLContextMethods; use GLContextAttributes; use GLContextCapabilities; use GLFormats; +use GLLimits; use DrawBuffer; use ColorAttachmentType; @@ -21,6 +22,7 @@ pub struct GLContext { attributes: GLContextAttributes, capabilities: GLContextCapabilities, formats: GLFormats, + limits: GLLimits, } impl GLContext @@ -30,6 +32,7 @@ impl GLContext try!(native_context.make_current()); let attributes = GLContextAttributes::any(); let formats = GLFormats::detect(&attributes); + let limits = GLLimits::detect(); Ok(GLContext { native_context: native_context, @@ -37,6 +40,7 @@ impl GLContext attributes: attributes, capabilities: GLContextCapabilities::detect(), formats: formats, + limits: limits, }) } @@ -110,6 +114,10 @@ impl GLContext &self.formats } + pub fn borrow_limits(&self) -> &GLLimits { + &self.limits + } + pub fn borrow_draw_buffer(&self) -> Option<&DrawBuffer> { self.draw_buffer.as_ref() } diff --git a/src/gl_limits.rs b/src/gl_limits.rs new file mode 100644 index 00000000..ff1fc9ea --- /dev/null +++ b/src/gl_limits.rs @@ -0,0 +1,15 @@ +use gleam::gl::types::GLint; +use gleam::gl; + +#[derive(Clone, Deserialize, Serialize)] +pub struct GLLimits { + pub max_vertex_attribs: GLint, +} + +impl GLLimits { + pub fn detect() -> GLLimits { + GLLimits { + max_vertex_attribs: gl::get_integer_v(gl::MAX_VERTEX_ATTRIBS), + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 9ab79046..d05060c5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,9 @@ pub use gl_feature::GLFeature; mod gl_formats; pub use gl_formats::GLFormats; +mod gl_limits; +pub use gl_limits::GLLimits; + #[macro_use] extern crate log; diff --git a/src/tests.rs b/src/tests.rs index ca824f36..8178f47e 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -159,3 +159,13 @@ fn test_sharing() { test_pixels(&vec); } + +#[test] +fn test_limits() { + let size = Size2D::new(256, 256); + let context = GLContext::::new(size, + GLContextAttributes::default(), + ColorAttachmentType::Texture, + None).unwrap(); + assert!(context.borrow_limits().max_vertex_attribs != 0); +}