Skip to content

Commit 24b7d22

Browse files
committed
Fix glGetShaderInfoLog and glGetProgramInfoLog
1 parent 23ec0e5 commit 24b7d22

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/gl/mod.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub enum ShaderType {
3535
Compute = ffi::GL_COMPUTE_SHADER,
3636
}
3737

38+
#[derive(Copy, Clone)]
3839
#[repr(u32)]
3940
pub enum DrawMode {
4041
Points = ffi::GL_POINTS,
@@ -266,12 +267,18 @@ pub unsafe fn get_shader_info_log(shader: Shader) -> String {
266267
ffi::glGetShaderiv(shader.0.get(), ffi::GL_INFO_LOG_LENGTH, &mut length);
267268

268269
if length > 0 {
269-
let mut log = String::with_capacity(length as _);
270+
use core::mem::MaybeUninit;
271+
272+
use alloc::vec::Vec;
273+
274+
let mut log: Vec<MaybeUninit<u8>> = Vec::with_capacity(length as _);
270275

271276
ffi::glGetShaderInfoLog(shader.0.get(), length, &mut length, log.as_mut_ptr() as _);
272277

273-
log.truncate(length as _);
274-
log
278+
log.set_len(length as _);
279+
280+
let log: Vec<u8> = core::mem::transmute(log);
281+
String::from_utf8_unchecked(log)
275282
} else {
276283
String::new()
277284
}
@@ -311,12 +318,18 @@ pub unsafe fn get_program_info_log(program: Program) -> String {
311318
ffi::glGetProgramiv(program.0.get(), ffi::GL_INFO_LOG_LENGTH, &mut length);
312319

313320
if length > 0 {
314-
let mut log = String::with_capacity(length as _);
321+
use core::mem::MaybeUninit;
322+
323+
use alloc::vec::Vec;
324+
325+
let mut log: Vec<MaybeUninit<u8>> = Vec::with_capacity(length as _);
315326

316327
ffi::glGetProgramInfoLog(program.0.get(), length, &mut length, log.as_mut_ptr() as _);
317328

318-
log.truncate(length as _);
319-
log
329+
log.set_len(length as _);
330+
331+
let log: Vec<u8> = core::mem::transmute(log);
332+
String::from_utf8_unchecked(log)
320333
} else {
321334
String::new()
322335
}
@@ -533,3 +546,6 @@ pub unsafe fn viewport(x: i32, y: i32, width: i32, height: i32) {
533546

534547
//TODO Make functions for all of these:
535548
// glNamedBufferStorage
549+
//
550+
// glDebugMessageCallback
551+
// glDebugMessageControl

0 commit comments

Comments
 (0)