Skip to content

Commit 3d717d8

Browse files
committed
Merge pull request #48 from simartin/servo_issue_9097
New GLLimits struct to access GL "limit values".
2 parents 0677179 + 644079e commit 3d717d8

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

src/gl_context.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use NativeGLContextMethods;
66
use GLContextAttributes;
77
use GLContextCapabilities;
88
use GLFormats;
9+
use GLLimits;
910
use DrawBuffer;
1011
use ColorAttachmentType;
1112

@@ -21,6 +22,7 @@ pub struct GLContext<Native> {
2122
attributes: GLContextAttributes,
2223
capabilities: GLContextCapabilities,
2324
formats: GLFormats,
25+
limits: GLLimits,
2426
}
2527

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

3437
Ok(GLContext {
3538
native_context: native_context,
3639
draw_buffer: None,
3740
attributes: attributes,
3841
capabilities: GLContextCapabilities::detect(),
3942
formats: formats,
43+
limits: limits,
4044
})
4145
}
4246

@@ -110,6 +114,10 @@ impl<Native> GLContext<Native>
110114
&self.formats
111115
}
112116

117+
pub fn borrow_limits(&self) -> &GLLimits {
118+
&self.limits
119+
}
120+
113121
pub fn borrow_draw_buffer(&self) -> Option<&DrawBuffer> {
114122
self.draw_buffer.as_ref()
115123
}

src/gl_limits.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use gleam::gl::types::GLint;
2+
use gleam::gl;
3+
4+
#[derive(Clone, Deserialize, Serialize)]
5+
pub struct GLLimits {
6+
pub max_vertex_attribs: GLint,
7+
}
8+
9+
impl GLLimits {
10+
pub fn detect() -> GLLimits {
11+
GLLimits {
12+
max_vertex_attribs: gl::get_integer_v(gl::MAX_VERTEX_ATTRIBS),
13+
}
14+
}
15+
}

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ pub use gl_feature::GLFeature;
3434
mod gl_formats;
3535
pub use gl_formats::GLFormats;
3636

37+
mod gl_limits;
38+
pub use gl_limits::GLLimits;
39+
3740
#[macro_use]
3841
extern crate log;
3942

src/tests.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,13 @@ fn test_sharing() {
159159

160160
test_pixels(&vec);
161161
}
162+
163+
#[test]
164+
fn test_limits() {
165+
let size = Size2D::new(256, 256);
166+
let context = GLContext::<NativeGLContext>::new(size,
167+
GLContextAttributes::default(),
168+
ColorAttachmentType::Texture,
169+
None).unwrap();
170+
assert!(context.borrow_limits().max_vertex_attribs != 0);
171+
}

0 commit comments

Comments
 (0)