core_video/
opengl_texture.rs1use core_foundation::{
2 base::{Boolean, CFTypeID, TCFType},
3 declare_TCFType, impl_CFTypeDescription, impl_TCFType,
4};
5
6use crate::{
7 buffer::TCVBuffer,
8 image_buffer::{CVImageBufferRef, TCVImageBuffer},
9 GLenum, GLuint,
10};
11
12pub type CVOpenGLTextureRef = CVImageBufferRef;
13
14extern "C" {
15 pub fn CVOpenGLTextureGetTypeID() -> CFTypeID;
16 pub fn CVOpenGLTextureRetain(texture: CVOpenGLTextureRef) -> CVOpenGLTextureRef;
17 pub fn CVOpenGLTextureRelease(texture: CVOpenGLTextureRef);
18 pub fn CVOpenGLTextureGetTarget(image: CVOpenGLTextureRef) -> GLenum;
19 pub fn CVOpenGLTextureGetName(image: CVOpenGLTextureRef) -> GLuint;
20 pub fn CVOpenGLTextureIsFlipped(image: CVOpenGLTextureRef) -> Boolean;
21 pub fn CVOpenGLTextureGetCleanTexCoords(
22 image: CVOpenGLTextureRef,
23 lowerLeft: *mut f32,
24 lowerRight: *mut f32,
25 upperRight: *mut f32,
26 upperLeft: *mut f32,
27 );
28}
29
30declare_TCFType!(CVOpenGLTexture, CVOpenGLTextureRef);
31impl_TCFType!(CVOpenGLTexture, CVOpenGLTextureRef, CVOpenGLTextureGetTypeID);
32impl_CFTypeDescription!(CVOpenGLTexture);
33
34impl TCVBuffer for CVOpenGLTexture {}
35impl TCVImageBuffer for CVOpenGLTexture {}
36
37impl CVOpenGLTexture {
38 #[inline]
39 pub fn get_target(&self) -> GLenum {
40 unsafe { CVOpenGLTextureGetTarget(self.as_concrete_TypeRef()) }
41 }
42
43 #[inline]
44 pub fn get_name(&self) -> GLuint {
45 unsafe { CVOpenGLTextureGetName(self.as_concrete_TypeRef()) }
46 }
47
48 #[inline]
49 pub fn is_flipped(&self) -> bool {
50 unsafe { CVOpenGLTextureIsFlipped(self.as_concrete_TypeRef()) != 0 }
51 }
52
53 #[inline]
54 pub fn get_clean_tex_coords(&self) -> (f32, f32, f32, f32) {
55 let mut lower_left = 0.0;
56 let mut lower_right = 0.0;
57 let mut upper_right = 0.0;
58 let mut upper_left = 0.0;
59 unsafe {
60 CVOpenGLTextureGetCleanTexCoords(self.as_concrete_TypeRef(), &mut lower_left, &mut lower_right, &mut upper_right, &mut upper_left);
61 }
62 (lower_left, lower_right, upper_right, upper_left)
63 }
64}