diff --git a/src/gl_context.rs b/src/gl_context.rs index 672159b..23db5e5 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 0000000..ff1fc9e --- /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 9ab7904..d05060c 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 ca824f3..8178f47 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); +}