1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
use crate::gl::consts; use crate::gl::Gl; #[derive(PartialEq)] pub enum BlendType { None, SrcAlphaOneMinusSrcAlpha, DstAlphaOneMinusDstAlpha, OneOne } pub fn blend(gl: &Gl, blend_type: BlendType) { unsafe { static mut CURRENT: BlendType = BlendType::None; if blend_type != CURRENT { match blend_type { BlendType::None => { gl.disable(consts::BLEND); }, BlendType::SrcAlphaOneMinusSrcAlpha => { gl.enable(consts::BLEND); gl.blend_func(consts::SRC_ALPHA, consts::ONE_MINUS_SRC_ALPHA); }, BlendType::DstAlphaOneMinusDstAlpha => { gl.enable(consts::BLEND); gl.blend_func(consts::DST_ALPHA, consts::ONE_MINUS_DST_ALPHA); }, BlendType::OneOne => { gl.enable(consts::BLEND); gl.blend_func(consts::ONE, consts::ONE); } } CURRENT = blend_type; } } } #[derive(PartialEq)] pub enum CullType { None, Back, Front, FrontAndBack } pub fn cull(gl: &Gl, cull_type: CullType) { unsafe { static mut CURRENT: CullType = CullType::None; if cull_type != CURRENT { match cull_type { CullType::None => { gl.disable(consts::CULL_FACE); }, CullType::Back => { gl.enable(consts::CULL_FACE); gl.cull_face(consts::BACK); }, CullType::Front => { gl.enable(consts::CULL_FACE); gl.cull_face(consts::FRONT); }, CullType::FrontAndBack => { gl.enable(consts::CULL_FACE); gl.cull_face(consts::FRONT_AND_BACK); } } CURRENT = cull_type; } } } #[derive(PartialEq)] pub enum DepthTestType { None, Never, Less, Equal, LessOrEqual, Greater, NotEqual, GreaterOrEqual, Always } pub fn depth_test(gl: &Gl, depth_test_type: DepthTestType) { unsafe { static mut CURRENT: DepthTestType = DepthTestType::None; if depth_test_type != CURRENT { if depth_test_type == DepthTestType::None { gl.disable(consts::DEPTH_TEST); } else { gl.enable(consts::DEPTH_TEST); } match depth_test_type { DepthTestType::Never => { gl.depth_func(consts::NEVER); }, DepthTestType::Less => { gl.depth_func(consts::LESS); }, DepthTestType::Equal => { gl.depth_func(consts::EQUAL); }, DepthTestType::LessOrEqual => { gl.depth_func(consts::LEQUAL); }, DepthTestType::Greater => { gl.depth_func(consts::GREATER); }, DepthTestType::NotEqual => { gl.depth_func(consts::NOTEQUAL); }, DepthTestType::GreaterOrEqual => { gl.depth_func(consts::GEQUAL); }, DepthTestType::Always => { gl.depth_func(consts::ALWAYS); }, DepthTestType::None => {} } CURRENT = depth_test_type; } } } pub fn depth_write(gl: &Gl, enable: bool) { unsafe { static mut CURRENTLY_ENABLED: bool = true; if enable != CURRENTLY_ENABLED { gl.depth_mask(enable); CURRENTLY_ENABLED = enable; } } }