Skip to content

Commit

Permalink
Merge pull request #48 from simartin/servo_issue_9097
Browse files Browse the repository at this point in the history
New GLLimits struct to access GL "limit values".
  • Loading branch information
emilio committed Jan 9, 2016
2 parents 0677179 + 644079e commit 3d717d8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/gl_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use NativeGLContextMethods;
use GLContextAttributes;
use GLContextCapabilities;
use GLFormats;
use GLLimits;
use DrawBuffer;
use ColorAttachmentType;

Expand All @@ -21,6 +22,7 @@ pub struct GLContext<Native> {
attributes: GLContextAttributes,
capabilities: GLContextCapabilities,
formats: GLFormats,
limits: GLLimits,
}

impl<Native> GLContext<Native>
Expand All @@ -30,13 +32,15 @@ impl<Native> GLContext<Native>
try!(native_context.make_current());
let attributes = GLContextAttributes::any();
let formats = GLFormats::detect(&attributes);
let limits = GLLimits::detect();

Ok(GLContext {
native_context: native_context,
draw_buffer: None,
attributes: attributes,
capabilities: GLContextCapabilities::detect(),
formats: formats,
limits: limits,
})
}

Expand Down Expand Up @@ -110,6 +114,10 @@ impl<Native> GLContext<Native>
&self.formats
}

pub fn borrow_limits(&self) -> &GLLimits {
&self.limits
}

pub fn borrow_draw_buffer(&self) -> Option<&DrawBuffer> {
self.draw_buffer.as_ref()
}
Expand Down
15 changes: 15 additions & 0 deletions src/gl_limits.rs
Original file line number Diff line number Diff line change
@@ -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),
}
}
}
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,13 @@ fn test_sharing() {

test_pixels(&vec);
}

#[test]
fn test_limits() {
let size = Size2D::new(256, 256);
let context = GLContext::<NativeGLContext>::new(size,
GLContextAttributes::default(),
ColorAttachmentType::Texture,
None).unwrap();
assert!(context.borrow_limits().max_vertex_attribs != 0);
}

0 comments on commit 3d717d8

Please sign in to comment.