1#![allow(clippy::too_many_arguments)]
7
8use crate::{gl, Error, GLchar, GLeglImageOES, GLenum, GLint, GLsizei, GLuint};
9use std::ffi::CStr;
10
11pub fn active_texture(texture: GLenum) {
13 unsafe { gl::ActiveTexture(texture) }
14}
15
16pub fn bind_texture(target: GLenum, texture: GLuint) {
18 unsafe { gl::BindTexture(target, texture) }
19}
20
21pub fn blend_func_separate(
23 sfactor_rgb: GLenum,
24 dfactor_rgb: GLenum,
25 sfactor_alpha: GLenum,
26 dfactor_alpha: GLenum,
27) {
28 unsafe { gl::BlendFuncSeparate(sfactor_rgb, dfactor_rgb, sfactor_alpha, dfactor_alpha) }
29}
30
31pub fn disable(cap: GLenum) {
33 unsafe { gl::Disable(cap) }
34}
35
36#[allow(clippy::not_unsafe_ptr_arg_deref)]
40pub fn egl_image_target_texture_2d_oes(target: GLenum, image: GLeglImageOES) {
41 unsafe { gl::EGLImageTargetTexture2DOES(target, image) }
42}
43
44pub fn enable(cap: GLenum) {
46 unsafe { gl::Enable(cap) }
47}
48
49pub fn finish() {
51 unsafe { gl::Finish() }
52}
53
54pub fn get_string(name: GLenum) -> Result<String, Error> {
56 unsafe {
57 let name: *const GLchar = gl::GetString(name) as *const GLchar;
58 if name.is_null() {
59 Err(Error::new())
60 } else {
61 Ok(CStr::from_ptr(name).to_string_lossy().into_owned())
62 }
63 }
64}
65
66pub fn tex_image2d<T>(
68 target: GLenum,
69 level: GLint,
70 internalformat: GLint,
71 width: GLsizei,
72 height: GLsizei,
73 border: GLint,
74 format: GLenum,
75 type_: GLenum,
76 pixels: Option<&[T]>,
77) where
78 T: Sized,
79{
80 let ptr = match pixels {
81 Some(v) => v.as_ptr() as *const core::ffi::c_void,
82 None => std::ptr::null(),
83 };
84 unsafe {
85 gl::TexImage2D(
86 target,
87 level,
88 internalformat,
89 width,
90 height,
91 border,
92 format,
93 type_,
94 ptr,
95 );
96 }
97}
98
99pub fn tex_image3d<T>(
101 target: GLenum,
102 level: GLint,
103 internalformat: GLint,
104 width: GLsizei,
105 height: GLsizei,
106 depth: GLsizei,
107 border: GLint,
108 format: GLenum,
109 type_: GLenum,
110 pixels: Option<&[T]>,
111) where
112 T: Sized,
113{
114 let ptr = match pixels {
115 Some(v) => v.as_ptr() as *const core::ffi::c_void,
116 None => std::ptr::null(),
117 };
118 unsafe {
119 gl::TexImage3D(
120 target,
121 level,
122 internalformat,
123 width,
124 height,
125 depth,
126 border,
127 format,
128 type_,
129 ptr,
130 );
131 }
132}
133
134pub fn tex_parameteri(target: GLenum, pname: GLenum, param: GLint) {
136 unsafe {
137 gl::TexParameteri(target, pname, param);
138 }
139}
140
141pub fn use_program(program: GLuint) {
143 unsafe {
144 gl::UseProgram(program);
145 }
146}