swgl_fns.rs (62786B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 #![allow(unused_variables)] 5 6 use gleam::gl::*; 7 use std::ffi::{CStr, CString}; 8 use std::os::raw::{c_char, c_int, c_void}; 9 use std::ptr; 10 use std::str; 11 12 #[allow(unused)] 13 macro_rules! debug { 14 ($($x:tt)*) => {}; 15 } 16 17 #[repr(C)] 18 struct LockedTexture { 19 _private: [u8; 0], 20 } 21 22 #[allow(dead_code)] 23 extern "C" { 24 fn ActiveTexture(texture: GLenum); 25 fn BindTexture(target: GLenum, texture: GLuint); 26 fn BindBuffer(target: GLenum, buffer: GLuint); 27 fn BindVertexArray(vao: GLuint); 28 fn BindFramebuffer(target: GLenum, fb: GLuint); 29 fn BindRenderbuffer(target: GLenum, rb: GLuint); 30 fn BlendFunc(srgb: GLenum, drgb: GLenum, sa: GLenum, da: GLenum); 31 fn BlendColor(r: GLfloat, g: GLfloat, b: GLfloat, a: GLfloat); 32 fn BlendEquation(mode: GLenum); 33 fn Enable(cap: GLenum); 34 fn Disable(cap: GLenum); 35 fn GenQueries(n: GLsizei, result: *mut GLuint); 36 fn BeginQuery(target: GLenum, id: GLuint); 37 fn EndQuery(target: GLenum); 38 fn GetQueryObjectui64v(id: GLuint, pname: GLenum, params: *mut GLuint64); 39 fn GenBuffers(n: i32, result: *mut GLuint); 40 fn GenTextures(n: i32, result: *mut GLuint); 41 fn GenFramebuffers(n: i32, result: *mut GLuint); 42 fn GenRenderbuffers(n: i32, result: *mut GLuint); 43 fn BufferData(target: GLenum, size: GLsizeiptr, data: *const GLvoid, usage: GLenum); 44 fn BufferSubData(target: GLenum, offset: GLintptr, size: GLsizeiptr, data: *const GLvoid); 45 fn MapBuffer(target: GLenum, access: GLbitfield) -> *mut c_void; 46 fn MapBufferRange( 47 target: GLenum, 48 offset: GLintptr, 49 length: GLsizeiptr, 50 access: GLbitfield, 51 ) -> *mut c_void; 52 fn UnmapBuffer(target: GLenum) -> GLboolean; 53 fn TexStorage2D( 54 target: GLenum, 55 levels: GLint, 56 internal_format: GLenum, 57 width: GLsizei, 58 height: GLsizei, 59 ); 60 fn FramebufferTexture2D( 61 target: GLenum, 62 attachment: GLenum, 63 textarget: GLenum, 64 texture: GLuint, 65 level: GLint, 66 ); 67 fn CheckFramebufferStatus(target: GLenum) -> GLenum; 68 fn InvalidateFramebuffer(target: GLenum, num_attachments: GLsizei, attachments: *const GLenum); 69 fn TexImage2D( 70 target: GLenum, 71 level: GLint, 72 internal_format: GLint, 73 width: GLsizei, 74 height: GLsizei, 75 border: GLint, 76 format: GLenum, 77 ty: GLenum, 78 data: *const c_void, 79 ); 80 fn TexSubImage2D( 81 target: GLenum, 82 level: GLint, 83 xoffset: GLint, 84 yoffset: GLint, 85 width: GLsizei, 86 height: GLsizei, 87 format: GLenum, 88 ty: GLenum, 89 data: *const c_void, 90 ); 91 fn GenerateMipmap(target: GLenum); 92 fn GetUniformLocation(program: GLuint, name: *const GLchar) -> GLint; 93 fn BindAttribLocation(program: GLuint, index: GLuint, name: *const GLchar); 94 fn GetAttribLocation(program: GLuint, name: *const GLchar) -> GLint; 95 fn GenVertexArrays(n: i32, result: *mut GLuint); 96 fn VertexAttribPointer( 97 index: GLuint, 98 size: GLint, 99 type_: GLenum, 100 normalized: GLboolean, 101 stride: GLsizei, 102 offset: *const GLvoid, 103 ); 104 fn VertexAttribIPointer( 105 index: GLuint, 106 size: GLint, 107 type_: GLenum, 108 stride: GLsizei, 109 offset: *const GLvoid, 110 ); 111 fn CreateShader(shader_type: GLenum) -> GLuint; 112 fn AttachShader(program: GLuint, shader: GLuint); 113 fn CreateProgram() -> GLuint; 114 fn Uniform1i(location: GLint, v0: GLint); 115 fn Uniform4fv(location: GLint, count: GLsizei, value: *const GLfloat); 116 fn UniformMatrix4fv( 117 location: GLint, 118 count: GLsizei, 119 transpose: GLboolean, 120 value: *const GLfloat, 121 ); 122 fn DrawElementsInstanced( 123 mode: GLenum, 124 count: GLsizei, 125 type_: GLenum, 126 indices: GLintptr, 127 instancecount: GLsizei, 128 ); 129 fn EnableVertexAttribArray(index: GLuint); 130 fn VertexAttribDivisor(index: GLuint, divisor: GLuint); 131 fn LinkProgram(program: GLuint); 132 fn GetLinkStatus(program: GLuint) -> GLint; 133 fn UseProgram(program: GLuint); 134 fn SetViewport(x: GLint, y: GLint, width: GLsizei, height: GLsizei); 135 fn FramebufferRenderbuffer( 136 target: GLenum, 137 attachment: GLenum, 138 renderbuffertarget: GLenum, 139 renderbuffer: GLuint, 140 ); 141 fn RenderbufferStorage(target: GLenum, internalformat: GLenum, width: GLsizei, height: GLsizei); 142 fn DepthMask(flag: GLboolean); 143 fn DepthFunc(func: GLenum); 144 fn SetScissor(x: GLint, y: GLint, width: GLsizei, height: GLsizei); 145 fn ClearColor(r: GLfloat, g: GLfloat, b: GLfloat, a: GLfloat); 146 fn ClearDepth(depth: GLdouble); 147 fn Clear(mask: GLbitfield); 148 fn ClearTexSubImage( 149 target: GLenum, 150 level: GLint, 151 xoffset: GLint, 152 yoffset: GLint, 153 zoffset: GLint, 154 width: GLsizei, 155 height: GLsizei, 156 depth: GLsizei, 157 format: GLenum, 158 ty: GLenum, 159 data: *const c_void, 160 ); 161 fn ClearTexImage(target: GLenum, level: GLint, format: GLenum, ty: GLenum, data: *const c_void); 162 fn ClearColorRect( 163 fbo: GLuint, 164 xoffset: GLint, 165 yoffset: GLint, 166 width: GLsizei, 167 height: GLsizei, 168 r: GLfloat, 169 g: GLfloat, 170 b: GLfloat, 171 a: GLfloat, 172 ); 173 fn PixelStorei(name: GLenum, param: GLint); 174 fn ReadPixels( 175 x: GLint, 176 y: GLint, 177 width: GLsizei, 178 height: GLsizei, 179 format: GLenum, 180 ty: GLenum, 181 data: *mut c_void, 182 ); 183 fn Finish(); 184 fn ShaderSourceByName(shader: GLuint, name: *const GLchar); 185 fn TexParameteri(target: GLenum, pname: GLenum, param: GLint); 186 fn CopyImageSubData( 187 src_name: GLuint, 188 src_target: GLenum, 189 src_level: GLint, 190 src_x: GLint, 191 src_y: GLint, 192 src_z: GLint, 193 dst_name: GLuint, 194 dst_target: GLenum, 195 dst_level: GLint, 196 dst_x: GLint, 197 dst_y: GLint, 198 dst_z: GLint, 199 src_width: GLsizei, 200 src_height: GLsizei, 201 src_depth: GLsizei, 202 ); 203 fn CopyTexSubImage2D( 204 target: GLenum, 205 level: GLint, 206 xoffset: GLint, 207 yoffset: GLint, 208 x: GLint, 209 y: GLint, 210 width: GLsizei, 211 height: GLsizei, 212 ); 213 fn BlitFramebuffer( 214 src_x0: GLint, 215 src_y0: GLint, 216 src_x1: GLint, 217 src_y1: GLint, 218 dst_x0: GLint, 219 dst_y0: GLint, 220 dst_x1: GLint, 221 dst_y1: GLint, 222 mask: GLbitfield, 223 filter: GLenum, 224 ); 225 fn GetIntegerv(pname: GLenum, params: *mut GLint); 226 fn GetBooleanv(pname: GLenum, params: *mut GLboolean); 227 fn GetString(name: GLenum) -> *const c_char; 228 fn GetStringi(name: GLenum, index: GLuint) -> *const c_char; 229 fn GetError() -> GLenum; 230 fn InitDefaultFramebuffer( 231 x: i32, 232 y: i32, 233 width: i32, 234 height: i32, 235 stride: i32, 236 buf: *mut c_void, 237 ); 238 fn GetColorBuffer( 239 fbo: GLuint, 240 flush: GLboolean, 241 width: *mut i32, 242 height: *mut i32, 243 stride: *mut i32, 244 ) -> *mut c_void; 245 fn ResolveFramebuffer(fbo: GLuint); 246 fn SetTextureBuffer( 247 tex: GLuint, 248 internal_format: GLenum, 249 width: GLsizei, 250 height: GLsizei, 251 stride: GLsizei, 252 buf: *mut c_void, 253 min_width: GLsizei, 254 min_height: GLsizei, 255 ); 256 fn SetTextureParameter(tex: GLuint, pname: GLenum, param: GLint); 257 fn DeleteTexture(n: GLuint); 258 fn DeleteRenderbuffer(n: GLuint); 259 fn DeleteFramebuffer(n: GLuint); 260 fn DeleteBuffer(n: GLuint); 261 fn DeleteVertexArray(n: GLuint); 262 fn DeleteQuery(n: GLuint); 263 fn DeleteShader(shader: GLuint); 264 fn DeleteProgram(program: GLuint); 265 fn LockFramebuffer(fbo: GLuint) -> *mut LockedTexture; 266 fn LockTexture(tex: GLuint) -> *mut LockedTexture; 267 fn LockResource(resource: *mut LockedTexture); 268 fn UnlockResource(resource: *mut LockedTexture) -> i32; 269 fn GetResourceBuffer( 270 resource: *mut LockedTexture, 271 width: *mut i32, 272 height: *mut i32, 273 stride: *mut i32, 274 ) -> *mut c_void; 275 fn Composite( 276 locked_dst: *mut LockedTexture, 277 locked_src: *mut LockedTexture, 278 src_x: GLint, 279 src_y: GLint, 280 src_width: GLsizei, 281 src_height: GLsizei, 282 dst_x: GLint, 283 dst_y: GLint, 284 dst_width: GLsizei, 285 dst_height: GLsizei, 286 opaque: GLboolean, 287 flip_x: GLboolean, 288 flip_y: GLboolean, 289 filter: GLenum, 290 clip_x: GLint, 291 clip_y: GLint, 292 clip_width: GLsizei, 293 clip_height: GLsizei, 294 ); 295 fn CompositeYUV( 296 locked_dst: *mut LockedTexture, 297 locked_y: *mut LockedTexture, 298 locked_u: *mut LockedTexture, 299 locked_v: *mut LockedTexture, 300 color_space: YuvRangedColorSpace, 301 color_depth: GLuint, 302 src_x: GLint, 303 src_y: GLint, 304 src_width: GLsizei, 305 src_height: GLsizei, 306 dst_x: GLint, 307 dst_y: GLint, 308 dst_width: GLsizei, 309 dst_height: GLsizei, 310 flip_x: GLboolean, 311 flip_y: GLboolean, 312 clip_x: GLint, 313 clip_y: GLint, 314 clip_width: GLsizei, 315 clip_height: GLsizei, 316 ); 317 fn ApplyMask( 318 locked_dst: *mut LockedTexture, 319 locked_mask: *mut LockedTexture, 320 ); 321 fn CreateContext() -> *mut c_void; 322 fn ReferenceContext(ctx: *mut c_void); 323 fn DestroyContext(ctx: *mut c_void); 324 fn MakeCurrent(ctx: *mut c_void); 325 fn ReportMemory(ctx: *mut c_void, size_of_op: unsafe extern "C" fn(ptr: *const c_void) -> usize) -> usize; 326 } 327 328 #[derive(Clone, Copy)] 329 pub struct Context(*mut c_void); 330 331 impl Context { 332 pub fn create() -> Self { 333 Context(unsafe { CreateContext() }) 334 } 335 336 pub fn reference(&self) { 337 unsafe { 338 ReferenceContext(self.0); 339 } 340 } 341 342 pub fn destroy(&self) { 343 unsafe { 344 DestroyContext(self.0); 345 } 346 } 347 348 pub fn make_current(&self) { 349 unsafe { 350 MakeCurrent(self.0); 351 } 352 } 353 354 pub fn init_default_framebuffer( 355 &self, 356 x: i32, 357 y: i32, 358 width: i32, 359 height: i32, 360 stride: i32, 361 buf: *mut c_void, 362 ) { 363 unsafe { 364 InitDefaultFramebuffer(x, y, width, height, stride, buf); 365 } 366 } 367 368 pub fn get_color_buffer(&self, fbo: GLuint, flush: bool) -> (*mut c_void, i32, i32, i32) { 369 unsafe { 370 let mut width: i32 = 0; 371 let mut height: i32 = 0; 372 let mut stride: i32 = 0; 373 let data_ptr = GetColorBuffer( 374 fbo, 375 flush as GLboolean, 376 &mut width, 377 &mut height, 378 &mut stride, 379 ); 380 (data_ptr, width, height, stride) 381 } 382 } 383 384 pub fn resolve_framebuffer(&self, fbo: GLuint) { 385 unsafe { 386 ResolveFramebuffer(fbo); 387 } 388 } 389 390 pub fn clear_color_rect( 391 &self, 392 fbo: GLuint, 393 xoffset: GLint, 394 yoffset: GLint, 395 width: GLsizei, 396 height: GLsizei, 397 r: f32, 398 g: f32, 399 b: f32, 400 a: f32, 401 ) { 402 unsafe { 403 ClearColorRect(fbo, xoffset, yoffset, width, height, r, g, b, a); 404 } 405 } 406 407 pub fn set_texture_buffer( 408 &self, 409 tex: GLuint, 410 internal_format: GLenum, 411 width: GLsizei, 412 height: GLsizei, 413 stride: GLsizei, 414 buf: *mut c_void, 415 min_width: GLsizei, 416 min_height: GLsizei, 417 ) { 418 unsafe { 419 SetTextureBuffer( 420 tex, 421 internal_format, 422 width, 423 height, 424 stride, 425 buf, 426 min_width, 427 min_height, 428 ); 429 } 430 } 431 432 pub fn set_texture_parameter(&self, tex: GLuint, pname: GLenum, param: GLint) { 433 unsafe { 434 SetTextureParameter(tex, pname, param); 435 } 436 } 437 438 pub fn lock_framebuffer(&self, fbo: GLuint) -> Option<LockedResource> { 439 unsafe { 440 let resource = LockFramebuffer(fbo); 441 if !resource.is_null() { 442 Some(LockedResource(resource)) 443 } else { 444 None 445 } 446 } 447 } 448 449 pub fn lock_texture(&self, tex: GLuint) -> Option<LockedResource> { 450 unsafe { 451 let resource = LockTexture(tex); 452 if !resource.is_null() { 453 Some(LockedResource(resource)) 454 } else { 455 None 456 } 457 } 458 } 459 460 pub fn report_memory(&self, size_of_op: unsafe extern "C" fn(ptr: *const c_void) -> usize) -> usize { 461 unsafe { ReportMemory(self.0, size_of_op) } 462 } 463 } 464 465 impl From<*mut c_void> for Context { 466 fn from(ptr: *mut c_void) -> Self { 467 Context(ptr) 468 } 469 } 470 471 impl From<Context> for *mut c_void { 472 fn from(ctx: Context) -> Self { 473 ctx.0 474 } 475 } 476 477 fn calculate_length(width: GLsizei, height: GLsizei, format: GLenum, pixel_type: GLenum) -> usize { 478 let colors = match format { 479 RED => 1, 480 RGB => 3, 481 BGR => 3, 482 483 RGBA => 4, 484 BGRA => 4, 485 486 ALPHA => 1, 487 R16 => 1, 488 LUMINANCE => 1, 489 DEPTH_COMPONENT => 1, 490 _ => panic!("unsupported format for read_pixels: {:?}", format), 491 }; 492 let depth = match pixel_type { 493 UNSIGNED_BYTE => 1, 494 UNSIGNED_SHORT => 2, 495 SHORT => 2, 496 FLOAT => 4, 497 UNSIGNED_INT_8_8_8_8_REV => 1, 498 _ => panic!("unsupported pixel_type for read_pixels: {:?}", pixel_type), 499 }; 500 501 (width * height * colors * depth) as usize 502 } 503 504 impl Gl for Context { 505 fn get_type(&self) -> GlType { 506 GlType::Gl 507 } 508 509 fn buffer_data_untyped( 510 &self, 511 target: GLenum, 512 size: GLsizeiptr, 513 data: *const GLvoid, 514 usage: GLenum, 515 ) { 516 debug!( 517 "buffer_data_untyped {} {} {:?} {}", 518 target, size, data, usage 519 ); 520 //panic!(); 521 unsafe { 522 BufferData(target, size, data, usage); 523 } 524 } 525 526 fn buffer_sub_data_untyped( 527 &self, 528 target: GLenum, 529 offset: isize, 530 size: GLsizeiptr, 531 data: *const GLvoid, 532 ) { 533 debug!( 534 "buffer_sub_data_untyped {} {} {} {:?}", 535 target, offset, size, data 536 ); 537 //panic!(); 538 unsafe { 539 BufferSubData(target, offset, size, data); 540 } 541 } 542 543 fn map_buffer(&self, target: GLenum, access: GLbitfield) -> *mut c_void { 544 unsafe { MapBuffer(target, access) } 545 } 546 547 fn map_buffer_range( 548 &self, 549 target: GLenum, 550 offset: GLintptr, 551 length: GLsizeiptr, 552 access: GLbitfield, 553 ) -> *mut c_void { 554 unsafe { MapBufferRange(target, offset, length, access) } 555 } 556 557 fn unmap_buffer(&self, target: GLenum) -> GLboolean { 558 unsafe { UnmapBuffer(target) } 559 } 560 561 fn shader_source(&self, shader: GLuint, strings: &[&[u8]]) { 562 //panic!(); 563 debug!("shader_source {}", shader); 564 //for s in strings { 565 // debug!("{}", str::from_utf8(s).unwrap()); 566 //} 567 //panic!(); 568 for s in strings { 569 let u = str::from_utf8(s).unwrap(); 570 const PREFIX: &str = "// shader: "; 571 if let Some(start) = u.find(PREFIX) { 572 if let Some(end) = u[start..].find('\n') { 573 let name = u[start + PREFIX.len()..start + end].trim(); 574 debug!("shader name: {}", name); 575 unsafe { 576 let c_string = CString::new(name).unwrap(); 577 ShaderSourceByName(shader, c_string.as_ptr()); 578 return; 579 } 580 } 581 } 582 } 583 panic!("unknown shader"); 584 } 585 586 fn tex_buffer(&self, target: GLenum, internal_format: GLenum, buffer: GLuint) { 587 panic!(); 588 } 589 590 fn read_buffer(&self, mode: GLenum) { 591 panic!(); 592 } 593 594 fn read_pixels_into_buffer( 595 &self, 596 x: GLint, 597 y: GLint, 598 width: GLsizei, 599 height: GLsizei, 600 format: GLenum, 601 pixel_type: GLenum, 602 dst_buffer: &mut [u8], 603 ) { 604 // Assumes that the user properly allocated the size for dst_buffer. 605 assert!(calculate_length(width, height, format, pixel_type) == dst_buffer.len()); 606 607 unsafe { 608 ReadPixels( 609 x, 610 y, 611 width, 612 height, 613 format, 614 pixel_type, 615 dst_buffer.as_mut_ptr() as *mut c_void, 616 ); 617 } 618 } 619 620 fn read_pixels( 621 &self, 622 x: GLint, 623 y: GLint, 624 width: GLsizei, 625 height: GLsizei, 626 format: GLenum, 627 pixel_type: GLenum, 628 ) -> Vec<u8> { 629 let len = calculate_length(width, height, format, pixel_type); 630 let mut pixels: Vec<u8> = Vec::new(); 631 pixels.reserve(len); 632 unsafe { 633 pixels.set_len(len); 634 } 635 636 self.read_pixels_into_buffer( 637 x, 638 y, 639 width, 640 height, 641 format, 642 pixel_type, 643 pixels.as_mut_slice(), 644 ); 645 646 pixels 647 } 648 649 unsafe fn read_pixels_into_pbo( 650 &self, 651 x: GLint, 652 y: GLint, 653 width: GLsizei, 654 height: GLsizei, 655 format: GLenum, 656 pixel_type: GLenum, 657 ) { 658 ReadPixels(x, y, width, height, format, pixel_type, ptr::null_mut()); 659 } 660 661 fn sample_coverage(&self, value: GLclampf, invert: bool) { 662 panic!(); 663 } 664 665 fn polygon_offset(&self, factor: GLfloat, units: GLfloat) { 666 panic!(); 667 } 668 669 fn pixel_store_i(&self, name: GLenum, param: GLint) { 670 //panic!(); 671 debug!("pixel_store_i {:x} {}", name, param); 672 unsafe { 673 PixelStorei(name, param); 674 } 675 } 676 677 fn gen_buffers(&self, n: GLsizei) -> Vec<GLuint> { 678 //panic!(); 679 let mut result = vec![0 as GLuint; n as usize]; 680 unsafe { 681 GenBuffers(n, result.as_mut_ptr()); 682 } 683 result 684 } 685 686 fn gen_renderbuffers(&self, n: GLsizei) -> Vec<GLuint> { 687 debug!("gen_renderbuffers {}", n); 688 //panic!(); 689 let mut result = vec![0 as GLuint; n as usize]; 690 unsafe { 691 GenRenderbuffers(n, result.as_mut_ptr()); 692 } 693 result 694 } 695 696 fn gen_framebuffers(&self, n: GLsizei) -> Vec<GLuint> { 697 //panic!(); 698 debug!("gen_framebuffers {}", n); 699 let mut result = vec![0 as GLuint; n as usize]; 700 unsafe { 701 GenFramebuffers(n, result.as_mut_ptr()); 702 } 703 result 704 } 705 706 fn gen_textures(&self, n: GLsizei) -> Vec<GLuint> { 707 //panic!(); 708 let mut result = vec![0 as GLuint; n as usize]; 709 unsafe { 710 GenTextures(n, result.as_mut_ptr()); 711 } 712 result 713 } 714 715 fn gen_vertex_arrays(&self, n: GLsizei) -> Vec<GLuint> { 716 //panic!(); 717 let mut result = vec![0 as GLuint; n as usize]; 718 unsafe { 719 GenVertexArrays(n, result.as_mut_ptr()); 720 } 721 result 722 } 723 724 fn gen_vertex_arrays_apple(&self, n: GLsizei) -> Vec<GLuint> { 725 self.gen_vertex_arrays(n) 726 } 727 728 fn gen_queries(&self, n: GLsizei) -> Vec<GLuint> { 729 let mut result = vec![0 as GLuint; n as usize]; 730 unsafe { 731 GenQueries(n, result.as_mut_ptr()); 732 } 733 result 734 } 735 736 fn begin_query(&self, target: GLenum, id: GLuint) { 737 unsafe { 738 BeginQuery(target, id); 739 } 740 } 741 742 fn end_query(&self, target: GLenum) { 743 unsafe { 744 EndQuery(target); 745 } 746 } 747 748 fn query_counter(&self, id: GLuint, target: GLenum) { 749 panic!(); 750 } 751 752 fn get_query_object_iv(&self, id: GLuint, pname: GLenum) -> i32 { 753 panic!(); 754 //0 755 } 756 757 fn get_query_object_uiv(&self, id: GLuint, pname: GLenum) -> u32 { 758 panic!(); 759 //0 760 } 761 762 fn get_query_object_i64v(&self, id: GLuint, pname: GLenum) -> i64 { 763 panic!(); 764 //0 765 } 766 767 fn get_query_object_ui64v(&self, id: GLuint, pname: GLenum) -> u64 { 768 let mut result = 0; 769 unsafe { 770 GetQueryObjectui64v(id, pname, &mut result); 771 } 772 result 773 } 774 775 fn delete_queries(&self, queries: &[GLuint]) { 776 unsafe { 777 for q in queries { 778 DeleteQuery(*q); 779 } 780 } 781 } 782 783 fn delete_vertex_arrays(&self, vertex_arrays: &[GLuint]) { 784 unsafe { 785 for v in vertex_arrays { 786 DeleteVertexArray(*v); 787 } 788 } 789 } 790 791 fn delete_vertex_arrays_apple(&self, vertex_arrays: &[GLuint]) { 792 self.delete_vertex_arrays(vertex_arrays) 793 } 794 795 fn delete_buffers(&self, buffers: &[GLuint]) { 796 unsafe { 797 for b in buffers { 798 DeleteBuffer(*b); 799 } 800 } 801 } 802 803 fn delete_renderbuffers(&self, renderbuffers: &[GLuint]) { 804 unsafe { 805 for r in renderbuffers { 806 DeleteRenderbuffer(*r); 807 } 808 } 809 } 810 811 fn delete_framebuffers(&self, framebuffers: &[GLuint]) { 812 unsafe { 813 for f in framebuffers { 814 DeleteFramebuffer(*f); 815 } 816 } 817 } 818 819 fn delete_textures(&self, textures: &[GLuint]) { 820 unsafe { 821 for t in textures { 822 DeleteTexture(*t); 823 } 824 } 825 } 826 827 fn framebuffer_renderbuffer( 828 &self, 829 target: GLenum, 830 attachment: GLenum, 831 renderbuffertarget: GLenum, 832 renderbuffer: GLuint, 833 ) { 834 debug!( 835 "framebufer_renderbuffer {} {} {} {}", 836 target, attachment, renderbuffertarget, renderbuffer 837 ); 838 //panic!(); 839 unsafe { 840 FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer); 841 } 842 } 843 844 fn renderbuffer_storage( 845 &self, 846 target: GLenum, 847 internalformat: GLenum, 848 width: GLsizei, 849 height: GLsizei, 850 ) { 851 debug!( 852 "renderbuffer_storage {} {} {} {}", 853 target, internalformat, width, height 854 ); 855 //panic!(); 856 unsafe { 857 RenderbufferStorage(target, internalformat, width, height); 858 } 859 } 860 861 fn depth_func(&self, func: GLenum) { 862 debug!("depth_func {}", func); 863 //panic!(); 864 unsafe { 865 DepthFunc(func); 866 } 867 } 868 869 fn active_texture(&self, texture: GLenum) { 870 //panic!(); 871 unsafe { 872 ActiveTexture(texture); 873 } 874 } 875 876 fn attach_shader(&self, program: GLuint, shader: GLuint) { 877 debug!("attach shader {} {}", program, shader); 878 //panic!(); 879 unsafe { 880 AttachShader(program, shader); 881 } 882 } 883 884 fn bind_attrib_location(&self, program: GLuint, index: GLuint, name: &str) { 885 debug!("bind_attrib_location {} {} {}", program, index, name); 886 //panic!(); 887 let c_string = CString::new(name).unwrap(); 888 unsafe { BindAttribLocation(program, index, c_string.as_ptr()) } 889 } 890 891 // https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glGetUniform.xml 892 unsafe fn get_uniform_iv(&self, program: GLuint, location: GLint, result: &mut [GLint]) { 893 panic!(); 894 //assert!(!result.is_empty()); 895 } 896 897 // https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glGetUniform.xml 898 unsafe fn get_uniform_fv(&self, program: GLuint, location: GLint, result: &mut [GLfloat]) { 899 panic!(); 900 //assert!(!result.is_empty()); 901 } 902 903 fn get_uniform_block_index(&self, program: GLuint, name: &str) -> GLuint { 904 panic!(); 905 //0 906 } 907 908 fn get_uniform_indices(&self, program: GLuint, names: &[&str]) -> Vec<GLuint> { 909 panic!(); 910 //Vec::new() 911 } 912 913 fn bind_buffer_base(&self, target: GLenum, index: GLuint, buffer: GLuint) { 914 panic!(); 915 } 916 917 fn bind_buffer_range( 918 &self, 919 target: GLenum, 920 index: GLuint, 921 buffer: GLuint, 922 offset: GLintptr, 923 size: GLsizeiptr, 924 ) { 925 panic!(); 926 } 927 928 fn uniform_block_binding( 929 &self, 930 program: GLuint, 931 uniform_block_index: GLuint, 932 uniform_block_binding: GLuint, 933 ) { 934 panic!(); 935 } 936 937 fn bind_buffer(&self, target: GLenum, buffer: GLuint) { 938 //panic!(); 939 unsafe { 940 BindBuffer(target, buffer); 941 } 942 } 943 944 fn bind_vertex_array(&self, vao: GLuint) { 945 //panic!(); 946 unsafe { 947 BindVertexArray(vao); 948 } 949 } 950 951 fn bind_vertex_array_apple(&self, vao: GLuint) { 952 self.bind_vertex_array(vao) 953 } 954 955 fn bind_renderbuffer(&self, target: GLenum, renderbuffer: GLuint) { 956 debug!("bind_renderbuffer {} {}", target, renderbuffer); 957 //panic!(); 958 unsafe { 959 BindRenderbuffer(target, renderbuffer); 960 } 961 } 962 963 fn bind_framebuffer(&self, target: GLenum, framebuffer: GLuint) { 964 debug!("bind_framebuffer {} {}", target, framebuffer); 965 //panic!(); 966 unsafe { 967 BindFramebuffer(target, framebuffer); 968 } 969 } 970 971 fn bind_vertex_buffer( 972 &self, 973 binding_index: GLuint, 974 buffer: GLuint, 975 offset: GLintptr, 976 stride: GLint, 977 ) { 978 unimplemented!("Not supported by SWGL"); 979 } 980 981 fn bind_texture(&self, target: GLenum, texture: GLuint) { 982 //panic!(); 983 unsafe { 984 BindTexture(target, texture); 985 } 986 } 987 988 fn draw_buffers(&self, bufs: &[GLenum]) { 989 panic!(); 990 //unsafe {} 991 } 992 993 // FIXME: Does not verify buffer size -- unsafe! 994 fn tex_image_2d( 995 &self, 996 target: GLenum, 997 level: GLint, 998 internal_format: GLint, 999 width: GLsizei, 1000 height: GLsizei, 1001 border: GLint, 1002 format: GLenum, 1003 ty: GLenum, 1004 opt_data: Option<&[u8]>, 1005 ) { 1006 unsafe { 1007 let pdata = match opt_data { 1008 Some(data) => data.as_ptr() as *const GLvoid, 1009 None => ptr::null(), 1010 }; 1011 TexImage2D( 1012 target, 1013 level, 1014 internal_format, 1015 width, 1016 height, 1017 border, 1018 format, 1019 ty, 1020 pdata, 1021 ); 1022 } 1023 } 1024 1025 fn compressed_tex_image_2d( 1026 &self, 1027 target: GLenum, 1028 level: GLint, 1029 internal_format: GLenum, 1030 width: GLsizei, 1031 height: GLsizei, 1032 border: GLint, 1033 data: &[u8], 1034 ) { 1035 panic!(); 1036 } 1037 1038 fn compressed_tex_sub_image_2d( 1039 &self, 1040 target: GLenum, 1041 level: GLint, 1042 xoffset: GLint, 1043 yoffset: GLint, 1044 width: GLsizei, 1045 height: GLsizei, 1046 format: GLenum, 1047 data: &[u8], 1048 ) { 1049 panic!(); 1050 } 1051 1052 fn tex_image_3d( 1053 &self, 1054 target: GLenum, 1055 level: GLint, 1056 internal_format: GLint, 1057 width: GLsizei, 1058 height: GLsizei, 1059 depth: GLsizei, 1060 border: GLint, 1061 format: GLenum, 1062 ty: GLenum, 1063 opt_data: Option<&[u8]>, 1064 ) { 1065 panic!(); 1066 } 1067 1068 fn copy_tex_image_2d( 1069 &self, 1070 target: GLenum, 1071 level: GLint, 1072 internal_format: GLenum, 1073 x: GLint, 1074 y: GLint, 1075 width: GLsizei, 1076 height: GLsizei, 1077 border: GLint, 1078 ) { 1079 panic!(); 1080 } 1081 1082 fn copy_tex_sub_image_2d( 1083 &self, 1084 target: GLenum, 1085 level: GLint, 1086 xoffset: GLint, 1087 yoffset: GLint, 1088 x: GLint, 1089 y: GLint, 1090 width: GLsizei, 1091 height: GLsizei, 1092 ) { 1093 unsafe { 1094 CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); 1095 } 1096 } 1097 1098 fn copy_tex_sub_image_3d( 1099 &self, 1100 target: GLenum, 1101 level: GLint, 1102 xoffset: GLint, 1103 yoffset: GLint, 1104 zoffset: GLint, 1105 x: GLint, 1106 y: GLint, 1107 width: GLsizei, 1108 height: GLsizei, 1109 ) { 1110 panic!(); 1111 } 1112 1113 fn tex_sub_image_2d( 1114 &self, 1115 target: GLenum, 1116 level: GLint, 1117 xoffset: GLint, 1118 yoffset: GLint, 1119 width: GLsizei, 1120 height: GLsizei, 1121 format: GLenum, 1122 ty: GLenum, 1123 data: &[u8], 1124 ) { 1125 debug!( 1126 "tex_sub_image_2d {} {} {} {} {} {} {} {}", 1127 target, level, xoffset, yoffset, width, height, format, ty 1128 ); 1129 //panic!(); 1130 unsafe { 1131 TexSubImage2D( 1132 target, 1133 level, 1134 xoffset, 1135 yoffset, 1136 width, 1137 height, 1138 format, 1139 ty, 1140 data.as_ptr() as *const c_void, 1141 ); 1142 } 1143 } 1144 1145 fn tex_sub_image_2d_pbo( 1146 &self, 1147 target: GLenum, 1148 level: GLint, 1149 xoffset: GLint, 1150 yoffset: GLint, 1151 width: GLsizei, 1152 height: GLsizei, 1153 format: GLenum, 1154 ty: GLenum, 1155 offset: usize, 1156 ) { 1157 debug!( 1158 "tex_sub_image_2d_pbo {} {} {} {} {} {} {} {} {}", 1159 target, level, xoffset, yoffset, width, height, format, ty, offset 1160 ); 1161 //panic!(); 1162 unsafe { 1163 TexSubImage2D( 1164 target, 1165 level, 1166 xoffset, 1167 yoffset, 1168 width, 1169 height, 1170 format, 1171 ty, 1172 offset as *const c_void, 1173 ); 1174 } 1175 } 1176 1177 fn tex_sub_image_3d( 1178 &self, 1179 target: GLenum, 1180 level: GLint, 1181 xoffset: GLint, 1182 yoffset: GLint, 1183 zoffset: GLint, 1184 width: GLsizei, 1185 height: GLsizei, 1186 depth: GLsizei, 1187 format: GLenum, 1188 ty: GLenum, 1189 data: &[u8], 1190 ) { 1191 debug!("tex_sub_image_3d"); 1192 panic!(); 1193 } 1194 1195 fn tex_sub_image_3d_pbo( 1196 &self, 1197 target: GLenum, 1198 level: GLint, 1199 xoffset: GLint, 1200 yoffset: GLint, 1201 zoffset: GLint, 1202 width: GLsizei, 1203 height: GLsizei, 1204 depth: GLsizei, 1205 format: GLenum, 1206 ty: GLenum, 1207 offset: usize, 1208 ) { 1209 panic!(); 1210 } 1211 1212 fn tex_storage_2d( 1213 &self, 1214 target: GLenum, 1215 levels: GLint, 1216 internal_format: GLenum, 1217 width: GLsizei, 1218 height: GLsizei, 1219 ) { 1220 //panic!(); 1221 unsafe { 1222 TexStorage2D(target, levels, internal_format, width, height); 1223 } 1224 } 1225 1226 fn tex_storage_3d( 1227 &self, 1228 target: GLenum, 1229 levels: GLint, 1230 internal_format: GLenum, 1231 width: GLsizei, 1232 height: GLsizei, 1233 depth: GLsizei, 1234 ) { 1235 panic!(); 1236 } 1237 1238 fn get_tex_image_into_buffer( 1239 &self, 1240 target: GLenum, 1241 level: GLint, 1242 format: GLenum, 1243 ty: GLenum, 1244 output: &mut [u8], 1245 ) { 1246 panic!(); 1247 } 1248 1249 unsafe fn copy_image_sub_data( 1250 &self, 1251 src_name: GLuint, 1252 src_target: GLenum, 1253 src_level: GLint, 1254 src_x: GLint, 1255 src_y: GLint, 1256 src_z: GLint, 1257 dst_name: GLuint, 1258 dst_target: GLenum, 1259 dst_level: GLint, 1260 dst_x: GLint, 1261 dst_y: GLint, 1262 dst_z: GLint, 1263 src_width: GLsizei, 1264 src_height: GLsizei, 1265 src_depth: GLsizei, 1266 ) { 1267 CopyImageSubData( 1268 src_name, src_target, src_level, src_x, src_y, src_z, dst_name, dst_target, dst_level, 1269 dst_x, dst_y, dst_z, src_width, src_height, src_depth, 1270 ); 1271 } 1272 1273 fn invalidate_framebuffer(&self, target: GLenum, attachments: &[GLenum]) { 1274 unsafe { 1275 InvalidateFramebuffer(target, attachments.len() as GLsizei, attachments.as_ptr()); 1276 } 1277 } 1278 1279 fn invalidate_sub_framebuffer( 1280 &self, 1281 target: GLenum, 1282 attachments: &[GLenum], 1283 xoffset: GLint, 1284 yoffset: GLint, 1285 width: GLsizei, 1286 height: GLsizei, 1287 ) { 1288 } 1289 1290 #[inline] 1291 unsafe fn get_integer_v(&self, name: GLenum, result: &mut [GLint]) { 1292 //panic!(); 1293 assert!(!result.is_empty()); 1294 GetIntegerv(name, result.as_mut_ptr()); 1295 } 1296 1297 #[inline] 1298 unsafe fn get_integer_64v(&self, name: GLenum, result: &mut [GLint64]) { 1299 panic!(); 1300 //assert!(!result.is_empty()); 1301 } 1302 1303 #[inline] 1304 unsafe fn get_integer_iv(&self, name: GLenum, index: GLuint, result: &mut [GLint]) { 1305 panic!(); 1306 //assert!(!result.is_empty()); 1307 } 1308 1309 #[inline] 1310 unsafe fn get_integer_64iv(&self, name: GLenum, index: GLuint, result: &mut [GLint64]) { 1311 panic!(); 1312 //assert!(!result.is_empty()); 1313 } 1314 1315 #[inline] 1316 unsafe fn get_boolean_v(&self, name: GLenum, result: &mut [GLboolean]) { 1317 debug!("get_boolean_v {}", name); 1318 //panic!(); 1319 assert!(!result.is_empty()); 1320 GetBooleanv(name, result.as_mut_ptr()); 1321 } 1322 1323 #[inline] 1324 unsafe fn get_float_v(&self, name: GLenum, result: &mut [GLfloat]) { 1325 panic!(); 1326 //assert!(!result.is_empty()); 1327 } 1328 1329 fn get_framebuffer_attachment_parameter_iv( 1330 &self, 1331 target: GLenum, 1332 attachment: GLenum, 1333 pname: GLenum, 1334 ) -> GLint { 1335 panic!(); 1336 //0 1337 } 1338 1339 fn get_renderbuffer_parameter_iv(&self, target: GLenum, pname: GLenum) -> GLint { 1340 panic!(); 1341 //0 1342 } 1343 1344 fn get_tex_parameter_iv(&self, target: GLenum, pname: GLenum) -> GLint { 1345 panic!(); 1346 //0 1347 } 1348 1349 fn get_tex_parameter_fv(&self, target: GLenum, pname: GLenum) -> GLfloat { 1350 panic!(); 1351 //0.0 1352 } 1353 1354 fn tex_parameter_i(&self, target: GLenum, pname: GLenum, param: GLint) { 1355 //panic!(); 1356 unsafe { 1357 TexParameteri(target, pname, param); 1358 } 1359 } 1360 1361 fn tex_parameter_f(&self, target: GLenum, pname: GLenum, param: GLfloat) { 1362 panic!(); 1363 } 1364 1365 fn framebuffer_texture_2d( 1366 &self, 1367 target: GLenum, 1368 attachment: GLenum, 1369 textarget: GLenum, 1370 texture: GLuint, 1371 level: GLint, 1372 ) { 1373 debug!( 1374 "framebuffer_texture_2d {} {} {} {} {}", 1375 target, attachment, textarget, texture, level 1376 ); 1377 //panic!(); 1378 unsafe { 1379 FramebufferTexture2D(target, attachment, textarget, texture, level); 1380 } 1381 } 1382 1383 fn framebuffer_texture_layer( 1384 &self, 1385 target: GLenum, 1386 attachment: GLenum, 1387 texture: GLuint, 1388 level: GLint, 1389 layer: GLint, 1390 ) { 1391 debug!( 1392 "framebuffer_texture_layer {} {} {} {} {}", 1393 target, attachment, texture, level, layer 1394 ); 1395 panic!(); 1396 } 1397 1398 fn blit_framebuffer( 1399 &self, 1400 src_x0: GLint, 1401 src_y0: GLint, 1402 src_x1: GLint, 1403 src_y1: GLint, 1404 dst_x0: GLint, 1405 dst_y0: GLint, 1406 dst_x1: GLint, 1407 dst_y1: GLint, 1408 mask: GLbitfield, 1409 filter: GLenum, 1410 ) { 1411 unsafe { 1412 BlitFramebuffer( 1413 src_x0, src_y0, src_x1, src_y1, dst_x0, dst_y0, dst_x1, dst_y1, mask, filter, 1414 ); 1415 } 1416 } 1417 1418 fn vertex_attrib_4f(&self, index: GLuint, x: GLfloat, y: GLfloat, z: GLfloat, w: GLfloat) { 1419 panic!(); 1420 } 1421 1422 fn vertex_attrib_binding(&self, attrib_index: GLuint, binding_index: GLuint) { 1423 unimplemented!("Not supported by SWGL"); 1424 } 1425 1426 fn vertex_attrib_pointer_f32( 1427 &self, 1428 index: GLuint, 1429 size: GLint, 1430 normalized: bool, 1431 stride: GLsizei, 1432 offset: GLuint, 1433 ) { 1434 panic!(); 1435 } 1436 1437 fn vertex_attrib_pointer( 1438 &self, 1439 index: GLuint, 1440 size: GLint, 1441 type_: GLenum, 1442 normalized: bool, 1443 stride: GLsizei, 1444 offset: GLuint, 1445 ) { 1446 debug!( 1447 "vertex_attrib_pointer {} {} {} {} {} {}", 1448 index, size, type_, normalized, stride, offset 1449 ); 1450 //panic!(); 1451 unsafe { 1452 VertexAttribPointer( 1453 index, 1454 size, 1455 type_, 1456 normalized as GLboolean, 1457 stride, 1458 offset as *const GLvoid, 1459 ); 1460 } 1461 } 1462 1463 fn vertex_attrib_i_pointer( 1464 &self, 1465 index: GLuint, 1466 size: GLint, 1467 type_: GLenum, 1468 stride: GLsizei, 1469 offset: GLuint, 1470 ) { 1471 debug!( 1472 "vertex_attrib_i_pointer {} {} {} {} {}", 1473 index, size, type_, stride, offset 1474 ); 1475 //panic!(); 1476 unsafe { 1477 VertexAttribIPointer(index, size, type_, stride, offset as *const GLvoid); 1478 } 1479 } 1480 1481 fn vertex_attrib_divisor(&self, index: GLuint, divisor: GLuint) { 1482 debug!("vertex_attrib_divisor {} {}", index, divisor); 1483 //assert!(index == 0 && divisor == 0); 1484 //panic!(); 1485 unsafe { 1486 VertexAttribDivisor(index, divisor); 1487 } 1488 } 1489 1490 fn vertex_attrib_format( 1491 &self, 1492 attrib_index: GLuint, 1493 size: GLint, 1494 type_: GLenum, 1495 normalized: bool, 1496 relative_offset: GLuint, 1497 ) { 1498 unimplemented!("Not supported by SWGL"); 1499 } 1500 1501 fn vertex_attrib_i_format( 1502 &self, 1503 attrib_index: GLuint, 1504 size: GLint, 1505 type_: GLenum, 1506 relative_offset: GLuint, 1507 ) { 1508 unimplemented!("Not supported by SWGL"); 1509 } 1510 1511 fn vertex_binding_divisor(&self, binding_index: GLuint, divisor: GLuint) { 1512 unimplemented!("Not supported by SWGL"); 1513 } 1514 1515 fn viewport(&self, x: GLint, y: GLint, width: GLsizei, height: GLsizei) { 1516 debug!("viewport {} {} {} {}", x, y, width, height); 1517 //panic!(); 1518 unsafe { 1519 SetViewport(x, y, width, height); 1520 } 1521 } 1522 1523 fn scissor(&self, x: GLint, y: GLint, width: GLsizei, height: GLsizei) { 1524 //panic!(); 1525 unsafe { 1526 SetScissor(x, y, width, height); 1527 } 1528 } 1529 1530 fn line_width(&self, width: GLfloat) { 1531 panic!(); 1532 } 1533 1534 fn use_program(&self, program: GLuint) { 1535 //panic!(); 1536 unsafe { 1537 UseProgram(program); 1538 } 1539 } 1540 1541 fn validate_program(&self, program: GLuint) { 1542 panic!(); 1543 } 1544 1545 fn draw_arrays(&self, mode: GLenum, first: GLint, count: GLsizei) { 1546 unsafe { 1547 DrawElementsInstanced(mode, count, NONE, first as GLintptr, 1); 1548 } 1549 } 1550 1551 fn draw_arrays_instanced( 1552 &self, 1553 mode: GLenum, 1554 first: GLint, 1555 count: GLsizei, 1556 primcount: GLsizei, 1557 ) { 1558 unsafe { 1559 DrawElementsInstanced(mode, count, NONE, first as GLintptr, primcount); 1560 } 1561 } 1562 1563 fn draw_elements( 1564 &self, 1565 mode: GLenum, 1566 count: GLsizei, 1567 element_type: GLenum, 1568 indices_offset: GLuint, 1569 ) { 1570 debug!( 1571 "draw_elements {} {} {} {} {}", 1572 mode, count, element_type, indices_offset 1573 ); 1574 //panic!(); 1575 unsafe { 1576 DrawElementsInstanced(mode, count, element_type, indices_offset as GLintptr, 1); 1577 } 1578 } 1579 1580 fn draw_elements_instanced( 1581 &self, 1582 mode: GLenum, 1583 count: GLsizei, 1584 element_type: GLenum, 1585 indices_offset: GLuint, 1586 primcount: GLsizei, 1587 ) { 1588 debug!( 1589 "draw_elements_instanced {} {} {} {} {}", 1590 mode, count, element_type, indices_offset, primcount 1591 ); 1592 //panic!(); 1593 unsafe { 1594 DrawElementsInstanced( 1595 mode, 1596 count, 1597 element_type, 1598 indices_offset as GLintptr, 1599 primcount, 1600 ); 1601 } 1602 } 1603 1604 fn blend_color(&self, r: f32, g: f32, b: f32, a: f32) { 1605 unsafe { 1606 BlendColor(r, g, b, a); 1607 } 1608 } 1609 1610 fn blend_func(&self, sfactor: GLenum, dfactor: GLenum) { 1611 unsafe { 1612 BlendFunc(sfactor, dfactor, sfactor, dfactor); 1613 } 1614 } 1615 1616 fn blend_func_separate( 1617 &self, 1618 src_rgb: GLenum, 1619 dest_rgb: GLenum, 1620 src_alpha: GLenum, 1621 dest_alpha: GLenum, 1622 ) { 1623 unsafe { 1624 BlendFunc(src_rgb, dest_rgb, src_alpha, dest_alpha); 1625 } 1626 } 1627 1628 fn blend_equation(&self, mode: GLenum) { 1629 unsafe { 1630 BlendEquation(mode); 1631 } 1632 } 1633 1634 fn blend_equation_separate(&self, mode_rgb: GLenum, mode_alpha: GLenum) { 1635 panic!(); 1636 } 1637 1638 fn color_mask(&self, r: bool, g: bool, b: bool, a: bool) { 1639 panic!(); 1640 } 1641 1642 fn cull_face(&self, mode: GLenum) { 1643 panic!(); 1644 } 1645 1646 fn front_face(&self, mode: GLenum) { 1647 panic!(); 1648 } 1649 1650 fn enable(&self, cap: GLenum) { 1651 debug!("enable {}", cap); 1652 //panic!(); 1653 unsafe { 1654 Enable(cap); 1655 } 1656 } 1657 1658 fn disable(&self, cap: GLenum) { 1659 debug!("disable {}", cap); 1660 //panic!(); 1661 unsafe { 1662 Disable(cap); 1663 } 1664 } 1665 1666 fn hint(&self, param_name: GLenum, param_val: GLenum) { 1667 panic!(); 1668 } 1669 1670 fn is_enabled(&self, cap: GLenum) -> GLboolean { 1671 panic!(); 1672 //0 1673 } 1674 1675 fn is_shader(&self, shader: GLuint) -> GLboolean { 1676 panic!(); 1677 //0 1678 } 1679 1680 fn is_texture(&self, texture: GLenum) -> GLboolean { 1681 panic!(); 1682 //0 1683 } 1684 1685 fn is_framebuffer(&self, framebuffer: GLenum) -> GLboolean { 1686 panic!(); 1687 //0 1688 } 1689 1690 fn is_renderbuffer(&self, renderbuffer: GLenum) -> GLboolean { 1691 panic!(); 1692 //0 1693 } 1694 1695 fn check_frame_buffer_status(&self, target: GLenum) -> GLenum { 1696 debug!("check_frame_buffer_status {}", target); 1697 //panic!(); 1698 unsafe { CheckFramebufferStatus(target) } 1699 } 1700 1701 fn enable_vertex_attrib_array(&self, index: GLuint) { 1702 //panic!(); 1703 debug!("enable_vertex_attrib_array {}", index); 1704 unsafe { 1705 EnableVertexAttribArray(index); 1706 //assert_eq!(index, 0); 1707 } 1708 } 1709 1710 fn disable_vertex_attrib_array(&self, index: GLuint) { 1711 panic!(); 1712 } 1713 1714 fn uniform_1f(&self, location: GLint, v0: GLfloat) { 1715 panic!(); 1716 } 1717 1718 fn uniform_1fv(&self, location: GLint, values: &[f32]) { 1719 panic!(); 1720 } 1721 1722 fn uniform_1i(&self, location: GLint, v0: GLint) { 1723 debug!("uniform_1i {} {}", location, v0); 1724 //panic!(); 1725 unsafe { 1726 Uniform1i(location, v0); 1727 } 1728 } 1729 1730 fn uniform_1iv(&self, location: GLint, values: &[i32]) { 1731 panic!(); 1732 } 1733 1734 fn uniform_1ui(&self, location: GLint, v0: GLuint) { 1735 panic!(); 1736 } 1737 1738 fn uniform_2f(&self, location: GLint, v0: GLfloat, v1: GLfloat) { 1739 panic!(); 1740 } 1741 1742 fn uniform_2fv(&self, location: GLint, values: &[f32]) { 1743 panic!(); 1744 } 1745 1746 fn uniform_2i(&self, location: GLint, v0: GLint, v1: GLint) { 1747 panic!(); 1748 } 1749 1750 fn uniform_2iv(&self, location: GLint, values: &[i32]) { 1751 panic!(); 1752 } 1753 1754 fn uniform_2ui(&self, location: GLint, v0: GLuint, v1: GLuint) { 1755 panic!(); 1756 } 1757 1758 fn uniform_3f(&self, location: GLint, v0: GLfloat, v1: GLfloat, v2: GLfloat) { 1759 panic!(); 1760 } 1761 1762 fn uniform_3fv(&self, location: GLint, values: &[f32]) { 1763 panic!(); 1764 } 1765 1766 fn uniform_3i(&self, location: GLint, v0: GLint, v1: GLint, v2: GLint) { 1767 panic!(); 1768 } 1769 1770 fn uniform_3iv(&self, location: GLint, values: &[i32]) { 1771 panic!(); 1772 } 1773 1774 fn uniform_3ui(&self, location: GLint, v0: GLuint, v1: GLuint, v2: GLuint) { 1775 panic!(); 1776 } 1777 1778 fn uniform_4f(&self, location: GLint, x: GLfloat, y: GLfloat, z: GLfloat, w: GLfloat) { 1779 panic!(); 1780 } 1781 1782 fn uniform_4i(&self, location: GLint, x: GLint, y: GLint, z: GLint, w: GLint) { 1783 panic!(); 1784 } 1785 1786 fn uniform_4iv(&self, location: GLint, values: &[i32]) { 1787 panic!(); 1788 } 1789 1790 fn uniform_4ui(&self, location: GLint, x: GLuint, y: GLuint, z: GLuint, w: GLuint) { 1791 panic!(); 1792 } 1793 1794 fn uniform_4fv(&self, location: GLint, values: &[f32]) { 1795 unsafe { 1796 Uniform4fv(location, (values.len() / 4) as GLsizei, values.as_ptr()); 1797 } 1798 } 1799 1800 fn uniform_matrix_2fv(&self, location: GLint, transpose: bool, value: &[f32]) { 1801 panic!(); 1802 } 1803 1804 fn uniform_matrix_3fv(&self, location: GLint, transpose: bool, value: &[f32]) { 1805 panic!(); 1806 } 1807 1808 fn uniform_matrix_4fv(&self, location: GLint, transpose: bool, value: &[f32]) { 1809 debug!("uniform_matrix_4fv {} {} {:?}", location, transpose, value); 1810 //panic!(); 1811 unsafe { 1812 UniformMatrix4fv( 1813 location, 1814 (value.len() / 16) as GLsizei, 1815 transpose as GLboolean, 1816 value.as_ptr(), 1817 ); 1818 } 1819 } 1820 1821 fn depth_mask(&self, flag: bool) { 1822 debug!("depth_mask {}", flag); 1823 //panic!(); 1824 unsafe { 1825 DepthMask(flag as GLboolean); 1826 } 1827 } 1828 1829 fn depth_range(&self, near: f64, far: f64) { 1830 panic!(); 1831 } 1832 1833 fn get_active_attrib(&self, program: GLuint, index: GLuint) -> (i32, u32, String) { 1834 panic!(); 1835 //(0, 0, String::new()) 1836 } 1837 1838 fn get_active_uniform(&self, program: GLuint, index: GLuint) -> (i32, u32, String) { 1839 panic!(); 1840 //(0, 0, String::new()) 1841 } 1842 1843 fn get_active_uniforms_iv( 1844 &self, 1845 program: GLuint, 1846 indices: Vec<GLuint>, 1847 pname: GLenum, 1848 ) -> Vec<GLint> { 1849 panic!(); 1850 //Vec::new() 1851 } 1852 1853 fn get_active_uniform_block_i(&self, program: GLuint, index: GLuint, pname: GLenum) -> GLint { 1854 panic!(); 1855 //0 1856 } 1857 1858 fn get_active_uniform_block_iv( 1859 &self, 1860 program: GLuint, 1861 index: GLuint, 1862 pname: GLenum, 1863 ) -> Vec<GLint> { 1864 panic!(); 1865 //Vec::new() 1866 } 1867 1868 fn get_active_uniform_block_name(&self, program: GLuint, index: GLuint) -> String { 1869 panic!(); 1870 //String::new() 1871 } 1872 1873 fn get_attrib_location(&self, program: GLuint, name: &str) -> c_int { 1874 let name = CString::new(name).unwrap(); 1875 unsafe { GetAttribLocation(program, name.as_ptr()) } 1876 } 1877 1878 fn get_frag_data_location(&self, program: GLuint, name: &str) -> c_int { 1879 panic!(); 1880 //0 1881 } 1882 1883 fn get_uniform_location(&self, program: GLuint, name: &str) -> c_int { 1884 debug!("get_uniform_location {} {}", program, name); 1885 //panic!(); 1886 let name = CString::new(name).unwrap(); 1887 unsafe { GetUniformLocation(program, name.as_ptr()) } 1888 } 1889 1890 fn get_program_info_log(&self, program: GLuint) -> String { 1891 debug!("get_program_info_log {}", program); 1892 String::new() 1893 } 1894 1895 #[inline] 1896 unsafe fn get_program_iv(&self, program: GLuint, pname: GLenum, result: &mut [GLint]) { 1897 debug!("get_program_iv {}", pname); 1898 //panic!(); 1899 assert!(!result.is_empty()); 1900 //#define GL_LINK_STATUS 0x8B82 1901 if pname == 0x8b82 { 1902 result[0] = GetLinkStatus(program); 1903 } 1904 } 1905 1906 fn get_program_binary(&self, program: GLuint) -> (Vec<u8>, GLenum) { 1907 panic!(); 1908 //(Vec::new(), NONE) 1909 } 1910 1911 fn program_binary(&self, program: GLuint, format: GLenum, binary: &[u8]) { 1912 panic!(); 1913 } 1914 1915 fn program_parameter_i(&self, program: GLuint, pname: GLenum, value: GLint) { 1916 panic!(); 1917 } 1918 1919 #[inline] 1920 unsafe fn get_vertex_attrib_iv(&self, index: GLuint, pname: GLenum, result: &mut [GLint]) { 1921 panic!(); 1922 //assert!(!result.is_empty()); 1923 } 1924 1925 #[inline] 1926 unsafe fn get_vertex_attrib_fv(&self, index: GLuint, pname: GLenum, result: &mut [GLfloat]) { 1927 panic!(); 1928 //assert!(!result.is_empty()); 1929 } 1930 1931 fn get_vertex_attrib_pointer_v(&self, index: GLuint, pname: GLenum) -> GLsizeiptr { 1932 panic!(); 1933 //0 1934 } 1935 1936 fn get_buffer_parameter_iv(&self, target: GLuint, pname: GLenum) -> GLint { 1937 panic!(); 1938 //0 1939 } 1940 1941 fn get_shader_info_log(&self, shader: GLuint) -> String { 1942 debug!("get_shader_info_log {}", shader); 1943 //panic!(); 1944 String::new() 1945 } 1946 1947 fn get_string(&self, which: GLenum) -> String { 1948 // panic!(); 1949 unsafe { 1950 let llstr = GetString(which); 1951 if !llstr.is_null() { 1952 str::from_utf8_unchecked(CStr::from_ptr(llstr).to_bytes()).to_string() 1953 } else { 1954 "".to_string() 1955 } 1956 } 1957 } 1958 1959 fn get_string_i(&self, which: GLenum, index: GLuint) -> String { 1960 //panic!(); 1961 unsafe { 1962 let llstr = GetStringi(which, index); 1963 if !llstr.is_null() { 1964 str::from_utf8_unchecked(CStr::from_ptr(llstr).to_bytes()).to_string() 1965 } else { 1966 "".to_string() 1967 } 1968 } 1969 } 1970 1971 unsafe fn get_shader_iv(&self, shader: GLuint, pname: GLenum, result: &mut [GLint]) { 1972 debug!("get_shader_iv"); 1973 //panic!(); 1974 assert!(!result.is_empty()); 1975 if pname == 0x8B81 1976 /*gl::COMPILE_STATUS*/ 1977 { 1978 result[0] = 1; 1979 } 1980 } 1981 1982 fn get_shader_precision_format( 1983 &self, 1984 _shader_type: GLuint, 1985 precision_type: GLuint, 1986 ) -> (GLint, GLint, GLint) { 1987 // gl.GetShaderPrecisionFormat is not available until OpenGL 4.1. 1988 // Fallback to OpenGL standard precissions that most desktop hardware support. 1989 match precision_type { 1990 LOW_FLOAT | MEDIUM_FLOAT | HIGH_FLOAT => { 1991 // Fallback to IEEE 754 single precision 1992 // Range: from -2^127 to 2^127 1993 // Significand precision: 23 bits 1994 (127, 127, 23) 1995 } 1996 LOW_INT | MEDIUM_INT | HIGH_INT => { 1997 // Fallback to single precision integer 1998 // Range: from -2^24 to 2^24 1999 // Precision: For integer formats this value is always 0 2000 (24, 24, 0) 2001 } 2002 _ => (0, 0, 0), 2003 } 2004 } 2005 2006 fn compile_shader(&self, shader: GLuint) { 2007 debug!("compile_shader {}", shader); 2008 //panic!(); 2009 } 2010 2011 fn create_program(&self) -> GLuint { 2012 debug!("create_program"); 2013 //panic!(); 2014 unsafe { CreateProgram() } 2015 } 2016 2017 fn delete_program(&self, program: GLuint) { 2018 unsafe { 2019 DeleteProgram(program); 2020 } 2021 } 2022 2023 fn create_shader(&self, shader_type: GLenum) -> GLuint { 2024 debug!("create_shader {}", shader_type); 2025 //panic!(); 2026 unsafe { CreateShader(shader_type) } 2027 } 2028 2029 fn delete_shader(&self, shader: GLuint) { 2030 debug!("delete_shader {}", shader); 2031 //panic!(); 2032 unsafe { 2033 DeleteShader(shader); 2034 } 2035 } 2036 2037 fn detach_shader(&self, program: GLuint, shader: GLuint) { 2038 debug!("detach_shader {} {}", program, shader); 2039 //panic!(); 2040 } 2041 2042 fn link_program(&self, program: GLuint) { 2043 debug!("link_program {}", program); 2044 //panic!(); 2045 unsafe { 2046 LinkProgram(program); 2047 } 2048 } 2049 2050 fn clear_color(&self, r: f32, g: f32, b: f32, a: f32) { 2051 //panic!(); 2052 unsafe { 2053 ClearColor(r, g, b, a); 2054 } 2055 } 2056 2057 fn clear(&self, buffer_mask: GLbitfield) { 2058 debug!("clear {}", buffer_mask); 2059 //panic!(); 2060 unsafe { 2061 Clear(buffer_mask); 2062 } 2063 } 2064 2065 fn clear_depth(&self, depth: f64) { 2066 debug!("clear_depth {}", depth); 2067 //panic!(); 2068 unsafe { 2069 ClearDepth(depth as GLclampd); 2070 } 2071 } 2072 2073 fn clear_stencil(&self, s: GLint) { 2074 panic!(); 2075 } 2076 2077 fn flush(&self) {} 2078 2079 fn finish(&self) { 2080 unsafe { 2081 Finish(); 2082 } 2083 } 2084 2085 fn get_error(&self) -> GLenum { 2086 //panic!(); 2087 unsafe { GetError() } 2088 } 2089 2090 fn stencil_mask(&self, mask: GLuint) { 2091 panic!(); 2092 } 2093 2094 fn stencil_mask_separate(&self, face: GLenum, mask: GLuint) { 2095 panic!(); 2096 } 2097 2098 fn stencil_func(&self, func: GLenum, ref_: GLint, mask: GLuint) { 2099 panic!(); 2100 } 2101 2102 fn stencil_func_separate(&self, face: GLenum, func: GLenum, ref_: GLint, mask: GLuint) { 2103 panic!(); 2104 } 2105 2106 fn stencil_op(&self, sfail: GLenum, dpfail: GLenum, dppass: GLenum) { 2107 panic!(); 2108 } 2109 2110 fn stencil_op_separate(&self, face: GLenum, sfail: GLenum, dpfail: GLenum, dppass: GLenum) { 2111 panic!(); 2112 } 2113 2114 fn egl_image_target_texture2d_oes(&self, target: GLenum, image: GLeglImageOES) { 2115 panic!("not supported") 2116 } 2117 2118 fn egl_image_target_renderbuffer_storage_oes(&self, target: GLenum, image: GLeglImageOES) { 2119 panic!("not supported") 2120 } 2121 2122 fn generate_mipmap(&self, target: GLenum) { 2123 unsafe { 2124 GenerateMipmap(target); 2125 } 2126 } 2127 2128 fn insert_event_marker_ext(&self, message: &str) { 2129 panic!(); 2130 } 2131 2132 fn push_group_marker_ext(&self, message: &str) { 2133 debug!("push group {}", message); 2134 panic!(); 2135 } 2136 2137 fn pop_group_marker_ext(&self) { 2138 debug!("pop group"); 2139 panic!(); 2140 } 2141 2142 fn debug_message_insert_khr( 2143 &self, 2144 source: GLenum, 2145 type_: GLenum, 2146 id: GLuint, 2147 severity: GLenum, 2148 message: &str, 2149 ) { 2150 panic!(); 2151 } 2152 2153 fn push_debug_group_khr(&self, source: GLenum, id: GLuint, message: &str) { 2154 panic!(); 2155 } 2156 2157 fn pop_debug_group_khr(&self) { 2158 panic!(); 2159 } 2160 2161 fn fence_sync(&self, condition: GLenum, flags: GLbitfield) -> GLsync { 2162 panic!(); 2163 //ptr::null() 2164 } 2165 2166 fn client_wait_sync(&self, sync: GLsync, flags: GLbitfield, timeout: GLuint64) -> GLenum { 2167 panic!(); 2168 } 2169 2170 fn wait_sync(&self, sync: GLsync, flags: GLbitfield, timeout: GLuint64) { 2171 panic!(); 2172 } 2173 2174 fn texture_range_apple(&self, target: GLenum, data: &[u8]) { 2175 panic!(); 2176 } 2177 2178 fn delete_sync(&self, sync: GLsync) { 2179 panic!(); 2180 } 2181 2182 fn gen_fences_apple(&self, n: GLsizei) -> Vec<GLuint> { 2183 panic!(); 2184 //Vec::new() 2185 } 2186 2187 fn delete_fences_apple(&self, fences: &[GLuint]) { 2188 panic!(); 2189 } 2190 2191 fn set_fence_apple(&self, fence: GLuint) { 2192 panic!(); 2193 } 2194 2195 fn finish_fence_apple(&self, fence: GLuint) { 2196 panic!(); 2197 } 2198 2199 fn test_fence_apple(&self, fence: GLuint) { 2200 panic!(); 2201 } 2202 2203 fn test_object_apple(&self, object: GLenum, name: GLuint) -> GLboolean { 2204 panic!(); 2205 //0 2206 } 2207 2208 fn finish_object_apple(&self, object: GLenum, name: GLuint) { 2209 panic!(); 2210 } 2211 2212 // GL_ARB_blend_func_extended 2213 fn bind_frag_data_location_indexed( 2214 &self, 2215 program: GLuint, 2216 color_number: GLuint, 2217 index: GLuint, 2218 name: &str, 2219 ) { 2220 panic!(); 2221 } 2222 2223 fn get_frag_data_index(&self, program: GLuint, name: &str) -> GLint { 2224 panic!(); 2225 //-1 2226 } 2227 2228 // GL_KHR_debug 2229 fn get_debug_messages(&self) -> Vec<DebugMessage> { 2230 Vec::new() 2231 } 2232 2233 fn provoking_vertex_angle(&self, _mode: GLenum) { 2234 unimplemented!("This extension is GLES only"); 2235 } 2236 2237 // GL_KHR_blend_equation_advanced 2238 fn blend_barrier_khr(&self) { 2239 // No barrier required, so nothing to do 2240 } 2241 2242 // GL_CHROMIUM_copy_texture 2243 fn copy_texture_chromium( 2244 &self, 2245 _source_id: GLuint, 2246 _source_level: GLint, 2247 _dest_target: GLenum, 2248 _dest_id: GLuint, 2249 _dest_level: GLint, 2250 _internal_format: GLint, 2251 _dest_type: GLenum, 2252 _unpack_flip_y: GLboolean, 2253 _unpack_premultiply_alpha: GLboolean, 2254 _unpack_unmultiply_alpha: GLboolean, 2255 ) { 2256 unimplemented!("This extension is GLES only"); 2257 } 2258 fn copy_sub_texture_chromium( 2259 &self, 2260 _source_id: GLuint, 2261 _source_level: GLint, 2262 _dest_target: GLenum, 2263 _dest_id: GLuint, 2264 _dest_level: GLint, 2265 _x_offset: GLint, 2266 _y_offset: GLint, 2267 _x: GLint, 2268 _y: GLint, 2269 _width: GLsizei, 2270 _height: GLsizei, 2271 _unpack_flip_y: GLboolean, 2272 _unpack_premultiply_alpha: GLboolean, 2273 _unpack_unmultiply_alpha: GLboolean, 2274 ) { 2275 unimplemented!("This extension is GLES only"); 2276 } 2277 2278 // GL_ANGLE_copy_texture_3d 2279 fn copy_texture_3d_angle( 2280 &self, 2281 _source_id: GLuint, 2282 _source_level: GLint, 2283 _dest_target: GLenum, 2284 _dest_id: GLuint, 2285 _dest_level: GLint, 2286 _internal_format: GLint, 2287 _dest_type: GLenum, 2288 _unpack_flip_y: GLboolean, 2289 _unpack_premultiply_alpha: GLboolean, 2290 _unpack_unmultiply_alpha: GLboolean, 2291 ) { 2292 unimplemented!("Not supported by SWGL"); 2293 } 2294 2295 fn copy_sub_texture_3d_angle( 2296 &self, 2297 _source_id: GLuint, 2298 _source_level: GLint, 2299 _dest_target: GLenum, 2300 _dest_id: GLuint, 2301 _dest_level: GLint, 2302 _x_offset: GLint, 2303 _y_offset: GLint, 2304 _z_offset: GLint, 2305 _x: GLint, 2306 _y: GLint, 2307 _z: GLint, 2308 _width: GLsizei, 2309 _height: GLsizei, 2310 _depth: GLsizei, 2311 _unpack_flip_y: GLboolean, 2312 _unpack_premultiply_alpha: GLboolean, 2313 _unpack_unmultiply_alpha: GLboolean, 2314 ) { 2315 unimplemented!("Not supported by SWGL"); 2316 } 2317 2318 fn buffer_storage( 2319 &self, 2320 target: GLenum, 2321 size: GLsizeiptr, 2322 data: *const GLvoid, 2323 flags: GLbitfield, 2324 ) { 2325 unimplemented!("Not supported by SWGL"); 2326 } 2327 2328 fn flush_mapped_buffer_range(&self, target: GLenum, offset: GLintptr, length: GLsizeiptr) { 2329 unimplemented!("Not supported by SWGL"); 2330 } 2331 2332 fn start_tiling_qcom( 2333 &self, 2334 x: GLuint, 2335 y: GLuint, 2336 width: GLuint, 2337 height: GLuint, 2338 preserve_mask: GLbitfield, 2339 ) { 2340 unimplemented!("Not supported by SWGL"); 2341 } 2342 2343 fn end_tiling_qcom(&self, preserve_mask: GLbitfield) { 2344 unimplemented!("Not supported by SWGL"); 2345 } 2346 } 2347 2348 /// A resource that is intended for sharing between threads. 2349 /// Locked resources such as textures or framebuffers will 2350 /// not allow any further modifications while it remains 2351 /// locked. The resource will be unlocked when LockedResource 2352 /// is dropped. 2353 pub struct LockedResource(*mut LockedTexture); 2354 2355 unsafe impl Send for LockedResource {} 2356 unsafe impl Sync for LockedResource {} 2357 2358 #[repr(u8)] 2359 pub enum YuvRangedColorSpace { 2360 Rec601Narrow = 0, 2361 Rec601Full, 2362 Rec709Narrow, 2363 Rec709Full, 2364 Rec2020Narrow, 2365 Rec2020Full, 2366 GbrIdentity, 2367 } 2368 2369 impl LockedResource { 2370 /// Composites from a locked resource to another locked resource. The band 2371 /// offset and height are relative to the destination rectangle and specify 2372 /// how to clip the composition into appropriate range for this band. 2373 pub fn composite( 2374 &self, 2375 locked_src: &LockedResource, 2376 src_x: GLint, 2377 src_y: GLint, 2378 src_width: GLsizei, 2379 src_height: GLsizei, 2380 dst_x: GLint, 2381 dst_y: GLint, 2382 dst_width: GLsizei, 2383 dst_height: GLsizei, 2384 opaque: bool, 2385 flip_x: bool, 2386 flip_y: bool, 2387 filter: GLenum, 2388 clip_x: GLint, 2389 clip_y: GLint, 2390 clip_width: GLsizei, 2391 clip_height: GLsizei, 2392 ) { 2393 unsafe { 2394 Composite( 2395 self.0, 2396 locked_src.0, 2397 src_x, 2398 src_y, 2399 src_width, 2400 src_height, 2401 dst_x, 2402 dst_y, 2403 dst_width, 2404 dst_height, 2405 opaque as GLboolean, 2406 flip_x as GLboolean, 2407 flip_y as GLboolean, 2408 filter, 2409 clip_x, 2410 clip_y, 2411 clip_width, 2412 clip_height, 2413 ); 2414 } 2415 } 2416 2417 /// Composites from locked resources representing YUV planes 2418 pub fn composite_yuv( 2419 &self, 2420 locked_y: &LockedResource, 2421 locked_u: &LockedResource, 2422 locked_v: &LockedResource, 2423 color_space: YuvRangedColorSpace, 2424 color_depth: GLuint, 2425 src_x: GLint, 2426 src_y: GLint, 2427 src_width: GLsizei, 2428 src_height: GLsizei, 2429 dst_x: GLint, 2430 dst_y: GLint, 2431 dst_width: GLsizei, 2432 dst_height: GLsizei, 2433 flip_x: bool, 2434 flip_y: bool, 2435 clip_x: GLint, 2436 clip_y: GLint, 2437 clip_width: GLsizei, 2438 clip_height: GLsizei, 2439 ) { 2440 unsafe { 2441 CompositeYUV( 2442 self.0, 2443 locked_y.0, 2444 locked_u.0, 2445 locked_v.0, 2446 color_space, 2447 color_depth, 2448 src_x, 2449 src_y, 2450 src_width, 2451 src_height, 2452 dst_x, 2453 dst_y, 2454 dst_width, 2455 dst_height, 2456 flip_x as GLboolean, 2457 flip_y as GLboolean, 2458 clip_x, 2459 clip_y, 2460 clip_width, 2461 clip_height, 2462 ); 2463 } 2464 } 2465 2466 /// Apply an R8 alpha mask to this surface 2467 pub fn apply_mask( 2468 &self, 2469 mask: &LockedResource, 2470 ) { 2471 unsafe { 2472 ApplyMask( 2473 self.0, 2474 mask.0, 2475 ); 2476 } 2477 } 2478 2479 /// Get the underlying buffer for a locked resource 2480 pub fn get_buffer(&self) -> (*mut c_void, i32, i32, i32) { 2481 unsafe { 2482 let mut width: i32 = 0; 2483 let mut height: i32 = 0; 2484 let mut stride: i32 = 0; 2485 let data_ptr = GetResourceBuffer(self.0, &mut width, &mut height, &mut stride); 2486 (data_ptr, width, height, stride) 2487 } 2488 } 2489 } 2490 2491 impl Clone for LockedResource { 2492 fn clone(&self) -> Self { 2493 unsafe { 2494 LockResource(self.0); 2495 } 2496 LockedResource(self.0) 2497 } 2498 } 2499 2500 impl Drop for LockedResource { 2501 fn drop(&mut self) { 2502 unsafe { 2503 UnlockResource(self.0); 2504 } 2505 } 2506 }