mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
sokol: type alias all sgl
structs, support sgl_context
(#13018)
This commit is contained in:
12
vlib/sokol/sgl/enums.v
Normal file
12
vlib/sokol/sgl/enums.v
Normal file
@ -0,0 +1,12 @@
|
||||
module sgl
|
||||
|
||||
// Error is C.sgl_error_t
|
||||
pub enum SglError {
|
||||
no_error = C.SGL_NO_ERROR // 0
|
||||
vertices_full = C.SGL_ERROR_VERTICES_FULL
|
||||
uniforms_full = C.SGL_ERROR_UNIFORMS_FULL
|
||||
commands_full = C.SGL_ERROR_COMMANDS_FULL
|
||||
stack_overflow = C.SGL_ERROR_STACK_OVERFLOW
|
||||
stack_underfloat = C.SGL_ERROR_STACK_UNDERFLOW
|
||||
no_context = C.SGL_ERROR_NO_CONTEXT
|
||||
}
|
@ -4,11 +4,12 @@ import sokol.gfx
|
||||
|
||||
pub const (
|
||||
version = gfx.version + 1
|
||||
context = Context{0x00010001} // C.SGL_DEFAULT_CONTEXT = { 0x00010001 }
|
||||
)
|
||||
|
||||
// setup/shutdown/misc
|
||||
[inline]
|
||||
pub fn setup(desc &C.sgl_desc_t) {
|
||||
pub fn setup(desc &Desc) {
|
||||
C.sgl_setup(desc)
|
||||
}
|
||||
|
||||
@ -18,13 +19,13 @@ pub fn shutdown() {
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn error() C.sgl_error_t {
|
||||
return C.sgl_error()
|
||||
pub fn error() SglError {
|
||||
return SglError(int(C.sgl_error()))
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn defaults() {
|
||||
C.sgl_defaults()
|
||||
pub fn context_error(ctx Context) SglError {
|
||||
return SglError(int(C.sgl_context_error(ctx)))
|
||||
}
|
||||
|
||||
[inline]
|
||||
@ -37,18 +38,54 @@ pub fn deg(rad f32) f32 {
|
||||
return C.sgl_deg(rad)
|
||||
}
|
||||
|
||||
// context functions
|
||||
[inline]
|
||||
pub fn make_context(desc &ContextDesc) Context {
|
||||
return C.sgl_make_context(desc)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn destroy_context(ctx Context) {
|
||||
C.sgl_destroy_context(ctx)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn set_context(ctx Context) {
|
||||
C.sgl_set_context(ctx)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn get_context() Context {
|
||||
return C.sgl_get_context()
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn default_context() Context {
|
||||
return C.sgl_default_context()
|
||||
}
|
||||
|
||||
// create and destroy pipeline objects
|
||||
[inline]
|
||||
pub fn make_pipeline(desc &gfx.PipelineDesc) C.sgl_pipeline {
|
||||
pub fn make_pipeline(desc &gfx.PipelineDesc) Pipeline {
|
||||
return C.sgl_make_pipeline(desc)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn destroy_pipeline(pip C.sgl_pipeline) {
|
||||
pub fn context_make_pipeline(ctx Context, desc &gfx.PipelineDesc) Pipeline {
|
||||
return C.sgl_context_make_pipeline(ctx, desc)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn destroy_pipeline(pip Pipeline) {
|
||||
C.sgl_destroy_pipeline(pip)
|
||||
}
|
||||
|
||||
// render state functions
|
||||
[inline]
|
||||
pub fn defaults() {
|
||||
C.sgl_defaults()
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn viewport(x int, y int, w int, h int, origin_top_left bool) {
|
||||
C.sgl_viewport(x, y, w, h, origin_top_left)
|
||||
@ -86,7 +123,7 @@ pub fn default_pipeline() {
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn load_pipeline(pip C.sgl_pipeline) {
|
||||
pub fn load_pipeline(pip Pipeline) {
|
||||
C.sgl_load_pipeline(pip)
|
||||
}
|
||||
|
||||
@ -373,8 +410,13 @@ pub fn end() {
|
||||
C.sgl_end()
|
||||
}
|
||||
|
||||
// render everything
|
||||
// render recorded commands
|
||||
[inline]
|
||||
pub fn draw() {
|
||||
C.sgl_draw()
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn context_draw(ctx Context) {
|
||||
C.sgl_context_draw(ctx)
|
||||
}
|
||||
|
@ -4,15 +4,24 @@ module sgl
|
||||
fn C.sgl_setup(desc &C.sgl_desc_t)
|
||||
fn C.sgl_shutdown()
|
||||
fn C.sgl_error() C.sgl_error_t
|
||||
fn C.sgl_defaults()
|
||||
fn C.sgl_context_error(ctx C.sgl_context) C.sgl_error_t
|
||||
fn C.sgl_rad(deg f32) f32
|
||||
fn C.sgl_deg(rad f32) f32
|
||||
|
||||
// context functions
|
||||
fn C.sgl_make_context(desc &C.sgl_context_desc_t) C.sgl_context
|
||||
fn C.sgl_destroy_context(ctx C.sgl_context)
|
||||
fn C.sgl_set_context(ctx C.sgl_context)
|
||||
fn C.sgl_get_context() C.sgl_context
|
||||
fn C.sgl_default_context() C.sgl_context
|
||||
|
||||
// create and destroy pipeline objects
|
||||
fn C.sgl_make_pipeline(desc &C.sg_pipeline_desc) C.sgl_pipeline
|
||||
fn C.sgl_context_make_pipeline(ctx C.sgl_context, desc &C.sg_pipeline_desc) C.sgl_pipeline
|
||||
fn C.sgl_destroy_pipeline(pip C.sgl_pipeline)
|
||||
|
||||
// render state functions
|
||||
fn C.sgl_defaults()
|
||||
fn C.sgl_viewport(x int, y int, w int, h int, origin_top_left bool)
|
||||
fn C.sgl_viewportf(x f32, y f32, w f32, h f32, origin_top_left bool)
|
||||
fn C.sgl_scissor_rect(x int, y int, w int, h int, origin_top_left bool)
|
||||
@ -87,5 +96,6 @@ fn C.sgl_v3f_t2f_c4b(x f32, y f32, z f32, u f32, v f32, r byte, g byte, b byte,
|
||||
fn C.sgl_v3f_t2f_c1i(x f32, y f32, z f32, u f32, v f32, rgba u32)
|
||||
fn C.sgl_end()
|
||||
|
||||
// render everything
|
||||
// render recorded commands
|
||||
fn C.sgl_draw()
|
||||
fn C.sgl_context_draw(ctx C.sgl_context)
|
||||
|
@ -1,24 +1,47 @@
|
||||
module sgl
|
||||
|
||||
// should be in a proper module
|
||||
pub enum SglError {
|
||||
no_error
|
||||
vertices_full
|
||||
commands_full
|
||||
stack_overflow
|
||||
stack_underfloat
|
||||
}
|
||||
import sokol.gfx
|
||||
|
||||
pub struct C.sgl_pipeline {
|
||||
[typedef]
|
||||
struct C.sgl_pipeline {
|
||||
id u32
|
||||
}
|
||||
|
||||
pub struct C.sgl_desc_t {
|
||||
pub type Pipeline = C.sgl_pipeline
|
||||
|
||||
[typedef]
|
||||
struct C.sgl_context {
|
||||
id u32
|
||||
}
|
||||
|
||||
pub type Context = C.sgl_context
|
||||
|
||||
// ContextDesc
|
||||
//
|
||||
// Describes the initialization parameters of a rendering context.
|
||||
// Creating additional contexts is useful if you want to render
|
||||
// in separate sokol-gfx passes.
|
||||
// ContextDesc is sgl_context_desc_t
|
||||
pub type ContextDesc = C.sgl_context_desc_t
|
||||
|
||||
[typedef]
|
||||
struct C.sgl_context_desc_t {
|
||||
max_vertices int // default: 64k
|
||||
max_commands int // default: 16k
|
||||
color_format gfx.PixelFormat // C.sg_pixel_format
|
||||
depth_format gfx.PixelFormat // C.sg_pixel_format
|
||||
sample_count int
|
||||
}
|
||||
|
||||
pub type Desc = C.sgl_desc_t
|
||||
|
||||
[typedef]
|
||||
struct C.sgl_desc_t {
|
||||
max_vertices int // size for vertex buffer
|
||||
max_commands int // size of uniform- and command-buffers
|
||||
pipeline_pool_size int // size of the internal pipeline pool, default is 64
|
||||
color_format C.sg_pixel_format
|
||||
depth_format C.sg_pixel_format
|
||||
color_format gfx.PixelFormat // C.sg_pixel_format
|
||||
depth_format gfx.PixelFormat // C.sg_pixel_format
|
||||
sample_count int
|
||||
face_winding C.sg_face_winding // default front face winding is CCW
|
||||
face_winding gfx.FaceWinding // C.sg_face_winding // default front face winding is CCW
|
||||
}
|
||||
|
Reference in New Issue
Block a user