use Handle;
use gl;
use smallvec::SmallVec;
pub struct GlState {
pub lost_context: bool,
pub enabled_blend: bool,
pub enabled_cull_face: bool,
pub enabled_debug_output: Option<bool>,
pub enabled_debug_output_synchronous: bool,
pub enabled_depth_test: bool,
pub enabled_depth_clamp_near: bool,
pub enabled_depth_clamp_far: bool,
pub enabled_dither: bool,
pub enabled_framebuffer_srgb: bool,
pub enabled_multisample: bool,
pub enabled_polygon_offset_fill: bool,
pub enabled_primitive_fixed_restart: bool,
pub enabled_rasterizer_discard: bool,
pub enabled_sample_alpha_to_coverage: bool,
pub enabled_sample_coverage: bool,
pub enabled_scissor_test: bool,
pub enabled_stencil_test: bool,
pub enabled_line_smooth: bool,
pub enabled_polygon_smooth: bool,
pub enabled_program_point_size: bool,
pub enabled_clip_planes: gl::types::GLuint,
pub program: Handle,
pub vertex_array: gl::types::GLuint,
pub clear_color: (gl::types::GLclampf, gl::types::GLclampf,
gl::types::GLclampf, gl::types::GLclampf),
pub clear_depth: gl::types::GLclampf,
pub clear_stencil: gl::types::GLint,
pub color_mask: (gl::types::GLboolean, gl::types::GLboolean,
gl::types::GLboolean, gl::types::GLboolean),
pub array_buffer_binding: gl::types::GLuint,
pub pixel_pack_buffer_binding: gl::types::GLuint,
pub pixel_unpack_buffer_binding: gl::types::GLuint,
pub uniform_buffer_binding: gl::types::GLuint,
pub indexed_uniform_buffer_bindings: SmallVec<[IndexedBufferState ; 8]>,
pub copy_read_buffer_binding: gl::types::GLuint,
pub copy_write_buffer_binding: gl::types::GLuint,
pub dispatch_indirect_buffer_binding: gl::types::GLuint,
pub draw_indirect_buffer_binding: gl::types::GLuint,
pub query_buffer_binding: gl::types::GLuint,
pub texture_buffer_binding: gl::types::GLuint,
pub atomic_counter_buffer_binding: gl::types::GLuint,
pub indexed_atomic_counter_buffer_bindings: SmallVec<[IndexedBufferState ; 8]>,
pub shader_storage_buffer_binding: gl::types::GLuint,
pub indexed_shader_storage_buffer_bindings: SmallVec<[IndexedBufferState ; 8]>,
pub indexed_transform_feedback_buffer_bindings: SmallVec<[IndexedBufferState; 4]>,
pub read_framebuffer: gl::types::GLuint,
pub draw_framebuffer: gl::types::GLuint,
pub default_framebuffer_read: Option<gl::types::GLenum>,
pub renderbuffer: gl::types::GLuint,
pub blend_equation: (gl::types::GLenum, gl::types::GLenum),
pub blend_func: (gl::types::GLenum, gl::types::GLenum,
gl::types::GLenum, gl::types::GLenum),
pub blend_color: (gl::types::GLclampf, gl::types::GLclampf,
gl::types::GLclampf, gl::types::GLclampf),
pub depth_func: gl::types::GLenum,
pub depth_mask: bool,
pub depth_range: (f32, f32),
pub stencil_func_front: (gl::types::GLenum, gl::types::GLint, gl::types::GLuint),
pub stencil_func_back: (gl::types::GLenum, gl::types::GLint, gl::types::GLuint),
pub stencil_mask_front: gl::types::GLuint,
pub stencil_mask_back: gl::types::GLuint,
pub stencil_op_front: (gl::types::GLenum, gl::types::GLenum, gl::types::GLenum),
pub stencil_op_back: (gl::types::GLenum, gl::types::GLenum, gl::types::GLenum),
pub viewport: Option<(gl::types::GLint, gl::types::GLint,
gl::types::GLsizei, gl::types::GLsizei)>,
pub scissor: Option<(gl::types::GLint, gl::types::GLint,
gl::types::GLsizei, gl::types::GLsizei)>,
pub line_width: gl::types::GLfloat,
pub point_size: gl::types::GLfloat,
pub cull_face: gl::types::GLenum,
pub polygon_mode: gl::types::GLenum,
pub smooth: (gl::types::GLenum, gl::types::GLenum),
pub provoking_vertex: gl::types::GLenum,
pub pixel_store_unpack_alignment: gl::types::GLint,
pub pixel_store_pack_alignment: gl::types::GLint,
pub clamp_color: gl::types::GLenum,
pub patch_patch_vertices: gl::types::GLint,
pub active_texture: gl::types::GLenum,
pub texture_units: SmallVec<[TextureUnitState ; 32]>,
pub samples_passed_query: gl::types::GLuint,
pub any_samples_passed_query: gl::types::GLuint,
pub any_samples_passed_conservative_query: gl::types::GLuint,
pub primitives_generated_query: gl::types::GLuint,
pub transform_feedback_primitives_written_query: gl::types::GLuint,
pub time_elapsed_query: gl::types::GLuint,
pub conditional_render: Option<(gl::types::GLuint, gl::types::GLenum)>,
pub transform_feedback_enabled: Option<gl::types::GLenum>,
pub transform_feedback_paused: bool,
pub primitive_bounding_box: (f32, f32, f32, f32, f32, f32, f32, f32),
pub next_draw_call_id: u64,
pub latest_memory_barrier_vertex_attrib_array: u64,
pub latest_memory_barrier_element_array: u64,
pub latest_memory_barrier_uniform: u64,
pub latest_memory_barrier_texture_fetch: u64,
pub latest_memory_barrier_shader_image_access: u64,
pub latest_memory_barrier_command: u64,
pub latest_memory_barrier_pixel_buffer: u64,
pub latest_memory_barrier_texture_update: u64,
pub latest_memory_barrier_buffer_update: u64,
pub latest_memory_barrier_framebuffer: u64,
pub latest_memory_barrier_transform_feedback: u64,
pub latest_memory_barrier_atomic_counter: u64,
pub latest_memory_barrier_shader_storage: u64,
pub latest_memory_barrier_query_buffer: u64,
}
#[derive(Copy, Clone, Debug)]
pub struct TextureUnitState {
pub texture: gl::types::GLuint,
pub sampler: gl::types::GLuint,
}
#[derive(Copy, Clone, Debug)]
pub struct IndexedBufferState {
pub buffer: gl::types::GLuint,
pub offset: gl::types::GLintptr,
pub size: gl::types::GLsizeiptr,
}
impl Default for GlState {
fn default() -> GlState {
fn small_vec_one<T>() -> SmallVec<T> where T: ::smallvec::Array, T::Item: Default {
let mut v = SmallVec::new();
v.push(Default::default());
v
}
GlState {
lost_context: false,
enabled_blend: false,
enabled_cull_face: false,
enabled_debug_output: None,
enabled_debug_output_synchronous: false,
enabled_depth_test: false,
enabled_depth_clamp_near: false,
enabled_depth_clamp_far: false,
enabled_dither: false,
enabled_framebuffer_srgb: false,
enabled_multisample: true,
enabled_polygon_offset_fill: false,
enabled_rasterizer_discard: false,
enabled_sample_alpha_to_coverage: false,
enabled_sample_coverage: false,
enabled_scissor_test: false,
enabled_stencil_test: false,
enabled_line_smooth: false,
enabled_polygon_smooth: false,
enabled_primitive_fixed_restart: false,
enabled_program_point_size: false,
enabled_clip_planes: 0,
program: Handle::Id(0),
vertex_array: 0,
clear_color: (0.0, 0.0, 0.0, 0.0),
clear_depth: 1.0,
clear_stencil: 0,
color_mask: (1, 1, 1, 1),
array_buffer_binding: 0,
pixel_pack_buffer_binding: 0,
pixel_unpack_buffer_binding: 0,
uniform_buffer_binding: 0,
indexed_uniform_buffer_bindings: small_vec_one(),
copy_read_buffer_binding: 0,
copy_write_buffer_binding: 0,
dispatch_indirect_buffer_binding: 0,
draw_indirect_buffer_binding: 0,
query_buffer_binding: 0,
texture_buffer_binding: 0,
atomic_counter_buffer_binding: 0,
indexed_atomic_counter_buffer_bindings: small_vec_one(),
shader_storage_buffer_binding: 0,
indexed_shader_storage_buffer_bindings: small_vec_one(),
indexed_transform_feedback_buffer_bindings: small_vec_one(),
read_framebuffer: 0,
draw_framebuffer: 0,
default_framebuffer_read: None,
renderbuffer: 0,
depth_func: gl::LESS,
depth_mask: true,
depth_range: (0.0, 1.0),
stencil_func_front: (gl::ALWAYS, 0, 0xffffffff),
stencil_func_back: (gl::ALWAYS, 0, 0xffffffff),
stencil_mask_front: 0xffffffff,
stencil_mask_back: 0xffffffff,
stencil_op_front: (gl::KEEP, gl::KEEP, gl::KEEP),
stencil_op_back: (gl::KEEP, gl::KEEP, gl::KEEP),
blend_equation: (gl::FUNC_ADD, gl::FUNC_ADD),
blend_func: (gl::ONE, gl::ZERO, gl::ONE, gl::ZERO),
blend_color: (0.0, 0.0, 0.0, 0.0),
viewport: None,
scissor: None,
line_width: 1.0,
point_size: 1.0,
cull_face: gl::BACK,
polygon_mode: gl::FILL,
smooth: (gl::DONT_CARE, gl::DONT_CARE),
provoking_vertex: gl::LAST_VERTEX_CONVENTION,
pixel_store_unpack_alignment: 4,
pixel_store_pack_alignment: 4,
clamp_color: gl::FIXED_ONLY,
patch_patch_vertices: 3,
active_texture: 0,
texture_units: small_vec_one(),
samples_passed_query: 0,
any_samples_passed_query: 0,
any_samples_passed_conservative_query: 0,
primitives_generated_query: 0,
transform_feedback_primitives_written_query: 0,
time_elapsed_query: 0,
conditional_render: None,
transform_feedback_enabled: None,
transform_feedback_paused: false,
primitive_bounding_box: (-1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0),
next_draw_call_id: 1,
latest_memory_barrier_vertex_attrib_array: 1,
latest_memory_barrier_element_array: 1,
latest_memory_barrier_uniform: 1,
latest_memory_barrier_texture_fetch: 1,
latest_memory_barrier_shader_image_access: 1,
latest_memory_barrier_command: 1,
latest_memory_barrier_pixel_buffer: 1,
latest_memory_barrier_texture_update: 1,
latest_memory_barrier_buffer_update: 1,
latest_memory_barrier_framebuffer: 1,
latest_memory_barrier_transform_feedback: 1,
latest_memory_barrier_atomic_counter: 1,
latest_memory_barrier_shader_storage: 1,
latest_memory_barrier_query_buffer: 1,
}
}
}
impl Default for TextureUnitState {
#[inline]
fn default() -> TextureUnitState {
TextureUnitState {
texture: 0,
sampler: 0,
}
}
}
impl Default for IndexedBufferState {
#[inline]
fn default() -> IndexedBufferState {
IndexedBufferState {
buffer: 0,
offset: 0,
size: 0,
}
}
}