sokol: type alias all `sgl` structs, support `sgl_context` (#13018)
parent
9974495f5e
commit
88a973b617
|
@ -26,7 +26,7 @@ const (
|
||||||
struct App {
|
struct App {
|
||||||
mut:
|
mut:
|
||||||
gg &gg.Context
|
gg &gg.Context
|
||||||
pip_3d C.sgl_pipeline
|
pip_3d sgl.Pipeline
|
||||||
texture gfx.Image
|
texture gfx.Image
|
||||||
init_flag bool
|
init_flag bool
|
||||||
frame_count int
|
frame_count int
|
||||||
|
@ -315,7 +315,7 @@ fn my_init(mut app App) {
|
||||||
// for a large number of the same type of object it is better use the instances!!
|
// for a large number of the same type of object it is better use the instances!!
|
||||||
desc := sapp.create_desc()
|
desc := sapp.create_desc()
|
||||||
gfx.setup(&desc)
|
gfx.setup(&desc)
|
||||||
sgl_desc := C.sgl_desc_t{
|
sgl_desc := sgl.Desc{
|
||||||
max_vertices: 50 * 65536
|
max_vertices: 50 * 65536
|
||||||
}
|
}
|
||||||
sgl.setup(&sgl_desc)
|
sgl.setup(&sgl_desc)
|
||||||
|
|
|
@ -37,7 +37,7 @@ const (
|
||||||
struct App {
|
struct App {
|
||||||
mut:
|
mut:
|
||||||
gg &gg.Context
|
gg &gg.Context
|
||||||
pip_3d C.sgl_pipeline
|
pip_3d sgl.Pipeline
|
||||||
texture gfx.Image
|
texture gfx.Image
|
||||||
init_flag bool
|
init_flag bool
|
||||||
frame_count int
|
frame_count int
|
||||||
|
@ -486,7 +486,7 @@ fn my_init(mut app App) {
|
||||||
// for a large number of the same type of object it is better use the instances!!
|
// for a large number of the same type of object it is better use the instances!!
|
||||||
desc := sapp.create_desc()
|
desc := sapp.create_desc()
|
||||||
gfx.setup(&desc)
|
gfx.setup(&desc)
|
||||||
sgl_desc := C.sgl_desc_t{
|
sgl_desc := sgl.Desc{
|
||||||
max_vertices: 50 * 65536
|
max_vertices: 50 * 65536
|
||||||
}
|
}
|
||||||
sgl.setup(&sgl_desc)
|
sgl.setup(&sgl_desc)
|
||||||
|
|
|
@ -325,7 +325,7 @@ fn my_init(mut app App) {
|
||||||
// for a large number of the same type of object it is better use the instances!!
|
// for a large number of the same type of object it is better use the instances!!
|
||||||
desc := sapp.create_desc()
|
desc := sapp.create_desc()
|
||||||
gfx.setup(&desc)
|
gfx.setup(&desc)
|
||||||
sgl_desc := C.sgl_desc_t{
|
sgl_desc := sgl.Desc{
|
||||||
max_vertices: 50 * 65536
|
max_vertices: 50 * 65536
|
||||||
}
|
}
|
||||||
sgl.setup(&sgl_desc)
|
sgl.setup(&sgl_desc)
|
||||||
|
|
|
@ -513,7 +513,7 @@ fn my_init(mut app App) {
|
||||||
// for a large number of the same type of object it is better use the instances!!
|
// for a large number of the same type of object it is better use the instances!!
|
||||||
desc := sapp.create_desc()
|
desc := sapp.create_desc()
|
||||||
gfx.setup(&desc)
|
gfx.setup(&desc)
|
||||||
sgl_desc := C.sgl_desc_t{
|
sgl_desc := sgl.Desc{
|
||||||
max_vertices: 50 * 65536
|
max_vertices: 50 * 65536
|
||||||
}
|
}
|
||||||
sgl.setup(&sgl_desc)
|
sgl.setup(&sgl_desc)
|
||||||
|
|
|
@ -212,7 +212,7 @@ fn my_init(mut app App) {
|
||||||
// for a large number of the same type of object it is better use the instances!!
|
// for a large number of the same type of object it is better use the instances!!
|
||||||
desc := sapp.create_desc()
|
desc := sapp.create_desc()
|
||||||
gfx.setup(&desc)
|
gfx.setup(&desc)
|
||||||
sgl_desc := C.sgl_desc_t{
|
sgl_desc := sgl.Desc{
|
||||||
max_vertices: 128 * 65536
|
max_vertices: 128 * 65536
|
||||||
}
|
}
|
||||||
sgl.setup(&sgl_desc)
|
sgl.setup(&sgl_desc)
|
||||||
|
|
|
@ -29,7 +29,7 @@ fn main() {
|
||||||
fn init(user_data voidptr) {
|
fn init(user_data voidptr) {
|
||||||
desc := sapp.create_desc() // gfx.Desc{
|
desc := sapp.create_desc() // gfx.Desc{
|
||||||
gfx.setup(&desc)
|
gfx.setup(&desc)
|
||||||
sgl_desc := C.sgl_desc_t{}
|
sgl_desc := sgl.Desc{}
|
||||||
sgl.setup(&sgl_desc)
|
sgl.setup(&sgl_desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ fn main() {
|
||||||
fn init(mut state AppState) {
|
fn init(mut state AppState) {
|
||||||
desc := sapp.create_desc()
|
desc := sapp.create_desc()
|
||||||
gfx.setup(&desc)
|
gfx.setup(&desc)
|
||||||
s := &C.sgl_desc_t{}
|
s := &sgl.Desc{}
|
||||||
C.sgl_setup(s)
|
C.sgl_setup(s)
|
||||||
state.fons = sfons.create(512, 512, 1)
|
state.fons = sfons.create(512, 512, 1)
|
||||||
// or use DroidSerif-Regular.ttf
|
// or use DroidSerif-Regular.ttf
|
||||||
|
|
|
@ -96,7 +96,7 @@ fn init(user_data voidptr) {
|
||||||
mut state := &AppState(user_data)
|
mut state := &AppState(user_data)
|
||||||
desc := sapp.create_desc()
|
desc := sapp.create_desc()
|
||||||
gfx.setup(&desc)
|
gfx.setup(&desc)
|
||||||
s := &C.sgl_desc_t{}
|
s := &sgl.Desc{}
|
||||||
C.sgl_setup(s)
|
C.sgl_setup(s)
|
||||||
state.fons = sfons.create(512, 512, 1)
|
state.fons = sfons.create(512, 512, 1)
|
||||||
// or use DroidSerif-Regular.ttf
|
// or use DroidSerif-Regular.ttf
|
||||||
|
|
|
@ -31,7 +31,7 @@ mut:
|
||||||
frame i64
|
frame i64
|
||||||
last i64
|
last i64
|
||||||
ps particle.System
|
ps particle.System
|
||||||
alpha_pip C.sgl_pipeline
|
alpha_pip sgl.Pipeline
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut a App) init() {
|
fn (mut a App) init() {
|
||||||
|
@ -75,7 +75,7 @@ fn init(user_data voidptr) {
|
||||||
mut app := &App(user_data)
|
mut app := &App(user_data)
|
||||||
desc := sapp.create_desc()
|
desc := sapp.create_desc()
|
||||||
gfx.setup(&desc)
|
gfx.setup(&desc)
|
||||||
sgl_desc := C.sgl_desc_t{
|
sgl_desc := sgl.Desc{
|
||||||
max_vertices: 50 * 65536
|
max_vertices: 50 * 65536
|
||||||
}
|
}
|
||||||
sgl.setup(&sgl_desc)
|
sgl.setup(&sgl_desc)
|
||||||
|
|
|
@ -61,7 +61,7 @@ enum Viewer_state {
|
||||||
struct App {
|
struct App {
|
||||||
mut:
|
mut:
|
||||||
gg &gg.Context
|
gg &gg.Context
|
||||||
pip_viewer C.sgl_pipeline
|
pip_viewer sgl.Pipeline
|
||||||
texture gfx.Image
|
texture gfx.Image
|
||||||
init_flag bool
|
init_flag bool
|
||||||
frame_count int
|
frame_count int
|
||||||
|
|
|
@ -111,7 +111,7 @@ pub mut:
|
||||||
height int
|
height int
|
||||||
clear_pass gfx.PassAction
|
clear_pass gfx.PassAction
|
||||||
window sapp.Desc
|
window sapp.Desc
|
||||||
timage_pip C.sgl_pipeline
|
timage_pip sgl.Pipeline
|
||||||
config Config
|
config Config
|
||||||
user_data voidptr
|
user_data voidptr
|
||||||
ft &FT
|
ft &FT
|
||||||
|
@ -150,7 +150,7 @@ fn gg_init_sokol_window(user_data voidptr) {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
gfx.setup(&desc)
|
gfx.setup(&desc)
|
||||||
sgl_desc := C.sgl_desc_t{}
|
sgl_desc := sgl.Desc{}
|
||||||
sgl.setup(&sgl_desc)
|
sgl.setup(&sgl_desc)
|
||||||
g.scale = dpi_scale()
|
g.scale = dpi_scale()
|
||||||
// is_high_dpi := sapp.high_dpi()
|
// is_high_dpi := sapp.high_dpi()
|
||||||
|
|
|
@ -11,6 +11,7 @@ pub enum Backend {
|
||||||
dummy
|
dummy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PixelFormat is C.sg_pixel_format
|
||||||
pub enum PixelFormat {
|
pub enum PixelFormat {
|
||||||
_default // value 0 reserved for default-init
|
_default // value 0 reserved for default-init
|
||||||
@none
|
@none
|
||||||
|
@ -216,6 +217,7 @@ pub enum CullMode {
|
||||||
_num
|
_num
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FaceWindin is C.sg_face_winding
|
||||||
pub enum FaceWinding {
|
pub enum FaceWinding {
|
||||||
_facewinding_default // value 0 reserved for default-init
|
_facewinding_default // value 0 reserved for default-init
|
||||||
facewinding_ccw
|
facewinding_ccw
|
||||||
|
|
|
@ -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 (
|
pub const (
|
||||||
version = gfx.version + 1
|
version = gfx.version + 1
|
||||||
|
context = Context{0x00010001} // C.SGL_DEFAULT_CONTEXT = { 0x00010001 }
|
||||||
)
|
)
|
||||||
|
|
||||||
// setup/shutdown/misc
|
// setup/shutdown/misc
|
||||||
[inline]
|
[inline]
|
||||||
pub fn setup(desc &C.sgl_desc_t) {
|
pub fn setup(desc &Desc) {
|
||||||
C.sgl_setup(desc)
|
C.sgl_setup(desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,13 +19,13 @@ pub fn shutdown() {
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn error() C.sgl_error_t {
|
pub fn error() SglError {
|
||||||
return C.sgl_error()
|
return SglError(int(C.sgl_error()))
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn defaults() {
|
pub fn context_error(ctx Context) SglError {
|
||||||
C.sgl_defaults()
|
return SglError(int(C.sgl_context_error(ctx)))
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
|
@ -37,18 +38,54 @@ pub fn deg(rad f32) f32 {
|
||||||
return C.sgl_deg(rad)
|
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
|
// create and destroy pipeline objects
|
||||||
[inline]
|
[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)
|
return C.sgl_make_pipeline(desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[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)
|
C.sgl_destroy_pipeline(pip)
|
||||||
}
|
}
|
||||||
|
|
||||||
// render state functions
|
// render state functions
|
||||||
|
[inline]
|
||||||
|
pub fn defaults() {
|
||||||
|
C.sgl_defaults()
|
||||||
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn viewport(x int, y int, w int, h int, origin_top_left bool) {
|
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)
|
C.sgl_viewport(x, y, w, h, origin_top_left)
|
||||||
|
@ -86,7 +123,7 @@ pub fn default_pipeline() {
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn load_pipeline(pip C.sgl_pipeline) {
|
pub fn load_pipeline(pip Pipeline) {
|
||||||
C.sgl_load_pipeline(pip)
|
C.sgl_load_pipeline(pip)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,8 +410,13 @@ pub fn end() {
|
||||||
C.sgl_end()
|
C.sgl_end()
|
||||||
}
|
}
|
||||||
|
|
||||||
// render everything
|
// render recorded commands
|
||||||
[inline]
|
[inline]
|
||||||
pub fn draw() {
|
pub fn draw() {
|
||||||
C.sgl_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_setup(desc &C.sgl_desc_t)
|
||||||
fn C.sgl_shutdown()
|
fn C.sgl_shutdown()
|
||||||
fn C.sgl_error() C.sgl_error_t
|
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_rad(deg f32) f32
|
||||||
fn C.sgl_deg(rad 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
|
// create and destroy pipeline objects
|
||||||
fn C.sgl_make_pipeline(desc &C.sg_pipeline_desc) C.sgl_pipeline
|
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)
|
fn C.sgl_destroy_pipeline(pip C.sgl_pipeline)
|
||||||
|
|
||||||
// render state functions
|
// 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_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_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)
|
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_v3f_t2f_c1i(x f32, y f32, z f32, u f32, v f32, rgba u32)
|
||||||
fn C.sgl_end()
|
fn C.sgl_end()
|
||||||
|
|
||||||
// render everything
|
// render recorded commands
|
||||||
fn C.sgl_draw()
|
fn C.sgl_draw()
|
||||||
|
fn C.sgl_context_draw(ctx C.sgl_context)
|
||||||
|
|
|
@ -1,24 +1,47 @@
|
||||||
module sgl
|
module sgl
|
||||||
|
|
||||||
// should be in a proper module
|
import sokol.gfx
|
||||||
pub enum SglError {
|
|
||||||
no_error
|
|
||||||
vertices_full
|
|
||||||
commands_full
|
|
||||||
stack_overflow
|
|
||||||
stack_underfloat
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct C.sgl_pipeline {
|
[typedef]
|
||||||
|
struct C.sgl_pipeline {
|
||||||
id u32
|
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_vertices int // size for vertex buffer
|
||||||
max_commands int // size of uniform- and command-buffers
|
max_commands int // size of uniform- and command-buffers
|
||||||
pipeline_pool_size int // size of the internal pipeline pool, default is 64
|
pipeline_pool_size int // size of the internal pipeline pool, default is 64
|
||||||
color_format C.sg_pixel_format
|
color_format gfx.PixelFormat // C.sg_pixel_format
|
||||||
depth_format C.sg_pixel_format
|
depth_format gfx.PixelFormat // C.sg_pixel_format
|
||||||
sample_count int
|
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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue