mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-19 04:50:29 +00:00
More allocator-aware webgl bindings and added more missing bindings.
This commit is contained in:
@@ -646,6 +646,27 @@ class WebGLInterface {
|
||||
}
|
||||
},
|
||||
|
||||
GetActiveUniform: (program, index, size_ptr, type_ptr, name_buf_ptr, name_buf_len, name_len_ptr) => {
|
||||
let info = this.ctx.getActiveUniform(program, index);
|
||||
|
||||
if (size_ptr) {
|
||||
this.mem.storeInt(size_ptr, info.size);
|
||||
}
|
||||
|
||||
if (type_ptr) {
|
||||
this.mem.storeI32(type_ptr, info.type);
|
||||
}
|
||||
|
||||
if name_buf_ptr && name_buf_len > 0 {
|
||||
let n = Math.min(name_buf_len, info.name.length);
|
||||
let name = info.name.substring(0, n);
|
||||
this.mem.loadBytes(name_buf_ptr, name_buf_len).set(new TextEncoder().encode(name));
|
||||
this.mem.storeInt(name_len_ptr, n);
|
||||
} else if name_len_ptr {
|
||||
this.mem.storeInt(name_len_ptr, info.name.length);
|
||||
}
|
||||
},
|
||||
|
||||
GetAttribLocation: (program, name_ptr, name_len) => {
|
||||
let name = this.mem.loadString(name_ptr, name_len);
|
||||
return this.ctx.getAttribLocation(this.programs[program], name);
|
||||
|
||||
37
vendor/wasm/WebGL/webgl.odin
vendored
37
vendor/wasm/WebGL/webgl.odin
vendored
@@ -313,6 +313,43 @@ GetActiveAttrib :: proc {
|
||||
GetActiveAttribAlloc,
|
||||
}
|
||||
|
||||
GetActiveUniformBuf :: proc "contextless" (program: Program, index: u32, name_buf: []byte) -> (info: ActiveInfo) {
|
||||
foreign webgl {
|
||||
@(link_name="GetActiveUniform")
|
||||
_GetActiveUniform :: proc "contextless" (shader: Program, index: u32, size: ^int, type: ^Enum, name_buf: []byte, name_len: ^int) ---
|
||||
}
|
||||
name_len: int
|
||||
_GetActiveUniform(program, index, &info.size, &info.type, name_buf, &name_len)
|
||||
info.name = string(name_buf[:name_len])
|
||||
return
|
||||
}
|
||||
|
||||
GetActiveUniformAlloc :: proc(program: Program, index: u32, allocator: runtime.Allocator, loc := #caller_location) -> (info: ActiveInfo) {
|
||||
foreign webgl {
|
||||
@(link_name="GetActiveUniform")
|
||||
_GetActiveUniform :: proc "contextless" (shader: Program, index: u32, size: ^int, type: ^Enum, name_buf: []byte, name_len: ^int) ---
|
||||
}
|
||||
|
||||
name_len: int
|
||||
|
||||
// Passing {} to the buf but giving it a name_len ptr will write the needed len into that int
|
||||
_GetActiveUniform(program, index, &info.size, &info.type, {}, &name_len)
|
||||
|
||||
if name_len > 0 {
|
||||
name_buf := make([]byte, name_len, allocator, loc)
|
||||
_GetActiveUniform(program, index, &info.size, &info.type, name_buf, &name_len)
|
||||
assert(name_len == len(name_buf))
|
||||
info.name = string(name_buf[:name_len])
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
GetActiveUniform :: proc {
|
||||
GetActiveUniformBuf,
|
||||
GetActiveUniformAlloc,
|
||||
}
|
||||
|
||||
GetProgramInfoLog :: proc "contextless" (program: Program, buf: []byte) -> string {
|
||||
foreign webgl {
|
||||
@(link_name="GetProgramInfoLog")
|
||||
|
||||
25
vendor/wasm/WebGL/webgl2.odin
vendored
25
vendor/wasm/WebGL/webgl2.odin
vendored
@@ -3,6 +3,7 @@ package webgl
|
||||
foreign import "webgl2"
|
||||
|
||||
import "base:intrinsics"
|
||||
import "base:runtime"
|
||||
import glm "core:math/linalg/glsl"
|
||||
|
||||
Query :: distinct u32
|
||||
@@ -109,7 +110,7 @@ foreign webgl2 {
|
||||
BindVertexArray :: proc(vertexArray: VertexArrayObject) ---
|
||||
}
|
||||
|
||||
GetActiveUniformBlockName :: proc(program: Program, uniformBlockIndex: i32, buf: []byte) -> string {
|
||||
GetActiveUniformBlockNameBuf :: proc(program: Program, uniformBlockIndex: i32, buf: []byte) -> string {
|
||||
foreign webgl2 {
|
||||
_GetActiveUniformBlockName :: proc "contextless" (program: Program, uniformBlockIndex: i32, buf: []byte, length: ^int) ---
|
||||
}
|
||||
@@ -118,6 +119,28 @@ GetActiveUniformBlockName :: proc(program: Program, uniformBlockIndex: i32, buf:
|
||||
return string(buf[:n])
|
||||
}
|
||||
|
||||
GetActiveUniformBlockNameAlloc :: proc(program: Program, uniformBlockIndex: i32, allocator: runtime.Allocator, loc := #caller_location) -> string {
|
||||
foreign webgl2 {
|
||||
_GetActiveUniformBlockName :: proc "contextless" (program: Program, uniformBlockIndex: i32, buf: []byte, length: ^int) ---
|
||||
}
|
||||
n: int
|
||||
_GetActiveUniformBlockName(program, uniformBlockIndex, {}, &n)
|
||||
|
||||
if n > 0 {
|
||||
buf := make([]byte, n, allocator, loc)
|
||||
_GetActiveUniformBlockName(program, uniformBlockIndex, buf, &n)
|
||||
assert(n == len(buf))
|
||||
return string(buf[:n])
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
GetActiveUniformBlockName :: proc {
|
||||
GetActiveUniformBlockNameBuf,
|
||||
GetActiveUniformBlockNameAlloc,
|
||||
}
|
||||
|
||||
|
||||
Uniform1uiv :: proc "contextless" (location: i32, v: u32) {
|
||||
Uniform1ui(location, v)
|
||||
|
||||
Reference in New Issue
Block a user