/*!
Easy-to-use, high-level, OpenGL3+ wrapper.
# Initialization
This library defines the `DisplayBuild` trait which is implemented on
`glium::glutin::WindowBuilder`.
Initialization is done by creating a `WindowBuilder` and calling `build_glium`.
```no_run
extern crate glium;
fn main() {
use glium::DisplayBuild;
let display = glium::glutin::WindowBuilder::new()
.with_dimensions(1024, 768)
.with_title(format!("Hello world"))
.build_glium()
.unwrap();
}
```
The `display` object is the most important object of this library and is used when you build
buffers, textures, etc. and when you draw.
You can clone it and pass it around. However it doesn't implement the `Send` and `Sync` traits,
meaning that you can't pass it to another thread.
The display has ownership of the window, and also provides some methods related to domains such
as events handling.
# Overview
OpenGL is similar to a drawing software: you draw something, then draw over it, then over it
again, etc. until you are satisfied of the result.
Once you have a `display`, you can call `let mut frame = display.draw();` to start drawing. This
`frame` object implements [the `Surface` trait](trait.Surface.html) and provides some functions
such as `clear_color`, but also allows you to draw with the rendering pipeline.
In order to draw something, you will need to pass:
- A source of vertices (see the [`vertex`](vertex/index.html) module)
- A source of indices (see the [`index`](index/index.html) module)
- A program that contains the shader that the GPU will execute (see the
[`program`](program/index.html) module)
- A list of uniforms for the program (see the [`uniforms`](uniforms/index.html) module)
- Draw parameters to customize the drawing process (see the
[`draw_parameters`](draw_parameters/index.html) module)
Once you have finished drawing, you can call `frame.finish()` to swap buffers and present the
result to the user.
# OpenGL equivalents in glium
- **Bind points**: Glium automatically binds and unbinds buffers, textures, etc. in an optimized
way.
- **Buffers**: Buffers are strongly typed and can be used through `vertex::VertexBuffer`,
`index::IndexBuffer` or `uniforms::UniformBuffer`.
- **Debug output**: If you compile in debug mode, glium registers a debug output callback and
panicks if an OpenGL error happens.
- **Framebuffer Objects**: FBOs are automatically managed by glium and are stored in the `Context`
object. You can specify the attachments that you wish with the `framebuffer` module.
- **Instancing**: Instancing is done either by passing a `vertex::EmptyInstanceAttributes` marker
or one or several references to vertex buffers wrapped inside a `PerInstance` struct. See the
`vertex` module for more infos.
- **Memory barriers**: Calling `glMemoryBarrier` is automatically handled by glium, however you
still need to call `memoryBarrier()` in your GLSL code in some situations.
- **Programs**: See the `program` module.
- **Query objects**: The corresponding structs are in the `draw_parameters` module. They are
passed as draw parameters.
- **Renderbuffer**: See the `framebuffer` module.
- **Render to texture**: If you just want to draw on a texture, you can call
`texture.as_surface()`. For more advanced options, see the `framebuffer` module.
- **Samplers**: Samplers are automatically managed by glium and are stored in the `Context`
object. You can specify how a texture should be sampled by using a `Sampler` dummy object
in the `uniforms` module.
- **Shaders**: You can't manually create individual shaders. Instead you must create whole
programs at once.
- **Textures**: Textures are strongly typed and are found in the `texture` module.
- **Uniform blocks**: If your program uses uniform blocks, you must pass a reference to a
uniform buffer for the name of the block when drawing.
- **Vertex array objects**: VAOs are automatically managed by glium if the backend supports them.
*/
#![warn(missing_docs)]
// TODO: remove these when everything is implemented
#![allow(dead_code)]
#![allow(unused_variables)]
#[macro_use]
extern crate lazy_static;
#[cfg(feature = "cgmath")]
extern crate cgmath;
#[cfg(feature = "image")]
extern crate image;
extern crate libc;
#[cfg(feature = "nalgebra")]
extern crate nalgebra;
#[cfg(feature = "glutin")]
pub use backend::glutin_backend::glutin;
pub use draw_parameters::{BlendingFunction, LinearBlendingFactor, BackfaceCullingMode};
pub use draw_parameters::{DepthTest, PolygonMode, DrawParameters, StencilTest, StencilOperation};
pub use index::IndexBuffer;
pub use vertex::{VertexBuffer, Vertex, VertexFormat};
pub use program::{Program, ProgramCreationError};
pub use program::ProgramCreationError::{CompilationError, LinkingError, ShaderTypeNotSupported};
pub use sync::{LinearSyncFence, SyncFence};
pub use texture::{Texture, Texture2d};
pub use version::{Api, Version, get_supported_glsl_version};
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
use context::Context;
use context::CommandContext;
pub mod backend;
pub mod buffer;
pub mod debug;
pub mod draw_parameters;
pub mod framebuffer;
pub mod index;
pub mod pixel_buffer;
pub mod program;
pub mod render_buffer;
pub mod uniforms;
pub mod vertex;
pub mod texture;
mod context;
mod fbo;
mod image_format;
mod macros;
mod ops;
mod sampler_object;
mod sync;
mod utils;
mod version;
mod vertex_array_object;
mod gl {
include!(concat!(env!("OUT_DIR"), "/gl_bindings.rs"));
}
/// The main object of this library. Controls the whole display.
///
/// This object contains a smart pointer to the real implementation.
/// Cloning the display allows you to easily share the `Display` object throughout
/// your program.
#[cfg(feature = "glutin")]
pub type Display = backend::glutin_backend::GlutinFacade;
/// Trait for objects that are OpenGL objects.
pub trait GlObject {
/// The type of identifier for this object.
type Id;
/// Returns the id of the object.
fn get_id(&self) -> Self::Id;
}
/// Handle to a shader or a program.
// TODO: Handle(null()) is equal to Id(0)
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)]
pub enum Handle {
/// A numberic identifier.
Id(gl::types::GLuint),
/// A `GLhandleARB`.
Handle(gl::types::GLhandleARB),
}
unsafe impl Send for Handle {}
/// Internal trait for enums that can be turned into GLenum.
trait ToGlEnum {
/// Returns the value.
fn to_glenum(&self) -> gl::types::GLenum;
}
/// Internal trait for subbuffers.
trait BufferViewExt {
/// Returns the number of bytes from the start of the buffer to this subbuffer.
fn get_offset_bytes(&self) -> usize;
/// Returns the raw identifier of the buffer.
fn get_buffer_id(&self) -> gl::types::GLuint;
/// Calls `glMemoryBarrier(GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT)` if necessary.
fn prepare_for_vertex_attrib_array(&self, &mut CommandContext);
/// Calls `glMemoryBarrier(ELEMENT_ARRAY_BARRIER_BIT)` if necessary.
fn prepare_for_element_array(&self, &mut CommandContext);
/// Binds the buffer to `GL_ELEMENT_ARRAY_BUFFER` regardless of the current vertex array object.
fn bind_to_element_array(&self, &mut CommandContext);
/// Makes sure that the buffer is binded to the `GL_PIXEL_PACK_BUFFER` and calls
/// `glMemoryBarrier(GL_PIXEL_BUFFER_BARRIER_BIT)` if necessary.
fn prepare_and_bind_for_pixel_pack(&self, &mut CommandContext);
/// Makes sure that the buffer is binded to the `GL_PIXEL_UNPACK_BUFFER` and calls
/// `glMemoryBarrier(GL_PIXEL_BUFFER_BARRIER_BIT)` if necessary.
fn prepare_and_bind_for_pixel_unpack(&self, &mut CommandContext);
/// Makes sure that the buffer is binded to the `GL_DRAW_INDIRECT_BUFFER` and calls
/// `glMemoryBarrier(GL_COMMAND_BARRIER_BIT)` if necessary.
fn prepare_and_bind_for_draw_indirect(&self, &mut CommandContext);
/// Makes sure that the buffer is binded to the indexed `GL_UNIFORM_BUFFER` point and calls
/// `glMemoryBarrier(GL_UNIFORM_BARRIER_BIT)` if necessary.
fn prepare_and_bind_for_uniform(&self, &mut CommandContext, index: gl::types::GLuint);
/// Makes sure that the buffer is binded to the indexed `GL_SHARED_STORAGE_BUFFER` point and calls
/// `glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT)` if necessary.
fn prepare_and_bind_for_shared_storage(&self, &mut CommandContext, index: gl::types::GLuint);
/// Binds the buffer to `GL_TRANSFORM_FEEDBACk_BUFFER` regardless of the current transform
/// feedback object.
fn bind_to_transform_feedback(&self, &mut CommandContext, index: gl::types::GLuint);
}
/// Internal trait for subbuffer slices.
trait BufferViewSliceExt<'a> {
/// Tries to get a reference to a `RefCell` where to write a fence.
///
/// If this function returns `None`, no fence will be created nor written.
fn add_fence(&self) -> Option<&'a RefCell<Option<sync::LinearSyncFence>>>;
}
/// Internal trait for contexts.
trait ContextExt {
/// Sets whether the context's debug output callback should take errors into account.
fn set_report_debug_output_errors(&self, value: bool);
/// Start executing OpenGL commands by checking the current context.
fn make_current(&self) -> context::CommandContext;
/// Returns the list of framebuffer objects.
fn get_framebuffer_objects(&self) -> &fbo::FramebuffersContainer;
/// Returns the list of samplers.
fn get_samplers(&self) -> &RefCell<HashMap<uniforms::SamplerBehavior,
sampler_object::SamplerObject>>;
/// Returns the capabilities of the backend.
fn capabilities(&self) -> &context::Capabilities;
/// Returns the list of extensions supported by the backend.
fn get_extensions(&self) -> &context::ExtensionsList;
}
/// Internal trait for programs.
trait ProgramExt {
/// Calls `glUseProgram`.
fn use_program(&self, ctxt: &mut context::CommandContext);
/// Changes the value of a uniform of the program.
fn set_uniform(&self, ctxt: &mut context::CommandContext, uniform_location: gl::types::GLint,
value: &RawUniformValue);
/// Changes the uniform block binding of the program.
fn set_uniform_block_binding(&self, ctxt: &mut context::CommandContext,
block_location: gl::types::GLuint, value: gl::types::GLuint);
/// Changes the shader storage block binding of the program.
fn set_shader_storage_block_binding(&self, ctxt: &mut context::CommandContext,
block_location: gl::types::GLuint,
value: gl::types::GLuint);
fn get_uniform(&self, name: &str) -> Option<&program::Uniform>;
fn get_uniform_blocks(&self) -> &HashMap<String, program::UniformBlock>;
fn get_shader_storage_blocks(&self) -> &HashMap<String, program::UniformBlock>;
}
/// Internal trait for queries.
trait QueryExt {
/// Returns true if the query has never been used.
fn is_unused(&self) -> bool;
/// Sets the query as having been used.
fn set_used(&self);
/// Returns the type of this query object.
fn get_type(&self) -> gl::types::GLenum;
}
/// Internal trait for textures.
trait TextureExt {
/// Returns the bind point of the texture.
fn get_bind_point(&self) -> gl::types::GLenum;
}
/// Internal trait for transform feedback sessions.
trait TransformFeedbackSessionExt {
/// Updates the state of OpenGL to make the transform feedback session current.
///
/// The second parameter must be the primitive type of the input vertex data.
fn bind(&self, &mut CommandContext, index::PrimitiveType);
/// Ensures that transform feedback is disabled.
fn unbind(&mut CommandContext);
/// Ensures that a buffer isn't used by transform feedback.
fn ensure_buffer_out_of_transform_feedback(&mut CommandContext, gl::types::GLuint);
}
/// Internal trait for uniforms handling.
trait UniformsExt {
/// Binds the uniforms to a given program.
///
/// Will replace texture and buffer bind points.
// TODO: put the samplers inside the CommandContext
fn bind_uniforms<'a, P>(&'a self, &mut CommandContext, &P,
&mut Vec<&'a RefCell<Option<sync::LinearSyncFence>>>,
&mut HashMap<uniforms::SamplerBehavior, sampler_object::SamplerObject>)
-> Result<(), DrawError> where P: ProgramExt;
}
/// A raw value of a uniform. "Raw" means that it's passed directly with `glUniform`. Textures
/// for example are just passed as integers.
///
/// Blocks and subroutines are not included.
#[derive(Copy, Clone, Debug)]
enum RawUniformValue {
SignedInt(gl::types::GLint),
UnsignedInt(gl::types::GLuint),
Float(gl::types::GLfloat),
/// 2x2 column-major matrix.
Mat2([[gl::types::GLfloat; 2]; 2]),
/// 3x3 column-major matrix.
Mat3([[gl::types::GLfloat; 3]; 3]),
/// 4x4 column-major matrix.
Mat4([[gl::types::GLfloat; 4]; 4]),
Vec2([gl::types::GLfloat; 2]),
Vec3([gl::types::GLfloat; 3]),
Vec4([gl::types::GLfloat; 4]),
}
/// Area of a surface in pixels.
///
/// In the OpenGL ecosystem, the (0,0) coordinate is at the bottom-left hand corner of the images.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct Rect {
/// Number of pixels between the left border of the surface and the left border of
/// the rectangle.
pub left: u32,
/// Number of pixels between the bottom border of the surface and the bottom border
/// of the rectangle.
pub bottom: u32,
/// Width of the area in pixels.
pub width: u32,
/// Height of the area in pixels.
pub height: u32,
}
/// Area of a surface in pixels. Similar to a `Rect` except that dimensions can be negative.
///
/// In the OpenGL ecosystem, the (0,0) coordinate is at the bottom-left hand corner of the images.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct BlitTarget {
/// Number of pixels between the left border of the surface and the left border of
/// the rectangle.
pub left: u32,
/// Number of pixels between the bottom border of the surface and the bottom border
/// of the rectangle.
pub bottom: u32,
/// Width of the area in pixels. Can be negative.
pub width: i32,
/// Height of the area in pixels. Can be negative.
pub height: i32,
}
/// Object that can be drawn upon.
///
/// # What does the GPU do when you draw?
///
/// This is a summary of everything that happens when you call the `draw` function. Note that
/// this is not necessarly *exactly* what happens. Backends are free to do whatever they want
/// as long as it always matches the expected outcome.
///
/// ## Step 1: Vertex shader
///
/// For each vertex in the vertices source, the GPU invokes the vertex shader that is part
/// of the program, and passes the corresponding vertex's attributes to it.
///
/// The vertex shader *must* write the special `gl_Position` variable in order to indicate
/// the four-dimensions coordinates of the vertex. In order to understand what these coordinates
/// mean, see the "vertex post-processing" step below.
///
/// In addition to the position of the vertex, the vertex shader can also specify the values of
/// various vertex attributes.
///
/// ## Step 2: Tessellation (optional)
///
/// It is possible to use tessellation shaders, but glium does not support them yet.
///
/// ## Step 3: Geometry shader (optional)
///
/// If you specify a geometry shader, then the GPU will invoke it once for each primitive.
///
/// The geometry shader can output multiple primitives.
///
/// ## Step 4: Transform feedback (optional)
///
/// Transform feedback is not supported by glium for the moment.
///
/// ## Step 5: Vertex post-processing
///
/// The vertex shader step told the GPU what the coordinates of each vertex are, but these
/// coordinates have four dimensions, named `x`, `y`, `z` and `w`.
///
/// The GPU then computes the position of the vertex on the 2D surface you are drawing on, and
/// the depth of this vertex:
///
/// ```notrust
/// window_x = viewport_left + viewport_width * ((x / w) + 1.0) / 2.0
/// window_y = viewport_bottom + viewport_height * ((y / w) + 1.0) / 2.0
/// depth = depth_near + (depth_far - depth_near) * ((z / w) + 1.0) / 2.0
/// ```
///
/// *`viewport_left`, `viewport_width`, `viewport_bottom` and `viewport_height` correspond to
/// the `viewport` member of the draw parameters, and `depth_near` and `depth_far` correspond
/// to the `depth_range` member*.
///
/// This means that if `x / w`, `y / w` or `z / w` are equal to `-1.0`, then the result will be
/// `viewport_left`, `viewport_bottom` or `depth_near`. If they are equal to `1.0`, the result
/// will be `viewport_left + viewport_width` (the right of the viewport),
/// `viewport_bottom + viewport_height` (the top of the viewport) or `depth_far`.
///
/// For example if you want to draw a rectangle that covers the whole screen, it should be made
/// of four vertices whose coordinates are `(-1.0, -1.0, 0.0, 1.0)` (bottom-left corner),
/// `(-1.0, 1.0, 0.0, 1.0)` (top-left corner), `(1.0, 1.0, 0.0, 1.0)` (top-right corner) and
/// `(1.0, -1.0, 0.0, 1.0)` (bottom-right corner).
///
/// ## Step 6: Primitive assembly
///
/// The next step consists in building the primitives. Triangle strips, triangle fans and line
/// strips are turned into individual triangles or lines.
///
/// Triangle strips obey certain rules for the order of indices. For example the triangle strip
/// `0, 1, 2, 3, 4, 5` does *not* correspond to `0, 1, 2`, `1, 2, 3`, `2, 3, 4`, `3, 4, 5` as you
/// would expect, but to `0, 1, 2`, `1, 3, 2`, `2, 3, 4`, `3, 5, 4` (some indices are reversed).
/// This is important with regards to the face culling step below.
///
/// Then, if you did specify `PrimitiveMode`, it is used. If you specified `Line`, triangles are
/// turned into lines. If specified `Point`, triangles and lines are turned into points.
///
/// The GPU then looks at the screen coordinates of each primitive, and discards primitives that
/// are entirely outside of the window.
///
/// Note that points whose centers are outside of the viewport are discarded, even if the point
/// width would be big enough for the point to be visible. However this standard behavior is not
/// respected by nVidia drivers, which show the points anyway.
///
/// ## Step 7: Face culling (triangles only)
///
/// This step is purely an optimization step and only concerns triangles.
///
/// If you specify a value for `backface_culling` other than `CullingDisabled`, the GPU will
/// discard triangles depending on the way that the vertices are arranged on the window. You can
/// either discard triangles whose vertices are clockwise or counterclockwise.
///
/// For more information, see the `BackfaceCullingMode` documentation.
///
/// ## Step 8: Rasterization
///
/// Now that the GPU knows where on the window the various triangles, points or lines are, it will
/// determine which pixels of the surface are part of each primitive.
///
/// For points and lines, this step depends on the points width and line width that you specified
/// in the draw parameters.
///
/// <img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAnYAAAEsCAYAAABOqf71AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAxOAAAMTgF/d4wjAAAAB3RJTUUH3wEIDBAooQVGygAAG4JJREFUeNrt3XuQXGWZx/HvmftMLjOZJJCLuZAEuYgJlIBKFBGQoNwCtQvlemPRVVaLhRUtlHG31KUVd7HEUgvwDy9LqaB7UVxL3dJV8a6sV5DLCkmASAwJyYRkMvfeP96ezJlmksxkumfOe/r7qUqR0wmZp5/z9ulfn/f0e0CSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEnSDEq64BLgFmBNhPUXgcTdqByKdWxvTuBvb4JvuQsP70Z4VQK3Aic6RiXH9hRtBa6tAz4RaajDg4ry/KEr0rpXFuEmd9+Ed/JHIw11Hn/l8Td7lgIfqQO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IkGewkSZJksJMkSTLYSZIkyWAnSZIkg50kSZIMdpIkSQY7SZIkGewkSZJksJMkSZLBTpIkyWAnSZIkg50kSZIMdpIkSTLYSZIkyWAnSZJksJMkSZLBTpIkSdWVdEExtf0b4AcR1H0KcGZq+z7gxxHU/ZfAktT27UBfBHW/A2go/b6vVHfWLQBel9reAnw1grrPBl6Y2v4m8EhkdXcXoMPD6+F1wW6gHWAYHhmA72e95npY3QDnjGwPwUODcG/W626C1yTwvNRDXwB2RDBMrgaaS78fBD4VQc3NpbpHbAPujqDu9cCpqe17gV/HVnd5sJOkqTLYHUGwk6RKqAMetQ2SKuhJWzBhf7QFkipoax1wA7A10ifg2UblVaxj+0Hg3e6+CXsfsNkxKjm2K+BR4Fp3nyRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRN3f8DIrOQLp3kqkAAAAAASUVORK5CYII=" />
///
/// The attributes of each vertex are being interpolated, and the GPU assigns a value for each
/// attribute for each pixel.
///
/// ## Step 9: Fragment shader
///
/// The GPU now executes the fragment shader once for each pixel of each primitive.
///
/// The vertex attributes that were interpolated at the previous step are passed to the fragment
/// shader.
///
/// The fragment shader must return the color to write by setting the value of `gl_FragColor`.
///
/// ## Step 10: Pixel ownership
///
/// This step is mostly an implementation detail. If the window you are drawing on is not on the
/// foreground, or if it is partially obstructed, then the pixels that are not on the
/// foreground will be discarded.
///
/// This is only relevant if you draw to the default framebuffer.
///
/// ## Step 11: Scissor test
///
/// If `scissor` has been specified, then all the pixels that are outside of this rect
/// are discarded.
///
/// ## Step 12: Multisampling
///
/// ## Step 13: Stencil test
///
/// Stencil tests are currently not supported by glium.
///
/// ## Step 14: Depth test
///
/// In addition to the colors, surfaces can also have a depth buffer attached to it. In this
/// situation, just like each pixel has a color, each pixel of the surface also has an associated
/// depth value.
///
/// If a depth buffer is present, the GPU will compare the depth value of the pixel currently
/// being processed, with the existing depth value. Depending on the value of `depth_test`
/// in the draw parameters, the depth test will either pass, in which case the pipeline
/// continues, or fail, in which case the pixel is discarded. If the value of `depth_write`
/// is true and the test passed, it will then also write the depth value of the pixel on the
/// depth buffer.
///
/// The purpose of this test is to avoid drawing elements that are in the background of the
/// scene over elements that are in the foreground.
///
/// See the documentation of `DepthTest` for more informations.
///
/// ## Step 15: Blending
///
/// For each pixel to write, the GPU takes the RGBA color that the fragment shader has returned
/// and the existing RGBA color already written on the surface, and merges the two.
///
/// The way they are merged depends on the value of `blending_function`. This allows you to choose
/// how alpha colors are merged together.
///
/// See the documentation of `BlendingFunction` fore more informations.
///
/// ## Step 16: Dithering (optional)
///
/// ## Step 17: End
///
/// This is finally the step where colors are being written.
///
/// ## Missing steps
///
/// Some steps are missing because they are not supported by glium for the moment: dithering,
/// occlusion query updating, logic operations, sRGB conversion, write masks.
///
/// Instancing and multiple viewports are also missing, as they are not supported.
///
pub trait Surface: Sized {
/// Clears some attachments of the target.
fn clear(&mut self, rect: Option<&Rect>, color: Option<(f32, f32, f32, f32)>,
depth: Option<f32>, stencil: Option<i32>);
/// Clears the color attachment of the target.
fn clear_color(&mut self, red: f32, green: f32, blue: f32, alpha: f32) {
self.clear(None, Some((red, green, blue, alpha)), None, None);
}
/// Clears the depth attachment of the target.
fn clear_depth(&mut self, value: f32) {
self.clear(None, None, Some(value), None);
}
/// Clears the stencil attachment of the target.
fn clear_stencil(&mut self, value: i32) {
self.clear(None, None, None, Some(value));
}
/// Clears the color and depth attachments of the target.
fn clear_color_and_depth(&mut self, color: (f32, f32, f32, f32), depth: f32) {
self.clear(None, Some(color), Some(depth), None);
}
/// Clears the color and stencil attachments of the target.
fn clear_color_and_stencil(&mut self, color: (f32, f32, f32, f32), stencil: i32) {
self.clear(None, Some(color), None, Some(stencil));
}
/// Clears the depth and stencil attachments of the target.
fn clear_depth_and_stencil(&mut self, depth: f32, stencil: i32) {
self.clear(None, None, Some(depth), Some(stencil));
}
/// Clears the color, depth and stencil attachments of the target.
fn clear_all(&mut self, color: (f32, f32, f32, f32), depth: f32, stencil: i32) {
self.clear(None, Some(color), Some(depth), Some(stencil));
}
/// Returns the dimensions in pixels of the target.
fn get_dimensions(&self) -> (u32, u32);
/// Returns the number of bits of each pixel of the depth buffer.
///
/// Returns `None` if there is no depth buffer.
fn get_depth_buffer_bits(&self) -> Option<u16>;
/// Returns true if the surface has a depth buffer available.
fn has_depth_buffer(&self) -> bool {
self.get_depth_buffer_bits().is_some()
}
/// Returns the number of bits of each pixel of the stencil buffer.
///
/// Returns `None` if there is no stencil buffer.
fn get_stencil_buffer_bits(&self) -> Option<u16>;
/// Returns true if the surface has a stencil buffer available.
fn has_stencil_buffer(&self) -> bool {
self.get_stencil_buffer_bits().is_some()
}
/// Draws.
///
/// See above for what happens exactly when you draw.
///
/// # Panic
///
/// - Panics if the requested depth function requires a depth buffer and none is attached.
/// - Panics if the type of some of the vertex source's attributes do not match the program's.
/// - Panics if a program's attribute is not in the vertex source (does *not* panic if a
/// vertex's attribute is not used by the program).
/// - Panics if the viewport is larger than the dimensions supported by the hardware.
/// - Panics if the depth range is outside of `(0, 1)`.
/// - Panics if a value in the uniforms doesn't match the type requested by the program.
///
fn draw<'a, 'b, V, I, U>(&mut self, V, I, program: &Program, uniforms: &U,
draw_parameters: &DrawParameters) -> Result<(), DrawError> where
V: vertex::MultiVerticesSource<'b>, I: Into<index::IndicesSource<'a>>,
U: uniforms::Uniforms;
/// Blits from the default framebuffer.
fn blit_from_frame(&self, source_rect: &Rect, target_rect: &BlitTarget,
filter: uniforms::MagnifySamplerFilter);
/// Blits from a simple framebuffer.
fn blit_from_simple_framebuffer(&self, source: &framebuffer::SimpleFrameBuffer,
source_rect: &Rect, target_rect: &BlitTarget,
filter: uniforms::MagnifySamplerFilter);
/// Blits from a multi-output framebuffer.
fn blit_from_multioutput_framebuffer(&self, source: &framebuffer::MultiOutputFrameBuffer,
source_rect: &Rect, target_rect: &BlitTarget,
filter: uniforms::MagnifySamplerFilter);
/// Copies a rectangle of pixels from this surface to another surface.
///
/// The `source_rect` defines the area of the source (`self`) that will be copied, and the
/// `target_rect` defines the area where the copied image will be pasted. If the source and
/// target areas don't have the same dimensions, the image will be resized to match.
/// The `filter` parameter is relevant only in this situation.
///
/// It is possible for the source and the target to be the same surface. However if the
/// rectangles overlap, then the behavior is undefined.
///
/// Note that there is no alpha blending, depth/stencil checking, etc. This function just
/// copies pixels.
fn blit_color<S>(&self, source_rect: &Rect, target: &S, target_rect: &BlitTarget,
filter: uniforms::MagnifySamplerFilter) where S: Surface;
/// Copies the entire surface to a target surface. See `blit_color`.
fn blit_whole_color_to<S>(&self, target: &S, target_rect: &BlitTarget,
filter: uniforms::MagnifySamplerFilter) where S: Surface
{
let src_dim = self.get_dimensions();
let src_rect = Rect { left: 0, bottom: 0, width: src_dim.0 as u32, height: src_dim.1 as u32 };
self.blit_color(&src_rect, target, target_rect, filter)
}
/// Copies the entire surface to the entire target. See `blit_color`.
fn fill<S>(&self, target: &S, filter: uniforms::MagnifySamplerFilter) where S: Surface {
let src_dim = self.get_dimensions();
let src_rect = Rect { left: 0, bottom: 0, width: src_dim.0 as u32, height: src_dim.1 as u32 };
let target_dim = target.get_dimensions();
let target_rect = BlitTarget { left: 0, bottom: 0, width: target_dim.0 as i32, height: target_dim.1 as i32 };
self.blit_color(&src_rect, target, &target_rect, filter)
}
}
/// Private trait for framebuffer-like objects that provide attachments.
trait FboAttachments {
/// Returns the list of attachments of this FBO, or `None` if it is the default framebuffer.
fn get_attachments(&self) -> Option<&fbo::ValidatedAttachments>;
}
/// Error that can happen while drawing.
#[derive(Clone, Debug)]
pub enum DrawError {
/// A depth function has been requested but no depth buffer is available.
NoDepthBuffer,
/// The type of a vertex attribute in the vertices source doesn't match what the
/// program requires.
AttributeTypeMismatch,
/// One of the attributes required by the program is missing from the vertex format.
///
/// Note that it is perfectly valid to have an attribute in the vertex format that is
/// not used by the program.
AttributeMissing,
/// The viewport's dimensions are not supported by the backend.
ViewportTooLarge,
/// The depth range is outside of the `(0, 1)` range.
InvalidDepthRange,
/// The type of a uniform doesn't match what the program requires.
UniformTypeMismatch {
/// Name of the uniform you are trying to bind.
name: String,
/// The expected type.
expected: uniforms::UniformType,
},
/// Tried to bind a uniform buffer to a single uniform value.
UniformBufferToValue {
/// Name of the uniform you are trying to bind.
name: String,
},
/// Tried to bind a single uniform value to a uniform block.
UniformValueToBlock {
/// Name of the uniform you are trying to bind.
name: String,
},
/// The layout of the content of the uniform buffer does not match the layout of the block.
UniformBlockLayoutMismatch {
/// Name of the block you are trying to bind.
name: String,
},
/// The number of vertices per patch that has been requested is not supported.
UnsupportedVerticesPerPatch,
/// Trying to use tessellation, but this is not supported by the underlying hardware.
TessellationNotSupported,
/// Using a program which contains tessellation shaders, but without submitting patches.
TessellationWithoutPatches,
/// Trying to use a sampler, but they are not supported by the backend.
SamplersNotSupported,
/// When you use instancing, all vertices sources must have the same size.
InstancesCountMismatch,
/// If you don't use indices, then all vertices sources must have the same size.
VerticesSourcesLengthMismatch,
/// You requested not to draw primitives, but this is not supported by the backend.
TransformFeedbackNotSupported,
/// See the documentation of the `draw_parameters` module for infos.
WrongQueryOperation,
}
impl std::fmt::Display for DrawError {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
match self {
&DrawError::NoDepthBuffer => write!(fmt, "A depth function has been requested but no \
depth buffer is available."),
&DrawError::AttributeTypeMismatch => write!(fmt, "The type of a vertex attribute in \
the vertices source doesn't match \
what the program requires."),
&DrawError::AttributeMissing => write!(fmt, "One of the attributes required by the \
program is missing from the vertex \
format."),
&DrawError::ViewportTooLarge => write!(fmt, "The viewport's dimensions are not \
supported by the backend."),
&DrawError::InvalidDepthRange => write!(fmt, "The depth range is outside of the \
`(0, 1)` range."),
&DrawError::UniformTypeMismatch { ref name, ref expected } => {
write!(fmt, "The type of a uniform doesn't match what the program requires.")
},
&DrawError::UniformBufferToValue { ref name } => write!(fmt, "Tried to bind a uniform \
buffer to a single \
uniform value."),
&DrawError::UniformValueToBlock { ref name } => {
write!(fmt, "Tried to bind a single uniform value to a uniform block.")
},
&DrawError::UniformBlockLayoutMismatch { ref name } => {
write!(fmt, "The layout of the content of the uniform buffer does not match \
the layout of the block.")
},
&DrawError::UnsupportedVerticesPerPatch => write!(fmt, "The number of vertices per \
patch that has been requested \
is not supported."),
&DrawError::TessellationNotSupported => write!(fmt, "Trying to use tessellation, but \
this is not supported by the \
underlying hardware."),
&DrawError::TessellationWithoutPatches => write!(fmt, "Using a program which contains \
tessellation shaders, but \
without submitting patches."),
&DrawError::SamplersNotSupported => write!(fmt, "Trying to use a sampler, but they are \
not supported by the backend."),
&DrawError::InstancesCountMismatch => write!(fmt, "When you use instancing, all \
vertices sources must have the \
same size"),
&DrawError::VerticesSourcesLengthMismatch => write!(fmt, "If you don't use indices, \
then all vertices sources \
must have the same size."),
&DrawError::TransformFeedbackNotSupported => write!(fmt, "Requested not to draw \
primitves, but this is not \
supported by the backend."),
&DrawError::WrongQueryOperation => write!(fmt, "Wrong query operation."),
}
}
}
/// Implementation of `Surface`, targeting the default framebuffer.
///
/// The back- and front-buffers are swapped when the `Frame` is destroyed. This operation is
/// instantaneous, even when vsync is enabled.
pub struct Frame {
context: Rc<Context>,
dimensions: (u32, u32),
}
impl Frame {
/// Builds a new `Frame`. Use the `draw` function on `Display` instead of this function.
pub fn new(context: Rc<Context>, dimensions: (u32, u32)) -> Frame {
Frame {
context: context,
dimensions: dimensions,
}
}
/// Stop drawing, and swap the buffers.
pub fn finish(self) {
}
}
impl Surface for Frame {
fn clear(&mut self, rect: Option<&Rect>, color: Option<(f32, f32, f32, f32)>,
depth: Option<f32>, stencil: Option<i32>)
{
ops::clear(&self.context, None, None, color, depth, stencil);
}
fn get_dimensions(&self) -> (u32, u32) {
self.dimensions
}
fn get_depth_buffer_bits(&self) -> Option<u16> {
self.context.capabilities().depth_bits
}
fn get_stencil_buffer_bits(&self) -> Option<u16> {
self.context.capabilities().stencil_bits
}
fn draw<'a, 'b, V, I, U>(&mut self, vertex_buffer: V,
index_buffer: I, program: &Program, uniforms: &U,
draw_parameters: &DrawParameters) -> Result<(), DrawError>
where I: Into<index::IndicesSource<'a>>, U: uniforms::Uniforms,
V: vertex::MultiVerticesSource<'b>
{
if !self.has_depth_buffer() && (draw_parameters.depth_test.requires_depth_buffer() ||
draw_parameters.depth_write)
{
return Err(DrawError::NoDepthBuffer);
}
if let Some(viewport) = draw_parameters.viewport {
if viewport.width > self.context.capabilities().max_viewport_dims.0
as u32
{
return Err(DrawError::ViewportTooLarge);
}
if viewport.height > self.context.capabilities().max_viewport_dims.1
as u32
{
return Err(DrawError::ViewportTooLarge);
}
}
ops::draw(&self.context, None, vertex_buffer, index_buffer.into(), program,
uniforms, draw_parameters, (self.dimensions.0 as u32, self.dimensions.1 as u32))
}
fn blit_color<S>(&self, source_rect: &Rect, target: &S, target_rect: &BlitTarget,
filter: uniforms::MagnifySamplerFilter) where S: Surface
{
target.blit_from_frame(source_rect, target_rect, filter)
}
fn blit_from_frame(&self, source_rect: &Rect, target_rect: &BlitTarget,
filter: uniforms::MagnifySamplerFilter)
{
ops::blit(&self.context, None, self.get_attachments(),
gl::COLOR_BUFFER_BIT, source_rect, target_rect, filter.to_glenum())
}
fn blit_from_simple_framebuffer(&self, source: &framebuffer::SimpleFrameBuffer,
source_rect: &Rect, target_rect: &BlitTarget,
filter: uniforms::MagnifySamplerFilter)
{
ops::blit(&self.context, source.get_attachments(), self.get_attachments(),
gl::COLOR_BUFFER_BIT, source_rect, target_rect, filter.to_glenum())
}
fn blit_from_multioutput_framebuffer(&self, source: &framebuffer::MultiOutputFrameBuffer,
source_rect: &Rect, target_rect: &BlitTarget,
filter: uniforms::MagnifySamplerFilter)
{
ops::blit(&self.context, source.get_attachments(), self.get_attachments(),
gl::COLOR_BUFFER_BIT, source_rect, target_rect, filter.to_glenum())
}
}
impl FboAttachments for Frame {
fn get_attachments(&self) -> Option<&fbo::ValidatedAttachments> {
None
}
}
impl Drop for Frame {
fn drop(&mut self) {
self.context.swap_buffers();
}
}
/// Objects that can build a facade object.
pub trait DisplayBuild {
/// The object that this `DisplayBuild` builds.
type Facade: backend::Facade;
/// The type of error that initialization can return.
type Err;
/// Build a context and a facade to draw on it.
///
/// Performs a compatibility check to make sure that all core elements of glium
/// are supported by the implementation.
fn build_glium(self) -> Result<Self::Facade, Self::Err>;
/// Build a context and a facade to draw on it
///
/// This function does the same as `build_glium`, except that the resulting context
/// will assume that the current OpenGL context will never change.
unsafe fn build_glium_unchecked(self) -> Result<Self::Facade, Self::Err>;
/// Changes the settings of an existing facade.
fn rebuild_glium(self, &Self::Facade) -> Result<(), Self::Err>;
}
/// Error that can happen while creating a glium display.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum GliumCreationError<T> {
/// An error has happened while creating the backend.
BackendCreationError(T),
/// The OpenGL implementation is too old.
IncompatibleOpenGl(String),
}
impl<T> std::fmt::Display for GliumCreationError<T> where T: std::error::Error {
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
let self_error = self as &std::error::Error;
formatter.write_str(self_error.description())
}
}
impl<T> std::error::Error for GliumCreationError<T> where T: std::error::Error {
fn description(&self) -> &str {
match self {
&GliumCreationError::BackendCreationError(_) => "Error while creating the backend",
&GliumCreationError::IncompatibleOpenGl(_) => "The OpenGL implementation is too old to work with glium",
}
}
fn cause(&self) -> Option<&std::error::Error> {
match self {
&GliumCreationError::BackendCreationError(ref err) => Some(err as &std::error::Error),
&GliumCreationError::IncompatibleOpenGl(_) => None,
}
}
}
impl<T> std::convert::From<T> for GliumCreationError<T> {
fn from(err: T) -> GliumCreationError<T> {
GliumCreationError::BackendCreationError(err)
}
}
#[allow(dead_code)]
fn get_gl_error(ctxt: &mut context::CommandContext) -> Option<&'static str> {
match unsafe { ctxt.gl.GetError() } {
gl::NO_ERROR => None,
gl::INVALID_ENUM => Some("GL_INVALID_ENUM"),
gl::INVALID_VALUE => Some("GL_INVALID_VALUE"),
gl::INVALID_OPERATION => Some("GL_INVALID_OPERATION"),
gl::INVALID_FRAMEBUFFER_OPERATION => Some("GL_INVALID_FRAMEBUFFER_OPERATION"),
gl::OUT_OF_MEMORY => Some("GL_OUT_OF_MEMORY"),
gl::STACK_UNDERFLOW => Some("GL_STACK_UNDERFLOW"),
gl::STACK_OVERFLOW => Some("GL_STACK_OVERFLOW"),
gl::CONTEXT_LOST => Some("GL_CONTEXT_LOST"),
_ => Some("Unknown glGetError return value")
}
}