sdl3 hello world gpu working
This commit is contained in:
parent
6eb7036182
commit
3b65cdb8f5
|
|
@ -2231,7 +2231,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetGPUDriver(int index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the name of the backend used to create this GPU context.
|
* Returns the name of the backend used to create this GPU context.
|
||||||
*
|
|
||||||
* \param device a GPU context to query.
|
* \param device a GPU context to query.
|
||||||
* \returns the name of the device's driver, or NULL on error.
|
* \returns the name of the device's driver, or NULL on error.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,118 @@
|
||||||
|
pub const first: u32 = 0;
|
||||||
|
pub const quit: u32 = 256;
|
||||||
|
pub const terminating: u32 = 257;
|
||||||
|
pub const low_memory: u32 = 258;
|
||||||
|
pub const will_enter_background: u32 = 259;
|
||||||
|
pub const did_enter_background: u32 = 260;
|
||||||
|
pub const will_enter_foreground: u32 = 261;
|
||||||
|
pub const did_enter_foreground: u32 = 262;
|
||||||
|
pub const locale_changed: u32 = 263;
|
||||||
|
pub const system_theme_changed: u32 = 264;
|
||||||
|
pub const display_orientation: u32 = 337;
|
||||||
|
pub const display_added: u32 = 338;
|
||||||
|
pub const display_removed: u32 = 339;
|
||||||
|
pub const display_moved: u32 = 340;
|
||||||
|
pub const display_desktop_mode_changed: u32 = 341;
|
||||||
|
pub const display_current_mode_changed: u32 = 342;
|
||||||
|
pub const display_content_scale_changed: u32 = 343;
|
||||||
|
pub const display_first: u32 = 337;
|
||||||
|
pub const display_last: u32 = 343;
|
||||||
|
pub const window_shown: u32 = 514;
|
||||||
|
pub const window_hidden: u32 = 515;
|
||||||
|
pub const window_exposed: u32 = 516;
|
||||||
|
pub const window_moved: u32 = 517;
|
||||||
|
pub const window_resized: u32 = 518;
|
||||||
|
pub const window_pixel_size_changed: u32 = 519;
|
||||||
|
pub const window_metal_view_resized: u32 = 520;
|
||||||
|
pub const window_minimized: u32 = 521;
|
||||||
|
pub const window_maximized: u32 = 522;
|
||||||
|
pub const window_restored: u32 = 523;
|
||||||
|
pub const window_mouse_enter: u32 = 524;
|
||||||
|
pub const window_mouse_leave: u32 = 525;
|
||||||
|
pub const window_focus_gained: u32 = 526;
|
||||||
|
pub const window_focus_lost: u32 = 527;
|
||||||
|
pub const window_close_requested: u32 = 528;
|
||||||
|
pub const window_hit_test: u32 = 529;
|
||||||
|
pub const window_iccprof_changed: u32 = 530;
|
||||||
|
pub const window_display_changed: u32 = 531;
|
||||||
|
pub const window_display_scale_changed: u32 = 532;
|
||||||
|
pub const window_safe_area_changed: u32 = 533;
|
||||||
|
pub const window_occluded: u32 = 534;
|
||||||
|
pub const window_enter_fullscreen: u32 = 535;
|
||||||
|
pub const window_leave_fullscreen: u32 = 536;
|
||||||
|
pub const window_destroyed: u32 = 537;
|
||||||
|
pub const window_hdr_state_changed: u32 = 538;
|
||||||
|
pub const window_first: u32 = 514;
|
||||||
|
pub const window_last: u32 = 538;
|
||||||
|
pub const key_down: u32 = 768;
|
||||||
|
pub const key_up: u32 = 769;
|
||||||
|
pub const text_editing: u32 = 770;
|
||||||
|
pub const text_input: u32 = 771;
|
||||||
|
pub const keymap_changed: u32 = 772;
|
||||||
|
pub const keyboard_added: u32 = 773;
|
||||||
|
pub const keyboard_removed: u32 = 774;
|
||||||
|
pub const text_editing_candidates: u32 = 775;
|
||||||
|
pub const mouse_motion: u32 = 1024;
|
||||||
|
pub const mouse_button_down: u32 = 1025;
|
||||||
|
pub const mouse_button_up: u32 = 1026;
|
||||||
|
pub const mouse_wheel: u32 = 1027;
|
||||||
|
pub const mouse_added: u32 = 1028;
|
||||||
|
pub const mouse_removed: u32 = 1029;
|
||||||
|
pub const joystick_axis_motion: u32 = 1536;
|
||||||
|
pub const joystick_ball_motion: u32 = 1537;
|
||||||
|
pub const joystick_hat_motion: u32 = 1538;
|
||||||
|
pub const joystick_button_down: u32 = 1539;
|
||||||
|
pub const joystick_button_up: u32 = 1540;
|
||||||
|
pub const joystick_added: u32 = 1541;
|
||||||
|
pub const joystick_removed: u32 = 1542;
|
||||||
|
pub const joystick_battery_updated: u32 = 1543;
|
||||||
|
pub const joystick_update_complete: u32 = 1544;
|
||||||
|
pub const gamepad_axis_motion: u32 = 1616;
|
||||||
|
pub const gamepad_button_down: u32 = 1617;
|
||||||
|
pub const gamepad_button_up: u32 = 1618;
|
||||||
|
pub const gamepad_added: u32 = 1619;
|
||||||
|
pub const gamepad_removed: u32 = 1620;
|
||||||
|
pub const gamepad_remapped: u32 = 1621;
|
||||||
|
pub const gamepad_touchpad_down: u32 = 1622;
|
||||||
|
pub const gamepad_touchpad_motion: u32 = 1623;
|
||||||
|
pub const gamepad_touchpad_up: u32 = 1624;
|
||||||
|
pub const gamepad_sensor_update: u32 = 1625;
|
||||||
|
pub const gamepad_update_complete: u32 = 1626;
|
||||||
|
pub const gamepad_steam_handle_updated: u32 = 1627;
|
||||||
|
pub const finger_down: u32 = 1792;
|
||||||
|
pub const finger_up: u32 = 1793;
|
||||||
|
pub const finger_motion: u32 = 1794;
|
||||||
|
pub const finger_canceled: u32 = 1795;
|
||||||
|
pub const clipboard_update: u32 = 2304;
|
||||||
|
pub const drop_file: u32 = 4096;
|
||||||
|
pub const drop_text: u32 = 4097;
|
||||||
|
pub const drop_begin: u32 = 4098;
|
||||||
|
pub const drop_complete: u32 = 4099;
|
||||||
|
pub const drop_position: u32 = 4100;
|
||||||
|
pub const audio_device_added: u32 = 4352;
|
||||||
|
pub const audio_device_removed: u32 = 4353;
|
||||||
|
pub const audio_device_format_changed: u32 = 4354;
|
||||||
|
pub const sensor_update: u32 = 4608;
|
||||||
|
pub const pen_proximity_in: u32 = 4864;
|
||||||
|
pub const pen_proximity_out: u32 = 4865;
|
||||||
|
pub const pen_down: u32 = 4866;
|
||||||
|
pub const pen_up: u32 = 4867;
|
||||||
|
pub const pen_button_down: u32 = 4868;
|
||||||
|
pub const pen_button_up: u32 = 4869;
|
||||||
|
pub const pen_motion: u32 = 4870;
|
||||||
|
pub const pen_axis: u32 = 4871;
|
||||||
|
pub const camera_device_added: u32 = 5120;
|
||||||
|
pub const camera_device_removed: u32 = 5121;
|
||||||
|
pub const camera_device_approved: u32 = 5122;
|
||||||
|
pub const camera_device_denied: u32 = 5123;
|
||||||
|
pub const render_targets_reset: u32 = 8192;
|
||||||
|
pub const render_device_reset: u32 = 8193;
|
||||||
|
pub const render_device_lost: u32 = 8194;
|
||||||
|
pub const private0: u32 = 16384;
|
||||||
|
pub const private1: u32 = 16385;
|
||||||
|
pub const private2: u32 = 16386;
|
||||||
|
pub const private3: u32 = 16387;
|
||||||
|
pub const poll_sentinel: u32 = 32512;
|
||||||
|
pub const user: u32 = 32768;
|
||||||
|
pub const last: u32 = 65535;
|
||||||
|
pub const enum_padding: u32 = 2147483647;
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
import math
|
import math
|
||||||
|
|
@ -23,7 +24,25 @@ def convertCase(x):
|
||||||
origDir = os.path.abspath(os.path.dirname(__file__))
|
origDir = os.path.abspath(os.path.dirname(__file__))
|
||||||
os.chdir(origDir)
|
os.chdir(origDir)
|
||||||
|
|
||||||
gpufile = "../../SDL/include/SDL3/SDL_gpu.h"
|
infile = "../../SDL/include/SDL3/SDL_gpu.h"
|
||||||
|
ofile = os.path.abspath(os.path.join(origDir, '../gpu.zig'))
|
||||||
|
|
||||||
|
SDL_files = [
|
||||||
|
'SDL_gpu.h',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
typeMap = {
|
||||||
|
'Uint32': 'u32', 'float': 'f32', 'Sint32': 'i32', 'bool': 'bool', 'Uint8': 'u8', 'SDL_PropertiesID': 'PropertiesID','char': 'u8',
|
||||||
|
'void': 'void',
|
||||||
|
'int': 'c_int',
|
||||||
|
'size_t': 'usize',
|
||||||
|
'SDL_Window': 'Window',
|
||||||
|
}
|
||||||
|
|
||||||
|
typeMap_r = {}
|
||||||
|
|
||||||
|
def generateAll(infile, ofile):
|
||||||
|
|
||||||
mode_default = 0
|
mode_default = 0
|
||||||
mode_collecting = 1
|
mode_collecting = 1
|
||||||
|
|
@ -40,7 +59,7 @@ defines = []
|
||||||
|
|
||||||
lastList = None
|
lastList = None
|
||||||
|
|
||||||
with open(gpufile) as rf:
|
with open(infile) as rf:
|
||||||
mode = mode_default
|
mode = mode_default
|
||||||
braceCount = 0
|
braceCount = 0
|
||||||
f = rf.readlines()
|
f = rf.readlines()
|
||||||
|
|
@ -54,6 +73,14 @@ typedef struct SDL_FColor {
|
||||||
float a;
|
float a;
|
||||||
} SDL_FColor;
|
} SDL_FColor;
|
||||||
|
|
||||||
|
typedef struct SDL_Rect
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int w;
|
||||||
|
int h;
|
||||||
|
} SDL_Rect;
|
||||||
|
|
||||||
typedef enum SDL_FlipMode {
|
typedef enum SDL_FlipMode {
|
||||||
|
|
||||||
SDL_FLIP_NONE, /**< Do not flip */
|
SDL_FLIP_NONE, /**< Do not flip */
|
||||||
|
|
@ -146,21 +173,16 @@ if print_defines:
|
||||||
|
|
||||||
print(f"\nfunctions: {len(functions)}, structs:{len(typedefs_struct)}, enums:{len(typedefs_enum)}\n")
|
print(f"\nfunctions: {len(functions)}, structs:{len(typedefs_struct)}, enums:{len(typedefs_enum)}\n")
|
||||||
|
|
||||||
ostring = 'pub const c = @import("c.zig").c;\n\npub const PropertiesID = u32;'
|
ostring = 'pub const c = @import("c.zig").c;\n\npub const PropertiesID = u32;\n pub const Window = c.SDL_Window;'
|
||||||
# time to generate types...
|
# time to generate types...
|
||||||
# first the opaques
|
# first the opaques
|
||||||
|
|
||||||
ostring += '\n'
|
ostring += '\n'
|
||||||
|
|
||||||
typeMap = {
|
opaques = {'Window': ''}
|
||||||
'Uint32': 'u32', 'float': 'f32', 'Sint32': 'i32', 'bool': 'bool', 'Uint8': 'u8', 'SDL_PropertiesID': 'PropertiesID','char': 'i8',
|
enums = {}
|
||||||
'size_t': 'usize',
|
|
||||||
'SDL_FColor': 'FColor',
|
|
||||||
'SDL_FlipMode': 'FlipMode'
|
|
||||||
}
|
|
||||||
|
|
||||||
typeMap_r = {}
|
|
||||||
|
|
||||||
|
opaqueOrder = []
|
||||||
|
|
||||||
for t in typedefs_pod:
|
for t in typedefs_pod:
|
||||||
c_typename = t.strip().strip(';').split(' ')[-1]
|
c_typename = t.strip().strip(';').split(' ')[-1]
|
||||||
|
|
@ -184,8 +206,11 @@ for t in typedefs_opaque:
|
||||||
typeMap_r[typename] = c_typename
|
typeMap_r[typename] = c_typename
|
||||||
|
|
||||||
brackets = "{}"
|
brackets = "{}"
|
||||||
definition = f"pub const {typename} = opaque{brackets};\n"
|
definition = f"pub const {typename} = opaque {{\n"
|
||||||
ostring += definition
|
# ostring += definition
|
||||||
|
opaques[typename] = definition
|
||||||
|
opaqueOrder.append(typename)
|
||||||
|
|
||||||
|
|
||||||
ostring += '\n'
|
ostring += '\n'
|
||||||
|
|
||||||
|
|
@ -198,6 +223,7 @@ packedFlags = [
|
||||||
('SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_READ', 1 << 4),
|
('SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_READ', 1 << 4),
|
||||||
('SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_WRITE', 1 << 5),
|
('SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_WRITE', 1 << 5),
|
||||||
('SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_SIMULTANEOUS_READ_WRITE', 1 << 6),
|
('SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_SIMULTANEOUS_READ_WRITE', 1 << 6),
|
||||||
|
('rsvd', 1 << 31)
|
||||||
]),
|
]),
|
||||||
('SDL_GPUBufferUsageFlags', 'Uint32', [
|
('SDL_GPUBufferUsageFlags', 'Uint32', [
|
||||||
('SDL_GPU_BUFFERUSAGE_VERTEX', (1 << 0)),
|
('SDL_GPU_BUFFERUSAGE_VERTEX', (1 << 0)),
|
||||||
|
|
@ -206,12 +232,14 @@ packedFlags = [
|
||||||
('SDL_GPU_BUFFERUSAGE_GRAPHICS_STORAGE_READ', (1 << 3)),
|
('SDL_GPU_BUFFERUSAGE_GRAPHICS_STORAGE_READ', (1 << 3)),
|
||||||
('SDL_GPU_BUFFERUSAGE_COMPUTE_STORAGE_READ', (1 << 4)),
|
('SDL_GPU_BUFFERUSAGE_COMPUTE_STORAGE_READ', (1 << 4)),
|
||||||
('SDL_GPU_BUFFERUSAGE_COMPUTE_STORAGE_WRITE', (1 << 5)),
|
('SDL_GPU_BUFFERUSAGE_COMPUTE_STORAGE_WRITE', (1 << 5)),
|
||||||
|
('rsvd', 1 << 31)
|
||||||
]),
|
]),
|
||||||
('SDL_GPUColorComponentFlags', 'Uint8', [
|
('SDL_GPUColorComponentFlags', 'Uint8', [
|
||||||
('SDL_GPU_COLORCOMPONENT_R', (1 << 0)),
|
('SDL_GPU_COLORCOMPONENT_R', (1 << 0)),
|
||||||
('SDL_GPU_COLORCOMPONENT_G', (1 << 1)),
|
('SDL_GPU_COLORCOMPONENT_G', (1 << 1)),
|
||||||
('SDL_GPU_COLORCOMPONENT_B', (1 << 2)),
|
('SDL_GPU_COLORCOMPONENT_B', (1 << 2)),
|
||||||
('SDL_GPU_COLORCOMPONENT_A', (1 << 3)),
|
('SDL_GPU_COLORCOMPONENT_A', (1 << 3)),
|
||||||
|
('rsvd', 1 << 7)
|
||||||
]),
|
]),
|
||||||
('SDL_GPUShaderFormat', 'Uint32', [
|
('SDL_GPUShaderFormat', 'Uint32', [
|
||||||
('SDL_GPU_SHADERFORMAT_PRIVATE', (1 << 0)),
|
('SDL_GPU_SHADERFORMAT_PRIVATE', (1 << 0)),
|
||||||
|
|
@ -220,6 +248,7 @@ packedFlags = [
|
||||||
('SDL_GPU_SHADERFORMAT_DXIL', (1 << 3)),
|
('SDL_GPU_SHADERFORMAT_DXIL', (1 << 3)),
|
||||||
('SDL_GPU_SHADERFORMAT_MSL', (1 << 4)),
|
('SDL_GPU_SHADERFORMAT_MSL', (1 << 4)),
|
||||||
('SDL_GPU_SHADERFORMAT_METALLIB', (1 << 5)),
|
('SDL_GPU_SHADERFORMAT_METALLIB', (1 << 5)),
|
||||||
|
('rsvd', 1 << 31)
|
||||||
], [('Invalid', '.{}')]),
|
], [('Invalid', '.{}')]),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -277,6 +306,7 @@ for t in typedefs_enum:
|
||||||
|
|
||||||
typeMap[c_typename] = typename
|
typeMap[c_typename] = typename
|
||||||
typeMap_r[typename] = c_typename
|
typeMap_r[typename] = c_typename
|
||||||
|
enums[typename] = ""
|
||||||
|
|
||||||
# print(t)
|
# print(t)
|
||||||
|
|
||||||
|
|
@ -311,7 +341,7 @@ for t in typedefs_enum:
|
||||||
#print(common)
|
#print(common)
|
||||||
#plos(e)
|
#plos(e)
|
||||||
|
|
||||||
ostring += 'pub const ' + typename + ' = ' + 'enum {\n'
|
ostring += 'pub const ' + typename + ' = ' + 'enum(c_int) {\n'
|
||||||
for i in e:
|
for i in e:
|
||||||
ostring += ' ' + i + '\n'
|
ostring += ' ' + i + '\n'
|
||||||
ostring += '};\n\n'
|
ostring += '};\n\n'
|
||||||
|
|
@ -366,6 +396,7 @@ for t in typedefs_struct:
|
||||||
pointer = True;
|
pointer = True;
|
||||||
name = name.strip('*')
|
name = name.strip('*')
|
||||||
|
|
||||||
|
|
||||||
if fieldType != '' and name != '':
|
if fieldType != '' and name != '':
|
||||||
fields.append((fieldType, name, const, comment, pointer))
|
fields.append((fieldType, name, const, comment, pointer))
|
||||||
|
|
||||||
|
|
@ -379,17 +410,190 @@ for t in typedefs_struct:
|
||||||
tstr = "pub const " + typename + " = extern struct {\n"
|
tstr = "pub const " + typename + " = extern struct {\n"
|
||||||
|
|
||||||
for field in fields:
|
for field in fields:
|
||||||
tstr += ' ' + field[1] + ': ' + ('*' if field[4] else '') + ('const ' if field[2] else '') + typeMap[field[0]] + ', ' + field[3] + ' \n'
|
typestring = typeMap[field[0]]
|
||||||
|
ptr = '[*c]'
|
||||||
|
if typestring in opaques:
|
||||||
|
ptr = '*'
|
||||||
|
tstr += ' ' + field[1] + ': ' + (ptr if field[4] else '') + ('const ' if field[2] else '') + typestring + ', ' + field[3] + ' \n'
|
||||||
|
|
||||||
tstr += '};\n'
|
tstr += '};\n'
|
||||||
|
|
||||||
ostring += tstr + "\n"
|
ostring += tstr + "\n"
|
||||||
|
|
||||||
for t in functions:
|
for t in functions:
|
||||||
print(t)
|
funcname = None
|
||||||
|
|
||||||
# print (ostring)
|
s = t[len("extern SDL_DECLSPEC "):].split('(')
|
||||||
|
label = s[0]
|
||||||
|
args = s[1].replace('\n', '')
|
||||||
|
|
||||||
with open(os.path.abspath(os.path.join(origDir, '../gpu.zig')), 'w') as f:
|
|
||||||
|
def findTypeFromLabel(label):
|
||||||
|
pointerCount = label.count('*')
|
||||||
|
|
||||||
|
label = label.split(' ')
|
||||||
|
|
||||||
|
typeStr = None
|
||||||
|
isConst = False
|
||||||
|
|
||||||
|
|
||||||
|
if label[0] == 'const':
|
||||||
|
isConst = True
|
||||||
|
|
||||||
|
if isConst:
|
||||||
|
typeStr = 'const ' + typeMap[label[1]]
|
||||||
|
else:
|
||||||
|
typeStr = typeMap[label[0]]
|
||||||
|
|
||||||
|
for i in range(0, pointerCount):
|
||||||
|
if typeStr.split(' ')[-1] in opaques:
|
||||||
|
typeStr = '*' + typeStr
|
||||||
|
else:
|
||||||
|
typeStr = '[*c]' + typeStr
|
||||||
|
|
||||||
|
if typeStr == '*void':
|
||||||
|
typeStr = '*anyopaque'
|
||||||
|
|
||||||
|
if typeStr == '*const u8':
|
||||||
|
return '[*c]const u8'
|
||||||
|
|
||||||
|
return typeStr
|
||||||
|
|
||||||
|
def getArgsListFromArgs(t, args):
|
||||||
|
rv = []
|
||||||
|
|
||||||
|
if args.strip(' );') == 'void':
|
||||||
|
return rv
|
||||||
|
|
||||||
|
l = args.replace(')', '')
|
||||||
|
l = l.replace(';', '')
|
||||||
|
l = l.split(',')
|
||||||
|
|
||||||
|
l2 = []
|
||||||
|
for x in l:
|
||||||
|
l2.append(x.strip())
|
||||||
|
|
||||||
|
print(l2)
|
||||||
|
for i in l2:
|
||||||
|
x = findTypeFromLabel(i)
|
||||||
|
print("type: ", i, '>', x, '<')
|
||||||
|
|
||||||
|
y = i.split(' ')[-1].replace('*', '')
|
||||||
|
|
||||||
|
if y == 'type':
|
||||||
|
y = '_type'
|
||||||
|
|
||||||
|
v = (x, y)
|
||||||
|
|
||||||
|
rv.append(v)
|
||||||
|
print(v)
|
||||||
|
|
||||||
|
return rv
|
||||||
|
|
||||||
|
def findFuncFromLabel(label):
|
||||||
|
rv = ''
|
||||||
|
|
||||||
|
rv = label.split(' ')[-1]
|
||||||
|
|
||||||
|
if rv.startswith('SDL_'):
|
||||||
|
rv = rv[4:]
|
||||||
|
|
||||||
|
if rv.startswith('GPU'):
|
||||||
|
rv = 'gpu' + rv[3:]
|
||||||
|
|
||||||
|
if rv.startswith('GDK'):
|
||||||
|
rv = 'gdk' + rv[3:]
|
||||||
|
|
||||||
|
rv = rv[0].lower() + rv[1:]
|
||||||
|
|
||||||
|
return rv
|
||||||
|
|
||||||
|
argsList = getArgsListFromArgs(t, args)
|
||||||
|
rtype = findTypeFromLabel(label)
|
||||||
|
funcLabel = findFuncFromLabel(label)
|
||||||
|
funcargs = ''
|
||||||
|
first = True
|
||||||
|
body = ''
|
||||||
|
for arg in argsList:
|
||||||
|
if first:
|
||||||
|
first = False
|
||||||
|
else:
|
||||||
|
funcargs += ', '
|
||||||
|
funcargs += arg[1] + ': ' + arg[0]
|
||||||
|
# body += ' _ = ' + arg[1] + ';\n'
|
||||||
|
|
||||||
|
cfunc = label.split(' ')[-1].strip()
|
||||||
|
funcstring = '// ' + label.split(' ')[-1] + '\n'
|
||||||
|
funcstring += 'pub inline fn ' + funcLabel + '('+ funcargs + ') ' + rtype + ' {\n'
|
||||||
|
bitCastRtype = False
|
||||||
|
ptrCastRtype = False
|
||||||
|
enumCastRtype = False
|
||||||
|
|
||||||
|
if rtype is not None and rtype != 'void':
|
||||||
|
funcstring += ' return '
|
||||||
|
if rtype == '[*c]const u8' or rtype.strip('*') in opaques:
|
||||||
|
ptrCastRtype = True
|
||||||
|
elif rtype in enums:
|
||||||
|
enumCastRtype = True
|
||||||
|
elif rtype != 'bool' and rtype != 'void':
|
||||||
|
print('rtype === ', rtype)
|
||||||
|
bitCastRtype = True
|
||||||
|
else:
|
||||||
|
funcstring += ' '
|
||||||
|
|
||||||
|
if ptrCastRtype:
|
||||||
|
funcstring += '@ptrCast('
|
||||||
|
|
||||||
|
if bitCastRtype:
|
||||||
|
funcstring += '@bitCast('
|
||||||
|
|
||||||
|
if enumCastRtype:
|
||||||
|
funcstring += '@enumFromInt('
|
||||||
|
|
||||||
|
funcstring += 'c.' + cfunc + '('
|
||||||
|
first = True
|
||||||
|
|
||||||
|
selfArg = None
|
||||||
|
for arg in argsList:
|
||||||
|
argType = arg[0]
|
||||||
|
argName = arg[1]
|
||||||
|
if first:
|
||||||
|
first = False
|
||||||
|
if argType.strip('*') in opaques:
|
||||||
|
selfArg = argType.strip('*')
|
||||||
|
else:
|
||||||
|
funcstring += ', '
|
||||||
|
|
||||||
|
if argType == 'bool' or argType == '[*c]const u8':
|
||||||
|
funcstring += argName
|
||||||
|
elif '*' in argType:
|
||||||
|
funcstring += '@ptrCast(' + argName + ')'
|
||||||
|
else:
|
||||||
|
funcstring += '@bitCast(' + argName + ')'
|
||||||
|
|
||||||
|
if bitCastRtype or ptrCastRtype or enumCastRtype:
|
||||||
|
funcstring += ')'
|
||||||
|
|
||||||
|
funcstring += ');\n'
|
||||||
|
|
||||||
|
funcstring += body
|
||||||
|
funcstring += '}\n\n'
|
||||||
|
|
||||||
|
if selfArg is not None:
|
||||||
|
opaques[selfArg] += funcstring
|
||||||
|
else:
|
||||||
|
ostring += funcstring
|
||||||
|
|
||||||
|
for opaque in opaques:
|
||||||
|
opaques[opaque] += '};\n\n'
|
||||||
|
|
||||||
|
for opaque in opaqueOrder:
|
||||||
|
ostring += opaques[opaque]
|
||||||
|
|
||||||
|
with open(ofile, 'w') as f:
|
||||||
f.write(ostring)
|
f.write(ostring)
|
||||||
|
|
||||||
|
subprocess.run(['zig', 'fmt', ofile])
|
||||||
|
|
||||||
|
|
||||||
|
generateAll(infile, ofile)
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,7 @@
|
||||||
pub const c = @import("c.zig").c;
|
pub const c = @import("c.zig").c;
|
||||||
|
|
||||||
pub const PropertiesID = u32;
|
pub const PropertiesID = u32;
|
||||||
pub const GPUDevice = opaque{};
|
pub const Window = c.SDL_Window;
|
||||||
pub const GPUBuffer = opaque{};
|
|
||||||
pub const GPUTransferBuffer = opaque{};
|
|
||||||
pub const GPUTexture = opaque{};
|
|
||||||
pub const GPUSampler = opaque{};
|
|
||||||
pub const GPUShader = opaque{};
|
|
||||||
pub const GPUComputePipeline = opaque{};
|
|
||||||
pub const GPUGraphicsPipeline = opaque{};
|
|
||||||
pub const GPUCommandBuffer = opaque{};
|
|
||||||
pub const GPURenderPass = opaque{};
|
|
||||||
pub const GPUComputePass = opaque{};
|
|
||||||
pub const GPUCopyPass = opaque{};
|
|
||||||
pub const GPUFence = opaque{};
|
|
||||||
|
|
||||||
|
|
||||||
pub const GPUTextureUsageFlags = packed struct(u32) {
|
pub const GPUTextureUsageFlags = packed struct(u32) {
|
||||||
textureusageSampler: bool = false,
|
textureusageSampler: bool = false,
|
||||||
|
|
@ -24,6 +11,8 @@ pub const GPUTextureUsageFlags = packed struct(u32) {
|
||||||
textureusageComputeStorageRead: bool = false,
|
textureusageComputeStorageRead: bool = false,
|
||||||
textureusageComputeStorageWrite: bool = false,
|
textureusageComputeStorageWrite: bool = false,
|
||||||
textureusageComputeStorageSimultaneousReadWrite: bool = false,
|
textureusageComputeStorageSimultaneousReadWrite: bool = false,
|
||||||
|
pad0: u24 = 0,
|
||||||
|
rsvd: bool = false,
|
||||||
};
|
};
|
||||||
pub const GPUBufferUsageFlags = packed struct(u32) {
|
pub const GPUBufferUsageFlags = packed struct(u32) {
|
||||||
bufferusageVertex: bool = false,
|
bufferusageVertex: bool = false,
|
||||||
|
|
@ -32,12 +21,16 @@ pub const GPUBufferUsageFlags = packed struct(u32) {
|
||||||
bufferusageGraphicsStorageRead: bool = false,
|
bufferusageGraphicsStorageRead: bool = false,
|
||||||
bufferusageComputeStorageRead: bool = false,
|
bufferusageComputeStorageRead: bool = false,
|
||||||
bufferusageComputeStorageWrite: bool = false,
|
bufferusageComputeStorageWrite: bool = false,
|
||||||
|
pad0: u25 = 0,
|
||||||
|
rsvd: bool = false,
|
||||||
};
|
};
|
||||||
pub const GPUColorComponentFlags = packed struct(u8) {
|
pub const GPUColorComponentFlags = packed struct(u8) {
|
||||||
colorcomponentR: bool = false,
|
colorcomponentR: bool = false,
|
||||||
colorcomponentG: bool = false,
|
colorcomponentG: bool = false,
|
||||||
colorcomponentB: bool = false,
|
colorcomponentB: bool = false,
|
||||||
colorcomponentA: bool = false,
|
colorcomponentA: bool = false,
|
||||||
|
pad0: u3 = 0,
|
||||||
|
rsvd: bool = false,
|
||||||
};
|
};
|
||||||
pub const GPUShaderFormat = packed struct(u32) {
|
pub const GPUShaderFormat = packed struct(u32) {
|
||||||
shaderformatPrivate: bool = false,
|
shaderformatPrivate: bool = false,
|
||||||
|
|
@ -46,9 +39,11 @@ pub const GPUShaderFormat = packed struct(u32) {
|
||||||
shaderformatDxil: bool = false,
|
shaderformatDxil: bool = false,
|
||||||
shaderformatMsl: bool = false,
|
shaderformatMsl: bool = false,
|
||||||
shaderformatMetallib: bool = false,
|
shaderformatMetallib: bool = false,
|
||||||
|
pad0: u25 = 0,
|
||||||
|
rsvd: bool = false,
|
||||||
pub const Invalid: @This() = .{};
|
pub const Invalid: @This() = .{};
|
||||||
};
|
};
|
||||||
pub const GPUPrimitiveType = enum {
|
pub const GPUPrimitiveType = enum(c_int) {
|
||||||
primitivetypeTrianglelist, //*< A series of separate triangles. */
|
primitivetypeTrianglelist, //*< A series of separate triangles. */
|
||||||
primitivetypeTrianglestrip, //*< A series of connected triangles. */
|
primitivetypeTrianglestrip, //*< A series of connected triangles. */
|
||||||
primitivetypeLinelist, //*< A series of separate lines. */
|
primitivetypeLinelist, //*< A series of separate lines. */
|
||||||
|
|
@ -56,25 +51,25 @@ pub const GPUPrimitiveType = enum {
|
||||||
primitivetypePointlist, //*< A series of separate points. */
|
primitivetypePointlist, //*< A series of separate points. */
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPULoadOp = enum {
|
pub const GPULoadOp = enum(c_int) {
|
||||||
loadopLoad, //*< The previous contents of the texture will be preserved. */
|
loadopLoad, //*< The previous contents of the texture will be preserved. */
|
||||||
loadopClear, //*< The contents of the texture will be cleared to a color. */
|
loadopClear, //*< The contents of the texture will be cleared to a color. */
|
||||||
loadopDontCare, //*< The previous contents of the texture need not be preserved. The contents will be undefined. */
|
loadopDontCare, //*< The previous contents of the texture need not be preserved. The contents will be undefined. */
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUStoreOp = enum {
|
pub const GPUStoreOp = enum(c_int) {
|
||||||
storeopStore, //*< The contents generated during the render pass will be written to memory. */
|
storeopStore, //*< The contents generated during the render pass will be written to memory. */
|
||||||
storeopDontCare, //*< The contents generated during the render pass are not needed and may be discarded. The contents will be undefined. */
|
storeopDontCare, //*< The contents generated during the render pass are not needed and may be discarded. The contents will be undefined. */
|
||||||
storeopResolve, //*< The multisample contents generated during the render pass will be resolved to a non-multisample texture. The contents in the multisample texture may then be discarded and will be undefined. */
|
storeopResolve, //*< The multisample contents generated during the render pass will be resolved to a non-multisample texture. The contents in the multisample texture may then be discarded and will be undefined. */
|
||||||
storeopResolveAndStore, //*< The multisample contents generated during the render pass will be resolved to a non-multisample texture. The contents in the multisample texture will be written to memory. */
|
storeopResolveAndStore, //*< The multisample contents generated during the render pass will be resolved to a non-multisample texture. The contents in the multisample texture will be written to memory. */
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUIndexElementSize = enum {
|
pub const GPUIndexElementSize = enum(c_int) {
|
||||||
indexelementsize16bit, //*< The index elements are 16-bit. */
|
indexelementsize16bit, //*< The index elements are 16-bit. */
|
||||||
indexelementsize32bit, //*< The index elements are 32-bit. */
|
indexelementsize32bit, //*< The index elements are 32-bit. */
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUTextureFormat = enum {
|
pub const GPUTextureFormat = enum(c_int) {
|
||||||
textureformatInvalid,
|
textureformatInvalid,
|
||||||
textureformatA8Unorm,
|
textureformatA8Unorm,
|
||||||
textureformatR8Unorm,
|
textureformatR8Unorm,
|
||||||
|
|
@ -182,7 +177,7 @@ pub const GPUTextureFormat = enum {
|
||||||
textureformatAstc12x12Float,
|
textureformatAstc12x12Float,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUTextureType = enum {
|
pub const GPUTextureType = enum(c_int) {
|
||||||
texturetype2d, //*< The texture is a 2-dimensional image. */
|
texturetype2d, //*< The texture is a 2-dimensional image. */
|
||||||
texturetype2dArray, //*< The texture is a 2-dimensional array image. */
|
texturetype2dArray, //*< The texture is a 2-dimensional array image. */
|
||||||
texturetype3d, //*< The texture is a 3-dimensional image. */
|
texturetype3d, //*< The texture is a 3-dimensional image. */
|
||||||
|
|
@ -190,14 +185,14 @@ pub const GPUTextureType = enum {
|
||||||
texturetypeCubeArray, //*< The texture is a cube array image. */
|
texturetypeCubeArray, //*< The texture is a cube array image. */
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUSampleCount = enum {
|
pub const GPUSampleCount = enum(c_int) {
|
||||||
samplecount1, //*< No multisampling. */
|
samplecount1, //*< No multisampling. */
|
||||||
samplecount2, //*< MSAA 2x */
|
samplecount2, //*< MSAA 2x */
|
||||||
samplecount4, //*< MSAA 4x */
|
samplecount4, //*< MSAA 4x */
|
||||||
samplecount8, //*< MSAA 8x */
|
samplecount8, //*< MSAA 8x */
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUCubeMapFace = enum {
|
pub const GPUCubeMapFace = enum(c_int) {
|
||||||
cubemapfacePositivex,
|
cubemapfacePositivex,
|
||||||
cubemapfaceNegativex,
|
cubemapfaceNegativex,
|
||||||
cubemapfacePositivey,
|
cubemapfacePositivey,
|
||||||
|
|
@ -206,17 +201,17 @@ pub const GPUCubeMapFace = enum {
|
||||||
cubemapfaceNegativez,
|
cubemapfaceNegativez,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUTransferBufferUsage = enum {
|
pub const GPUTransferBufferUsage = enum(c_int) {
|
||||||
transferbufferusageUpload,
|
transferbufferusageUpload,
|
||||||
transferbufferusageDownload,
|
transferbufferusageDownload,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUShaderStage = enum {
|
pub const GPUShaderStage = enum(c_int) {
|
||||||
shaderstageVertex,
|
shaderstageVertex,
|
||||||
shaderstageFragment,
|
shaderstageFragment,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUVertexElementFormat = enum {
|
pub const GPUVertexElementFormat = enum(c_int) {
|
||||||
vertexelementformatInvalid,
|
vertexelementformatInvalid,
|
||||||
vertexelementformatInt,
|
vertexelementformatInt,
|
||||||
vertexelementformatInt2,
|
vertexelementformatInt2,
|
||||||
|
|
@ -250,28 +245,28 @@ pub const GPUVertexElementFormat = enum {
|
||||||
vertexelementformatHalf4,
|
vertexelementformatHalf4,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUVertexInputRate = enum {
|
pub const GPUVertexInputRate = enum(c_int) {
|
||||||
vertexinputrateVertex, //*< Attribute addressing is a function of the vertex index. */
|
vertexinputrateVertex, //*< Attribute addressing is a function of the vertex index. */
|
||||||
vertexinputrateInstance, //*< Attribute addressing is a function of the instance index. */
|
vertexinputrateInstance, //*< Attribute addressing is a function of the instance index. */
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUFillMode = enum {
|
pub const GPUFillMode = enum(c_int) {
|
||||||
fillmodeFill, //*< Polygons will be rendered via rasterization. */
|
fillmodeFill, //*< Polygons will be rendered via rasterization. */
|
||||||
fillmodeLine, //*< Polygon edges will be drawn as line segments. */
|
fillmodeLine, //*< Polygon edges will be drawn as line segments. */
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUCullMode = enum {
|
pub const GPUCullMode = enum(c_int) {
|
||||||
cullmodeNone, //*< No triangles are culled. */
|
cullmodeNone, //*< No triangles are culled. */
|
||||||
cullmodeFront, //*< Front-facing triangles are culled. */
|
cullmodeFront, //*< Front-facing triangles are culled. */
|
||||||
cullmodeBack, //*< Back-facing triangles are culled. */
|
cullmodeBack, //*< Back-facing triangles are culled. */
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUFrontFace = enum {
|
pub const GPUFrontFace = enum(c_int) {
|
||||||
frontfaceCounterClockwise, //*< A triangle with counter-clockwise vertex winding will be considered front-facing. */
|
frontfaceCounterClockwise, //*< A triangle with counter-clockwise vertex winding will be considered front-facing. */
|
||||||
frontfaceClockwise, //*< A triangle with clockwise vertex winding will be considered front-facing. */
|
frontfaceClockwise, //*< A triangle with clockwise vertex winding will be considered front-facing. */
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUCompareOp = enum {
|
pub const GPUCompareOp = enum(c_int) {
|
||||||
compareopInvalid,
|
compareopInvalid,
|
||||||
compareopNever, //*< The comparison always evaluates false. */
|
compareopNever, //*< The comparison always evaluates false. */
|
||||||
compareopLess, //*< The comparison evaluates reference < test. */
|
compareopLess, //*< The comparison evaluates reference < test. */
|
||||||
|
|
@ -283,7 +278,7 @@ pub const GPUCompareOp = enum {
|
||||||
compareopAlways, //*< The comparison always evaluates true. */
|
compareopAlways, //*< The comparison always evaluates true. */
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUStencilOp = enum {
|
pub const GPUStencilOp = enum(c_int) {
|
||||||
stencilopInvalid,
|
stencilopInvalid,
|
||||||
stencilopKeep, //*< Keeps the current value. */
|
stencilopKeep, //*< Keeps the current value. */
|
||||||
stencilopZero, //*< Sets the value to 0. */
|
stencilopZero, //*< Sets the value to 0. */
|
||||||
|
|
@ -295,16 +290,16 @@ pub const GPUStencilOp = enum {
|
||||||
stencilopDecrementAndWrap, //*< Decrements the current value and wraps to the maximum value. */
|
stencilopDecrementAndWrap, //*< Decrements the current value and wraps to the maximum value. */
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUBlendOp = enum {
|
pub const GPUBlendOp = enum(c_int) {
|
||||||
blendopInvalid,
|
blendopInvalid,
|
||||||
blendopAdd, //*< (source * source_factor) + (destination * destination_factor) */
|
blendopAdd, //*< (source * source_factor) + (destination * destination_factor) */
|
||||||
blendopSubtract, //*< (source * source_factor) - (destination * destination_factor) */
|
blendopSubtract, //*< (source * source_factor) - (destination * destination_factor) */
|
||||||
blendopReverseSubtract, //*< (destination * destination_factor) - (source * source_factor) */
|
blendopReverseSubtract, //*< (destination * destination_factor) - (source * source_factor) */
|
||||||
blendopMin, //*< min(source
|
blendopMin, //*< min(source
|
||||||
blendopMax //*< max(source, destination) */
|
blendopMax, //*< max(source, destination) */
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUBlendFactor = enum {
|
pub const GPUBlendFactor = enum(c_int) {
|
||||||
blendfactorInvalid,
|
blendfactorInvalid,
|
||||||
blendfactorZero, //*< 0 */
|
blendfactorZero, //*< 0 */
|
||||||
blendfactorOne, //*< 1 */
|
blendfactorOne, //*< 1 */
|
||||||
|
|
@ -318,39 +313,39 @@ pub const GPUBlendFactor = enum {
|
||||||
blendfactorOneMinusDstAlpha, //*< 1 - destination alpha */
|
blendfactorOneMinusDstAlpha, //*< 1 - destination alpha */
|
||||||
blendfactorConstantColor, //*< blend constant */
|
blendfactorConstantColor, //*< blend constant */
|
||||||
blendfactorOneMinusConstantColor, //*< 1 - blend constant */
|
blendfactorOneMinusConstantColor, //*< 1 - blend constant */
|
||||||
blendfactorSrcAlphaSaturate //*< min(source alpha, 1 - destination alpha) */
|
blendfactorSrcAlphaSaturate, //*< min(source alpha, 1 - destination alpha) */
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUFilter = enum {
|
pub const GPUFilter = enum(c_int) {
|
||||||
filterNearest, //*< Point filtering. */
|
filterNearest, //*< Point filtering. */
|
||||||
filterLinear, //*< Linear filtering. */
|
filterLinear, //*< Linear filtering. */
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUSamplerMipmapMode = enum {
|
pub const GPUSamplerMipmapMode = enum(c_int) {
|
||||||
samplermipmapmodeNearest, //*< Point filtering. */
|
samplermipmapmodeNearest, //*< Point filtering. */
|
||||||
samplermipmapmodeLinear, //*< Linear filtering. */
|
samplermipmapmodeLinear, //*< Linear filtering. */
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUSamplerAddressMode = enum {
|
pub const GPUSamplerAddressMode = enum(c_int) {
|
||||||
sampleraddressmodeRepeat, //*< Specifies that the coordinates will wrap around. */
|
sampleraddressmodeRepeat, //*< Specifies that the coordinates will wrap around. */
|
||||||
sampleraddressmodeMirroredRepeat, //*< Specifies that the coordinates will wrap around mirrored. */
|
sampleraddressmodeMirroredRepeat, //*< Specifies that the coordinates will wrap around mirrored. */
|
||||||
sampleraddressmodeClampToEdge, //*< Specifies that the coordinates will clamp to the 0-1 range. */
|
sampleraddressmodeClampToEdge, //*< Specifies that the coordinates will clamp to the 0-1 range. */
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUPresentMode = enum {
|
pub const GPUPresentMode = enum(c_int) {
|
||||||
presentmodeVsync,
|
presentmodeVsync,
|
||||||
presentmodeImmediate,
|
presentmodeImmediate,
|
||||||
presentmodeMailbox,
|
presentmodeMailbox,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUSwapchainComposition = enum {
|
pub const GPUSwapchainComposition = enum(c_int) {
|
||||||
swapchaincompositionSdr,
|
swapchaincompositionSdr,
|
||||||
swapchaincompositionSdrLinear,
|
swapchaincompositionSdrLinear,
|
||||||
swapchaincompositionHdrExtendedLinear,
|
swapchaincompositionHdrExtendedLinear,
|
||||||
swapchaincompositionHdr10St2084,
|
swapchaincompositionHdr10St2084,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const FlipMode = enum {
|
pub const FlipMode = enum(c_int) {
|
||||||
sdlFlipNone, //*< Do not flip */
|
sdlFlipNone, //*< Do not flip */
|
||||||
sdlFlipHorizontal, //*< flip horizontally */
|
sdlFlipHorizontal, //*< flip horizontally */
|
||||||
sdlFlipVertical, //*< flip vertically */
|
sdlFlipVertical, //*< flip vertically */
|
||||||
|
|
@ -474,9 +469,9 @@ pub const GPUVertexAttribute = extern struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUVertexInputState = extern struct {
|
pub const GPUVertexInputState = extern struct {
|
||||||
vertex_buffer_descriptions: *const GPUVertexBufferDescription, // A pointer to an array of vertex buffer descriptions.
|
vertex_buffer_descriptions: [*c]const GPUVertexBufferDescription, // A pointer to an array of vertex buffer descriptions.
|
||||||
num_vertex_buffers: u32, // The number of vertex buffer descriptions in the above array.
|
num_vertex_buffers: u32, // The number of vertex buffer descriptions in the above array.
|
||||||
vertex_attributes: *const GPUVertexAttribute, // A pointer to an array of vertex attribute descriptions.
|
vertex_attributes: [*c]const GPUVertexAttribute, // A pointer to an array of vertex attribute descriptions.
|
||||||
num_vertex_attributes: u32, // The number of vertex attribute descriptions in the above array.
|
num_vertex_attributes: u32, // The number of vertex attribute descriptions in the above array.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -503,8 +498,8 @@ pub const GPUColorTargetBlendState = extern struct {
|
||||||
|
|
||||||
pub const GPUShaderCreateInfo = extern struct {
|
pub const GPUShaderCreateInfo = extern struct {
|
||||||
code_size: usize, // The size in bytes of the code pointed to.
|
code_size: usize, // The size in bytes of the code pointed to.
|
||||||
code: *const u8, // A pointer to shader code.
|
code: [*c]const u8, // A pointer to shader code.
|
||||||
entrypoint: *const i8, // A pointer to a null-terminated UTF-8 string specifying the entry point function name for the shader.
|
entrypoint: [*c]const u8, // A pointer to a null-terminated UTF-8 string specifying the entry point function name for the shader.
|
||||||
format: GPUShaderFormat, // The format of the shader code.
|
format: GPUShaderFormat, // The format of the shader code.
|
||||||
stage: GPUShaderStage, // The stage the shader program corresponds to.
|
stage: GPUShaderStage, // The stage the shader program corresponds to.
|
||||||
num_samplers: u32, // The number of samplers defined in the shader.
|
num_samplers: u32, // The number of samplers defined in the shader.
|
||||||
|
|
@ -580,7 +575,7 @@ pub const GPUColorTargetDescription = extern struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GPUGraphicsPipelineTargetInfo = extern struct {
|
pub const GPUGraphicsPipelineTargetInfo = extern struct {
|
||||||
color_target_descriptions: *const GPUColorTargetDescription, // A pointer to an array of color target descriptions.
|
color_target_descriptions: [*c]const GPUColorTargetDescription, // A pointer to an array of color target descriptions.
|
||||||
num_color_targets: u32, // The number of color target descriptions in the above array.
|
num_color_targets: u32, // The number of color target descriptions in the above array.
|
||||||
depth_stencil_format: GPUTextureFormat, // The pixel format of the depth-stencil target. Ignored if has_depth_stencil_target is false.
|
depth_stencil_format: GPUTextureFormat, // The pixel format of the depth-stencil target. Ignored if has_depth_stencil_target is false.
|
||||||
has_depth_stencil_target: bool, // true specifies that the pipeline uses a depth-stencil target.
|
has_depth_stencil_target: bool, // true specifies that the pipeline uses a depth-stencil target.
|
||||||
|
|
@ -603,8 +598,8 @@ pub const GPUGraphicsPipelineCreateInfo = extern struct {
|
||||||
|
|
||||||
pub const GPUComputePipelineCreateInfo = extern struct {
|
pub const GPUComputePipelineCreateInfo = extern struct {
|
||||||
code_size: usize, // The size in bytes of the compute shader code pointed to.
|
code_size: usize, // The size in bytes of the compute shader code pointed to.
|
||||||
code: *const u8, // A pointer to compute shader code.
|
code: [*c]const u8, // A pointer to compute shader code.
|
||||||
entrypoint: *const i8, // A pointer to a null-terminated UTF-8 string specifying the entry point function name for the shader.
|
entrypoint: [*c]const u8, // A pointer to a null-terminated UTF-8 string specifying the entry point function name for the shader.
|
||||||
format: GPUShaderFormat, // The format of the compute shader code.
|
format: GPUShaderFormat, // The format of the compute shader code.
|
||||||
num_samplers: u32, // The number of samplers defined in the shader.
|
num_samplers: u32, // The number of samplers defined in the shader.
|
||||||
num_readonly_storage_textures: u32, // The number of readonly storage textures defined in the shader.
|
num_readonly_storage_textures: u32, // The number of readonly storage textures defined in the shader.
|
||||||
|
|
@ -694,3 +689,505 @@ pub const FColor = extern struct {
|
||||||
a: f32,
|
a: f32,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const Rect = extern struct {
|
||||||
|
x: c_int,
|
||||||
|
y: c_int,
|
||||||
|
w: c_int,
|
||||||
|
h: c_int,
|
||||||
|
};
|
||||||
|
|
||||||
|
// SDL_GPUSupportsShaderFormats
|
||||||
|
pub inline fn gpuSupportsShaderFormats(format_flags: GPUShaderFormat, name: [*c]const u8) bool {
|
||||||
|
return c.SDL_GPUSupportsShaderFormats(@bitCast(format_flags), name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_GPUSupportsProperties
|
||||||
|
pub inline fn gpuSupportsProperties(props: PropertiesID) bool {
|
||||||
|
return c.SDL_GPUSupportsProperties(@bitCast(props));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_CreateGPUDevice
|
||||||
|
pub inline fn createGPUDevice(format_flags: GPUShaderFormat, debug_mode: bool, name: [*c]const u8) *GPUDevice {
|
||||||
|
return @ptrCast(c.SDL_CreateGPUDevice(@bitCast(format_flags), debug_mode, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_CreateGPUDeviceWithProperties
|
||||||
|
pub inline fn createGPUDeviceWithProperties(props: PropertiesID) *GPUDevice {
|
||||||
|
return @ptrCast(c.SDL_CreateGPUDeviceWithProperties(@bitCast(props)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_GetNumGPUDrivers
|
||||||
|
pub inline fn getNumGPUDrivers() c_int {
|
||||||
|
return @bitCast(c.SDL_GetNumGPUDrivers());
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_GetGPUDriver
|
||||||
|
pub inline fn getGPUDriver(index: c_int) [*c]const u8 {
|
||||||
|
return @ptrCast(c.SDL_GetGPUDriver(@bitCast(index)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_GPUTextureFormatTexelBlockSize
|
||||||
|
pub inline fn gpuTextureFormatTexelBlockSize(format: GPUTextureFormat) u32 {
|
||||||
|
return @bitCast(c.SDL_GPUTextureFormatTexelBlockSize(@bitCast(format)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_CalculateGPUTextureFormatSize
|
||||||
|
pub inline fn calculateGPUTextureFormatSize(format: GPUTextureFormat, width: u32, height: u32, depth_or_layer_count: u32) u32 {
|
||||||
|
return @bitCast(c.SDL_CalculateGPUTextureFormatSize(@bitCast(format), @bitCast(width), @bitCast(height), @bitCast(depth_or_layer_count)));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const GPUDevice = opaque {
|
||||||
|
// SDL_DestroyGPUDevice
|
||||||
|
pub inline fn destroyGPUDevice(device: *GPUDevice) void {
|
||||||
|
c.SDL_DestroyGPUDevice(@ptrCast(device));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_GetGPUDeviceDriver
|
||||||
|
pub inline fn getGPUDeviceDriver(device: *GPUDevice) [*c]const u8 {
|
||||||
|
return @ptrCast(c.SDL_GetGPUDeviceDriver(@ptrCast(device)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_GetGPUShaderFormats
|
||||||
|
pub inline fn getGPUShaderFormats(device: *GPUDevice) GPUShaderFormat {
|
||||||
|
return @bitCast(c.SDL_GetGPUShaderFormats(@ptrCast(device)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_CreateGPUComputePipeline
|
||||||
|
pub inline fn createGPUComputePipeline(device: *GPUDevice, createinfo: [*c]const GPUComputePipelineCreateInfo) *GPUComputePipeline {
|
||||||
|
return @ptrCast(c.SDL_CreateGPUComputePipeline(@ptrCast(device), @ptrCast(createinfo)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_CreateGPUGraphicsPipeline
|
||||||
|
pub inline fn createGPUGraphicsPipeline(device: *GPUDevice, createinfo: [*c]const GPUGraphicsPipelineCreateInfo) *GPUGraphicsPipeline {
|
||||||
|
return @ptrCast(c.SDL_CreateGPUGraphicsPipeline(@ptrCast(device), @ptrCast(createinfo)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_CreateGPUSampler
|
||||||
|
pub inline fn createGPUSampler(device: *GPUDevice, createinfo: [*c]const GPUSamplerCreateInfo) *GPUSampler {
|
||||||
|
return @ptrCast(c.SDL_CreateGPUSampler(@ptrCast(device), @ptrCast(createinfo)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_CreateGPUShader
|
||||||
|
pub inline fn createGPUShader(device: *GPUDevice, createinfo: [*c]const GPUShaderCreateInfo) *GPUShader {
|
||||||
|
return @ptrCast(c.SDL_CreateGPUShader(@ptrCast(device), @ptrCast(createinfo)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_CreateGPUTexture
|
||||||
|
pub inline fn createGPUTexture(device: *GPUDevice, createinfo: [*c]const GPUTextureCreateInfo) *GPUTexture {
|
||||||
|
return @ptrCast(c.SDL_CreateGPUTexture(@ptrCast(device), @ptrCast(createinfo)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_CreateGPUBuffer
|
||||||
|
pub inline fn createGPUBuffer(device: *GPUDevice, createinfo: [*c]const GPUBufferCreateInfo) *GPUBuffer {
|
||||||
|
return @ptrCast(c.SDL_CreateGPUBuffer(@ptrCast(device), @ptrCast(createinfo)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_CreateGPUTransferBuffer
|
||||||
|
pub inline fn createGPUTransferBuffer(device: *GPUDevice, createinfo: [*c]const GPUTransferBufferCreateInfo) *GPUTransferBuffer {
|
||||||
|
return @ptrCast(c.SDL_CreateGPUTransferBuffer(@ptrCast(device), @ptrCast(createinfo)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_SetGPUBufferName
|
||||||
|
pub inline fn setGPUBufferName(device: *GPUDevice, buffer: *GPUBuffer, text: [*c]const u8) void {
|
||||||
|
c.SDL_SetGPUBufferName(@ptrCast(device), @ptrCast(buffer), text);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_SetGPUTextureName
|
||||||
|
pub inline fn setGPUTextureName(device: *GPUDevice, texture: *GPUTexture, text: [*c]const u8) void {
|
||||||
|
c.SDL_SetGPUTextureName(@ptrCast(device), @ptrCast(texture), text);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_ReleaseGPUTexture
|
||||||
|
pub inline fn releaseGPUTexture(device: *GPUDevice, texture: *GPUTexture) void {
|
||||||
|
c.SDL_ReleaseGPUTexture(@ptrCast(device), @ptrCast(texture));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_ReleaseGPUSampler
|
||||||
|
pub inline fn releaseGPUSampler(device: *GPUDevice, sampler: *GPUSampler) void {
|
||||||
|
c.SDL_ReleaseGPUSampler(@ptrCast(device), @ptrCast(sampler));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_ReleaseGPUBuffer
|
||||||
|
pub inline fn releaseGPUBuffer(device: *GPUDevice, buffer: *GPUBuffer) void {
|
||||||
|
c.SDL_ReleaseGPUBuffer(@ptrCast(device), @ptrCast(buffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_ReleaseGPUTransferBuffer
|
||||||
|
pub inline fn releaseGPUTransferBuffer(device: *GPUDevice, transfer_buffer: *GPUTransferBuffer) void {
|
||||||
|
c.SDL_ReleaseGPUTransferBuffer(@ptrCast(device), @ptrCast(transfer_buffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_ReleaseGPUComputePipeline
|
||||||
|
pub inline fn releaseGPUComputePipeline(device: *GPUDevice, compute_pipeline: *GPUComputePipeline) void {
|
||||||
|
c.SDL_ReleaseGPUComputePipeline(@ptrCast(device), @ptrCast(compute_pipeline));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_ReleaseGPUShader
|
||||||
|
pub inline fn releaseGPUShader(device: *GPUDevice, shader: *GPUShader) void {
|
||||||
|
c.SDL_ReleaseGPUShader(@ptrCast(device), @ptrCast(shader));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_ReleaseGPUGraphicsPipeline
|
||||||
|
pub inline fn releaseGPUGraphicsPipeline(device: *GPUDevice, graphics_pipeline: *GPUGraphicsPipeline) void {
|
||||||
|
c.SDL_ReleaseGPUGraphicsPipeline(@ptrCast(device), @ptrCast(graphics_pipeline));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_AcquireGPUCommandBuffer
|
||||||
|
pub inline fn acquireGPUCommandBuffer(device: *GPUDevice) *GPUCommandBuffer {
|
||||||
|
return @ptrCast(c.SDL_AcquireGPUCommandBuffer(@ptrCast(device)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_MapGPUTransferBuffer
|
||||||
|
pub inline fn mapGPUTransferBuffer(device: *GPUDevice, transfer_buffer: *GPUTransferBuffer, cycle: bool) [*c]void {
|
||||||
|
return @bitCast(c.SDL_MapGPUTransferBuffer(@ptrCast(device), @ptrCast(transfer_buffer), cycle));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_UnmapGPUTransferBuffer
|
||||||
|
pub inline fn unmapGPUTransferBuffer(device: *GPUDevice, transfer_buffer: *GPUTransferBuffer) void {
|
||||||
|
c.SDL_UnmapGPUTransferBuffer(@ptrCast(device), @ptrCast(transfer_buffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_WindowSupportsGPUSwapchainComposition
|
||||||
|
pub inline fn windowSupportsGPUSwapchainComposition(device: *GPUDevice, window: *Window, swapchain_composition: GPUSwapchainComposition) bool {
|
||||||
|
return c.SDL_WindowSupportsGPUSwapchainComposition(@ptrCast(device), @ptrCast(window), @bitCast(swapchain_composition));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_WindowSupportsGPUPresentMode
|
||||||
|
pub inline fn windowSupportsGPUPresentMode(device: *GPUDevice, window: *Window, present_mode: GPUPresentMode) bool {
|
||||||
|
return c.SDL_WindowSupportsGPUPresentMode(@ptrCast(device), @ptrCast(window), @bitCast(present_mode));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_ClaimWindowForGPUDevice
|
||||||
|
pub inline fn claimWindowForGPUDevice(device: *GPUDevice, window: *Window) bool {
|
||||||
|
return c.SDL_ClaimWindowForGPUDevice(@ptrCast(device), @ptrCast(window));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_ReleaseWindowFromGPUDevice
|
||||||
|
pub inline fn releaseWindowFromGPUDevice(device: *GPUDevice, window: *Window) void {
|
||||||
|
c.SDL_ReleaseWindowFromGPUDevice(@ptrCast(device), @ptrCast(window));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_SetGPUSwapchainParameters
|
||||||
|
pub inline fn setGPUSwapchainParameters(device: *GPUDevice, window: *Window, swapchain_composition: GPUSwapchainComposition, present_mode: GPUPresentMode) bool {
|
||||||
|
return c.SDL_SetGPUSwapchainParameters(@ptrCast(device), @ptrCast(window), @bitCast(swapchain_composition), @bitCast(present_mode));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_SetGPUAllowedFramesInFlight
|
||||||
|
pub inline fn setGPUAllowedFramesInFlight(device: *GPUDevice, allowed_frames_in_flight: u32) bool {
|
||||||
|
return c.SDL_SetGPUAllowedFramesInFlight(@ptrCast(device), @bitCast(allowed_frames_in_flight));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_GetGPUSwapchainTextureFormat
|
||||||
|
pub inline fn getGPUSwapchainTextureFormat(device: *GPUDevice, window: *Window) GPUTextureFormat {
|
||||||
|
return @enumFromInt(c.SDL_GetGPUSwapchainTextureFormat(@ptrCast(device), @ptrCast(window)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_WaitForGPUSwapchain
|
||||||
|
pub inline fn waitForGPUSwapchain(device: *GPUDevice, window: *Window) bool {
|
||||||
|
return c.SDL_WaitForGPUSwapchain(@ptrCast(device), @ptrCast(window));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_WaitForGPUIdle
|
||||||
|
pub inline fn waitForGPUIdle(device: *GPUDevice) bool {
|
||||||
|
return c.SDL_WaitForGPUIdle(@ptrCast(device));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_WaitForGPUFences
|
||||||
|
pub inline fn waitForGPUFences(device: *GPUDevice, wait_all: bool, fences: [*c]*GPUFence, num_fences: u32) bool {
|
||||||
|
return c.SDL_WaitForGPUFences(@ptrCast(device), wait_all, @ptrCast(fences), @bitCast(num_fences));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_QueryGPUFence
|
||||||
|
pub inline fn queryGPUFence(device: *GPUDevice, fence: *GPUFence) bool {
|
||||||
|
return c.SDL_QueryGPUFence(@ptrCast(device), @ptrCast(fence));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_ReleaseGPUFence
|
||||||
|
pub inline fn releaseGPUFence(device: *GPUDevice, fence: *GPUFence) void {
|
||||||
|
c.SDL_ReleaseGPUFence(@ptrCast(device), @ptrCast(fence));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_GPUTextureSupportsFormat
|
||||||
|
pub inline fn gpuTextureSupportsFormat(device: *GPUDevice, format: GPUTextureFormat, _type: GPUTextureType, usage: GPUTextureUsageFlags) bool {
|
||||||
|
return c.SDL_GPUTextureSupportsFormat(@ptrCast(device), @bitCast(format), @bitCast(_type), @bitCast(usage));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_GPUTextureSupportsSampleCount
|
||||||
|
pub inline fn gpuTextureSupportsSampleCount(device: *GPUDevice, format: GPUTextureFormat, sample_count: GPUSampleCount) bool {
|
||||||
|
return c.SDL_GPUTextureSupportsSampleCount(@ptrCast(device), @bitCast(format), @bitCast(sample_count));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_GDKSuspendGPU
|
||||||
|
pub inline fn gdkSuspendGPU(device: *GPUDevice) void {
|
||||||
|
c.SDL_GDKSuspendGPU(@ptrCast(device));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_GDKResumeGPU
|
||||||
|
pub inline fn gdkResumeGPU(device: *GPUDevice) void {
|
||||||
|
c.SDL_GDKResumeGPU(@ptrCast(device));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const GPUBuffer = opaque {};
|
||||||
|
|
||||||
|
pub const GPUTransferBuffer = opaque {};
|
||||||
|
|
||||||
|
pub const GPUTexture = opaque {};
|
||||||
|
|
||||||
|
pub const GPUSampler = opaque {};
|
||||||
|
|
||||||
|
pub const GPUShader = opaque {};
|
||||||
|
|
||||||
|
pub const GPUComputePipeline = opaque {};
|
||||||
|
|
||||||
|
pub const GPUGraphicsPipeline = opaque {};
|
||||||
|
|
||||||
|
pub const GPUCommandBuffer = opaque {
|
||||||
|
// SDL_InsertGPUDebugLabel
|
||||||
|
pub inline fn insertGPUDebugLabel(command_buffer: *GPUCommandBuffer, text: [*c]const u8) void {
|
||||||
|
c.SDL_InsertGPUDebugLabel(@ptrCast(command_buffer), text);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_PushGPUDebugGroup
|
||||||
|
pub inline fn pushGPUDebugGroup(command_buffer: *GPUCommandBuffer, name: [*c]const u8) void {
|
||||||
|
c.SDL_PushGPUDebugGroup(@ptrCast(command_buffer), name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_PopGPUDebugGroup
|
||||||
|
pub inline fn popGPUDebugGroup(command_buffer: *GPUCommandBuffer) void {
|
||||||
|
c.SDL_PopGPUDebugGroup(@ptrCast(command_buffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_PushGPUVertexUniformData
|
||||||
|
pub inline fn pushGPUVertexUniformData(command_buffer: *GPUCommandBuffer, slot_index: u32, data: [*c]const void, length: u32) void {
|
||||||
|
c.SDL_PushGPUVertexUniformData(@ptrCast(command_buffer), @bitCast(slot_index), @ptrCast(data), @bitCast(length));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_PushGPUFragmentUniformData
|
||||||
|
pub inline fn pushGPUFragmentUniformData(command_buffer: *GPUCommandBuffer, slot_index: u32, data: [*c]const void, length: u32) void {
|
||||||
|
c.SDL_PushGPUFragmentUniformData(@ptrCast(command_buffer), @bitCast(slot_index), @ptrCast(data), @bitCast(length));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_PushGPUComputeUniformData
|
||||||
|
pub inline fn pushGPUComputeUniformData(command_buffer: *GPUCommandBuffer, slot_index: u32, data: [*c]const void, length: u32) void {
|
||||||
|
c.SDL_PushGPUComputeUniformData(@ptrCast(command_buffer), @bitCast(slot_index), @ptrCast(data), @bitCast(length));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_BeginGPURenderPass
|
||||||
|
pub inline fn beginGPURenderPass(command_buffer: *GPUCommandBuffer, color_target_infos: [*c]const GPUColorTargetInfo, num_color_targets: u32, depth_stencil_target_info: [*c]const GPUDepthStencilTargetInfo) *GPURenderPass {
|
||||||
|
return @ptrCast(c.SDL_BeginGPURenderPass(@ptrCast(command_buffer), @ptrCast(color_target_infos), @bitCast(num_color_targets), @ptrCast(depth_stencil_target_info)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_BeginGPUComputePass
|
||||||
|
pub inline fn beginGPUComputePass(command_buffer: *GPUCommandBuffer, storage_texture_bindings: [*c]const GPUStorageTextureReadWriteBinding, num_storage_texture_bindings: u32, storage_buffer_bindings: [*c]const GPUStorageBufferReadWriteBinding, num_storage_buffer_bindings: u32) *GPUComputePass {
|
||||||
|
return @ptrCast(c.SDL_BeginGPUComputePass(@ptrCast(command_buffer), @ptrCast(storage_texture_bindings), @bitCast(num_storage_texture_bindings), @ptrCast(storage_buffer_bindings), @bitCast(num_storage_buffer_bindings)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_BeginGPUCopyPass
|
||||||
|
pub inline fn beginGPUCopyPass(command_buffer: *GPUCommandBuffer) *GPUCopyPass {
|
||||||
|
return @ptrCast(c.SDL_BeginGPUCopyPass(@ptrCast(command_buffer)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_GenerateMipmapsForGPUTexture
|
||||||
|
pub inline fn generateMipmapsForGPUTexture(command_buffer: *GPUCommandBuffer, texture: *GPUTexture) void {
|
||||||
|
c.SDL_GenerateMipmapsForGPUTexture(@ptrCast(command_buffer), @ptrCast(texture));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_BlitGPUTexture
|
||||||
|
pub inline fn blitGPUTexture(command_buffer: *GPUCommandBuffer, info: [*c]const GPUBlitInfo) void {
|
||||||
|
c.SDL_BlitGPUTexture(@ptrCast(command_buffer), @ptrCast(info));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_AcquireGPUSwapchainTexture
|
||||||
|
pub inline fn acquireGPUSwapchainTexture(command_buffer: *GPUCommandBuffer, window: *Window, swapchain_texture: [*c]*GPUTexture, swapchain_texture_width: [*c]u32, swapchain_texture_height: [*c]u32) bool {
|
||||||
|
return c.SDL_AcquireGPUSwapchainTexture(@ptrCast(command_buffer), @ptrCast(window), @ptrCast(swapchain_texture), @ptrCast(swapchain_texture_width), @ptrCast(swapchain_texture_height));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_WaitAndAcquireGPUSwapchainTexture
|
||||||
|
pub inline fn waitAndAcquireGPUSwapchainTexture(command_buffer: *GPUCommandBuffer, window: *Window, swapchain_texture: [*c]*GPUTexture, swapchain_texture_width: [*c]u32, swapchain_texture_height: [*c]u32) bool {
|
||||||
|
return c.SDL_WaitAndAcquireGPUSwapchainTexture(@ptrCast(command_buffer), @ptrCast(window), @ptrCast(swapchain_texture), @ptrCast(swapchain_texture_width), @ptrCast(swapchain_texture_height));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_SubmitGPUCommandBuffer
|
||||||
|
pub inline fn submitGPUCommandBuffer(command_buffer: *GPUCommandBuffer) bool {
|
||||||
|
return c.SDL_SubmitGPUCommandBuffer(@ptrCast(command_buffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_SubmitGPUCommandBufferAndAcquireFence
|
||||||
|
pub inline fn submitGPUCommandBufferAndAcquireFence(command_buffer: *GPUCommandBuffer) *GPUFence {
|
||||||
|
return @ptrCast(c.SDL_SubmitGPUCommandBufferAndAcquireFence(@ptrCast(command_buffer)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_CancelGPUCommandBuffer
|
||||||
|
pub inline fn cancelGPUCommandBuffer(command_buffer: *GPUCommandBuffer) bool {
|
||||||
|
return c.SDL_CancelGPUCommandBuffer(@ptrCast(command_buffer));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const GPURenderPass = opaque {
|
||||||
|
// SDL_BindGPUGraphicsPipeline
|
||||||
|
pub inline fn bindGPUGraphicsPipeline(render_pass: *GPURenderPass, graphics_pipeline: *GPUGraphicsPipeline) void {
|
||||||
|
c.SDL_BindGPUGraphicsPipeline(@ptrCast(render_pass), @ptrCast(graphics_pipeline));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_SetGPUViewport
|
||||||
|
pub inline fn setGPUViewport(render_pass: *GPURenderPass, viewport: [*c]const GPUViewport) void {
|
||||||
|
c.SDL_SetGPUViewport(@ptrCast(render_pass), @ptrCast(viewport));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_SetGPUScissor
|
||||||
|
pub inline fn setGPUScissor(render_pass: *GPURenderPass, scissor: [*c]const Rect) void {
|
||||||
|
c.SDL_SetGPUScissor(@ptrCast(render_pass), @ptrCast(scissor));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_SetGPUBlendConstants
|
||||||
|
pub inline fn setGPUBlendConstants(render_pass: *GPURenderPass, blend_constants: FColor) void {
|
||||||
|
c.SDL_SetGPUBlendConstants(@ptrCast(render_pass), @bitCast(blend_constants));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_SetGPUStencilReference
|
||||||
|
pub inline fn setGPUStencilReference(render_pass: *GPURenderPass, reference: u8) void {
|
||||||
|
c.SDL_SetGPUStencilReference(@ptrCast(render_pass), @bitCast(reference));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_BindGPUVertexBuffers
|
||||||
|
pub inline fn bindGPUVertexBuffers(render_pass: *GPURenderPass, first_slot: u32, bindings: [*c]const GPUBufferBinding, num_bindings: u32) void {
|
||||||
|
c.SDL_BindGPUVertexBuffers(@ptrCast(render_pass), @bitCast(first_slot), @ptrCast(bindings), @bitCast(num_bindings));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_BindGPUIndexBuffer
|
||||||
|
pub inline fn bindGPUIndexBuffer(render_pass: *GPURenderPass, binding: [*c]const GPUBufferBinding, index_element_size: GPUIndexElementSize) void {
|
||||||
|
c.SDL_BindGPUIndexBuffer(@ptrCast(render_pass), @ptrCast(binding), @bitCast(index_element_size));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_BindGPUVertexSamplers
|
||||||
|
pub inline fn bindGPUVertexSamplers(render_pass: *GPURenderPass, first_slot: u32, texture_sampler_bindings: [*c]const GPUTextureSamplerBinding, num_bindings: u32) void {
|
||||||
|
c.SDL_BindGPUVertexSamplers(@ptrCast(render_pass), @bitCast(first_slot), @ptrCast(texture_sampler_bindings), @bitCast(num_bindings));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_BindGPUVertexStorageTextures
|
||||||
|
pub inline fn bindGPUVertexStorageTextures(render_pass: *GPURenderPass, first_slot: u32, storage_textures: [*c]*GPUTexture, num_bindings: u32) void {
|
||||||
|
c.SDL_BindGPUVertexStorageTextures(@ptrCast(render_pass), @bitCast(first_slot), @ptrCast(storage_textures), @bitCast(num_bindings));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_BindGPUVertexStorageBuffers
|
||||||
|
pub inline fn bindGPUVertexStorageBuffers(render_pass: *GPURenderPass, first_slot: u32, storage_buffers: [*c]*GPUBuffer, num_bindings: u32) void {
|
||||||
|
c.SDL_BindGPUVertexStorageBuffers(@ptrCast(render_pass), @bitCast(first_slot), @ptrCast(storage_buffers), @bitCast(num_bindings));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_BindGPUFragmentSamplers
|
||||||
|
pub inline fn bindGPUFragmentSamplers(render_pass: *GPURenderPass, first_slot: u32, texture_sampler_bindings: [*c]const GPUTextureSamplerBinding, num_bindings: u32) void {
|
||||||
|
c.SDL_BindGPUFragmentSamplers(@ptrCast(render_pass), @bitCast(first_slot), @ptrCast(texture_sampler_bindings), @bitCast(num_bindings));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_BindGPUFragmentStorageTextures
|
||||||
|
pub inline fn bindGPUFragmentStorageTextures(render_pass: *GPURenderPass, first_slot: u32, storage_textures: [*c]*GPUTexture, num_bindings: u32) void {
|
||||||
|
c.SDL_BindGPUFragmentStorageTextures(@ptrCast(render_pass), @bitCast(first_slot), @ptrCast(storage_textures), @bitCast(num_bindings));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_BindGPUFragmentStorageBuffers
|
||||||
|
pub inline fn bindGPUFragmentStorageBuffers(render_pass: *GPURenderPass, first_slot: u32, storage_buffers: [*c]*GPUBuffer, num_bindings: u32) void {
|
||||||
|
c.SDL_BindGPUFragmentStorageBuffers(@ptrCast(render_pass), @bitCast(first_slot), @ptrCast(storage_buffers), @bitCast(num_bindings));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_DrawGPUIndexedPrimitives
|
||||||
|
pub inline fn drawGPUIndexedPrimitives(render_pass: *GPURenderPass, num_indices: u32, num_instances: u32, first_index: u32, vertex_offset: i32, first_instance: u32) void {
|
||||||
|
c.SDL_DrawGPUIndexedPrimitives(@ptrCast(render_pass), @bitCast(num_indices), @bitCast(num_instances), @bitCast(first_index), @bitCast(vertex_offset), @bitCast(first_instance));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_DrawGPUPrimitives
|
||||||
|
pub inline fn drawGPUPrimitives(render_pass: *GPURenderPass, num_vertices: u32, num_instances: u32, first_vertex: u32, first_instance: u32) void {
|
||||||
|
c.SDL_DrawGPUPrimitives(@ptrCast(render_pass), @bitCast(num_vertices), @bitCast(num_instances), @bitCast(first_vertex), @bitCast(first_instance));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_DrawGPUPrimitivesIndirect
|
||||||
|
pub inline fn drawGPUPrimitivesIndirect(render_pass: *GPURenderPass, buffer: *GPUBuffer, offset: u32, draw_count: u32) void {
|
||||||
|
c.SDL_DrawGPUPrimitivesIndirect(@ptrCast(render_pass), @ptrCast(buffer), @bitCast(offset), @bitCast(draw_count));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_DrawGPUIndexedPrimitivesIndirect
|
||||||
|
pub inline fn drawGPUIndexedPrimitivesIndirect(render_pass: *GPURenderPass, buffer: *GPUBuffer, offset: u32, draw_count: u32) void {
|
||||||
|
c.SDL_DrawGPUIndexedPrimitivesIndirect(@ptrCast(render_pass), @ptrCast(buffer), @bitCast(offset), @bitCast(draw_count));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_EndGPURenderPass
|
||||||
|
pub inline fn endGPURenderPass(render_pass: *GPURenderPass) void {
|
||||||
|
c.SDL_EndGPURenderPass(@ptrCast(render_pass));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const GPUComputePass = opaque {
|
||||||
|
// SDL_BindGPUComputePipeline
|
||||||
|
pub inline fn bindGPUComputePipeline(compute_pass: *GPUComputePass, compute_pipeline: *GPUComputePipeline) void {
|
||||||
|
c.SDL_BindGPUComputePipeline(@ptrCast(compute_pass), @ptrCast(compute_pipeline));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_BindGPUComputeSamplers
|
||||||
|
pub inline fn bindGPUComputeSamplers(compute_pass: *GPUComputePass, first_slot: u32, texture_sampler_bindings: [*c]const GPUTextureSamplerBinding, num_bindings: u32) void {
|
||||||
|
c.SDL_BindGPUComputeSamplers(@ptrCast(compute_pass), @bitCast(first_slot), @ptrCast(texture_sampler_bindings), @bitCast(num_bindings));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_BindGPUComputeStorageTextures
|
||||||
|
pub inline fn bindGPUComputeStorageTextures(compute_pass: *GPUComputePass, first_slot: u32, storage_textures: [*c]*GPUTexture, num_bindings: u32) void {
|
||||||
|
c.SDL_BindGPUComputeStorageTextures(@ptrCast(compute_pass), @bitCast(first_slot), @ptrCast(storage_textures), @bitCast(num_bindings));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_BindGPUComputeStorageBuffers
|
||||||
|
pub inline fn bindGPUComputeStorageBuffers(compute_pass: *GPUComputePass, first_slot: u32, storage_buffers: [*c]*GPUBuffer, num_bindings: u32) void {
|
||||||
|
c.SDL_BindGPUComputeStorageBuffers(@ptrCast(compute_pass), @bitCast(first_slot), @ptrCast(storage_buffers), @bitCast(num_bindings));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_DispatchGPUCompute
|
||||||
|
pub inline fn dispatchGPUCompute(compute_pass: *GPUComputePass, groupcount_x: u32, groupcount_y: u32, groupcount_z: u32) void {
|
||||||
|
c.SDL_DispatchGPUCompute(@ptrCast(compute_pass), @bitCast(groupcount_x), @bitCast(groupcount_y), @bitCast(groupcount_z));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_DispatchGPUComputeIndirect
|
||||||
|
pub inline fn dispatchGPUComputeIndirect(compute_pass: *GPUComputePass, buffer: *GPUBuffer, offset: u32) void {
|
||||||
|
c.SDL_DispatchGPUComputeIndirect(@ptrCast(compute_pass), @ptrCast(buffer), @bitCast(offset));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_EndGPUComputePass
|
||||||
|
pub inline fn endGPUComputePass(compute_pass: *GPUComputePass) void {
|
||||||
|
c.SDL_EndGPUComputePass(@ptrCast(compute_pass));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const GPUCopyPass = opaque {
|
||||||
|
// SDL_UploadToGPUTexture
|
||||||
|
pub inline fn uploadToGPUTexture(copy_pass: *GPUCopyPass, source: [*c]const GPUTextureTransferInfo, destination: [*c]const GPUTextureRegion, cycle: bool) void {
|
||||||
|
c.SDL_UploadToGPUTexture(@ptrCast(copy_pass), @ptrCast(source), @ptrCast(destination), cycle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_UploadToGPUBuffer
|
||||||
|
pub inline fn uploadToGPUBuffer(copy_pass: *GPUCopyPass, source: [*c]const GPUTransferBufferLocation, destination: [*c]const GPUBufferRegion, cycle: bool) void {
|
||||||
|
c.SDL_UploadToGPUBuffer(@ptrCast(copy_pass), @ptrCast(source), @ptrCast(destination), cycle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_CopyGPUTextureToTexture
|
||||||
|
pub inline fn copyGPUTextureToTexture(copy_pass: *GPUCopyPass, source: [*c]const GPUTextureLocation, destination: [*c]const GPUTextureLocation, w: u32, h: u32, d: u32, cycle: bool) void {
|
||||||
|
c.SDL_CopyGPUTextureToTexture(@ptrCast(copy_pass), @ptrCast(source), @ptrCast(destination), @bitCast(w), @bitCast(h), @bitCast(d), cycle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_CopyGPUBufferToBuffer
|
||||||
|
pub inline fn copyGPUBufferToBuffer(copy_pass: *GPUCopyPass, source: [*c]const GPUBufferLocation, destination: [*c]const GPUBufferLocation, size: u32, cycle: bool) void {
|
||||||
|
c.SDL_CopyGPUBufferToBuffer(@ptrCast(copy_pass), @ptrCast(source), @ptrCast(destination), @bitCast(size), cycle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_DownloadFromGPUTexture
|
||||||
|
pub inline fn downloadFromGPUTexture(copy_pass: *GPUCopyPass, source: [*c]const GPUTextureRegion, destination: [*c]const GPUTextureTransferInfo) void {
|
||||||
|
c.SDL_DownloadFromGPUTexture(@ptrCast(copy_pass), @ptrCast(source), @ptrCast(destination));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_DownloadFromGPUBuffer
|
||||||
|
pub inline fn downloadFromGPUBuffer(copy_pass: *GPUCopyPass, source: [*c]const GPUBufferRegion, destination: [*c]const GPUTransferBufferLocation) void {
|
||||||
|
c.SDL_DownloadFromGPUBuffer(@ptrCast(copy_pass), @ptrCast(source), @ptrCast(destination));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_EndGPUCopyPass
|
||||||
|
pub inline fn endGPUCopyPass(copy_pass: *GPUCopyPass) void {
|
||||||
|
c.SDL_EndGPUCopyPass(@ptrCast(copy_pass));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const GPUFence = opaque {};
|
||||||
|
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
pub const c = @cImport({ // todo, should not be constant
|
|
||||||
@cInclude("SDL3/SDL.h");
|
|
||||||
});
|
|
||||||
|
|
||||||
pub const InitOptions = packed struct(c_int) {
|
|
||||||
pad0: u4 = 0, // 0 - 3
|
|
||||||
audio: bool = false, // 4
|
|
||||||
video: bool = false, // 5
|
|
||||||
pad1: u2 = 0, // 6-7
|
|
||||||
pad2: u1 = 0, // 8
|
|
||||||
joystick: bool = false, // 9
|
|
||||||
pad3: u2 = 0, // 10-11
|
|
||||||
haptic: bool = false, // 12
|
|
||||||
gamepad: bool = false,
|
|
||||||
events: bool = false,
|
|
||||||
sensor: bool = false,
|
|
||||||
camera: bool = false,
|
|
||||||
pad4: u3 = 0,
|
|
||||||
pad5: u12 = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const AppResult = enum{
|
|
||||||
app_continue,
|
|
||||||
app_success,
|
|
||||||
app_failure,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const Window = opaque {};
|
|
||||||
|
|
||||||
pub fn createWindow() !*Window {
|
|
||||||
|
|
||||||
return @ptrCast();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn init(options: InitOptions) !void {
|
|
||||||
if (!c.SDL_Init(@bitCast(options))) {
|
|
||||||
return error.InitFailed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -4,9 +4,17 @@ timer: std.time.Timer,
|
||||||
// fillPipeline: *sdl3.GpuGraphicsPipeline = undefined,
|
// fillPipeline: *sdl3.GpuGraphicsPipeline = undefined,
|
||||||
// linePipeline: *sdl3.GpuGraphicsPipeline = undefined,
|
// linePipeline: *sdl3.GpuGraphicsPipeline = undefined,
|
||||||
// viewport: sdl3.GpuViewport = undefined,
|
// viewport: sdl3.GpuViewport = undefined,
|
||||||
// scissor: sdl3.Rect = undefined,
|
scissor: gpu.Rect = .{ .x = 0, .y = 0, .w = 640, .h = 480 },
|
||||||
|
|
||||||
running: bool = true,
|
running: bool = true,
|
||||||
|
window: *sdl3.Window = undefined,
|
||||||
|
device: *gpu.GPUDevice = undefined,
|
||||||
|
shaderpath: []const u8 = undefined,
|
||||||
|
shadersuffix: []const u8 = undefined,
|
||||||
|
fragment: *gpu.GPUShader = undefined,
|
||||||
|
vertex: *gpu.GPUShader = undefined,
|
||||||
|
pipeline: *gpu.GPUGraphicsPipeline = undefined,
|
||||||
|
shaderformat: gpu.GPUShaderFormat = undefined,
|
||||||
|
|
||||||
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||||
const self = try allocator.create(@This());
|
const self = try allocator.create(@This());
|
||||||
|
|
@ -24,10 +32,92 @@ pub fn startContext(self: *@This()) !void {
|
||||||
.gamepad = true,
|
.gamepad = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const window = sdl3.c.SDL_CreateWindow("lmao your mom", 640, 480, 0);
|
self.window = sdl3.c.SDL_CreateWindow("hello-world", 640, 480, 0).?;
|
||||||
_ = window;
|
self.device = gpu.createGPUDevice(.{
|
||||||
|
.shaderformatSpirv = true,
|
||||||
|
.shaderformatDxil = true,
|
||||||
|
.shaderformatMsl = true,
|
||||||
|
}, false, null);
|
||||||
|
|
||||||
_ = self;
|
if (!self.device.claimWindowForGPUDevice(self.window))
|
||||||
|
return error.UnableToClaimGpu;
|
||||||
|
|
||||||
|
const formats = self.device.getGPUShaderFormats();
|
||||||
|
std.debug.print("SDL Context Loaded: {}\n", .{formats});
|
||||||
|
if (formats.shaderformatSpirv) {
|
||||||
|
self.shaderpath = "./content/_cooked/spv"; // shaderformatSpirv
|
||||||
|
self.shadersuffix = ".spv";
|
||||||
|
self.shaderformat = .{ .shaderformatSpirv = true };
|
||||||
|
} else if (formats.shaderformatMsl) {
|
||||||
|
self.shaderpath = "./content/_cooked/msl"; // shaderformatSpirv
|
||||||
|
self.shadersuffix = ".msl";
|
||||||
|
self.shaderformat = .{ .shaderformatMsl = true };
|
||||||
|
} else if (formats.shaderformatDxil) {
|
||||||
|
self.shaderpath = "./content/_cooked/dxil"; // shaderformatSpirv
|
||||||
|
self.shadersuffix = ".dxil";
|
||||||
|
self.shaderformat = .{ .shaderformatDxil = true };
|
||||||
|
}
|
||||||
|
|
||||||
|
self.fragment = try self.loadShader("hello-triangle.frag", .shaderstageFragment, 0, 0, 0, 0);
|
||||||
|
self.vertex = try self.loadShader("hello-triangle.vert", .shaderstageVertex, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
var pci = std.mem.zeroes(gpu.GPUGraphicsPipelineCreateInfo);
|
||||||
|
pci.fragment_shader = self.fragment;
|
||||||
|
pci.vertex_shader = self.vertex;
|
||||||
|
|
||||||
|
pci.target_info.num_color_targets = 1;
|
||||||
|
pci.target_info.color_target_descriptions = &[_]gpu.GPUColorTargetDescription{
|
||||||
|
.{
|
||||||
|
.format = self.device.getGPUSwapchainTextureFormat(self.window),
|
||||||
|
.blend_state = std.mem.zeroes(gpu.GPUColorTargetBlendState),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
pci.rasterizer_state.fill_mode = .fillmodeFill;
|
||||||
|
self.pipeline = self.device.createGPUGraphicsPipeline(&pci);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn loadFileAlloc(filename: []const u8, comptime alignment: usize, allocator: std.mem.Allocator) ![]u8 {
|
||||||
|
var file = try std.fs.cwd().openFile(filename, .{});
|
||||||
|
defer file.close();
|
||||||
|
const filesize = (try file.stat()).size + 1; // add null byte
|
||||||
|
const buffer: []align(alignment) u8 = try allocator.alignedAlloc(u8, alignment, filesize);
|
||||||
|
errdefer allocator.free(buffer);
|
||||||
|
try file.reader().readNoEof(buffer[0 .. buffer.len - 1]);
|
||||||
|
buffer[buffer.len - 1] = 0;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn loadShader(
|
||||||
|
self: *@This(),
|
||||||
|
shaderName: []const u8,
|
||||||
|
stage: gpu.GPUShaderStage,
|
||||||
|
num_samplers: u32, // The number of samplers defined in the shader.
|
||||||
|
num_storage_textures: u32, // The number of storage textures defined in the shader.
|
||||||
|
num_storage_buffers: u32, // The number of storage buffers defined in the shader.
|
||||||
|
num_uniform_buffers: u32, // The number of uniform buffers defined in the shader.
|
||||||
|
) !*gpu.GPUShader {
|
||||||
|
const spath = try std.fmt.allocPrintZ(self.allocator, "{s}/{s}{s}", .{ self.shaderpath, shaderName, self.shadersuffix });
|
||||||
|
defer self.allocator.free(spath);
|
||||||
|
|
||||||
|
std.debug.print("loading shader {s}\n", .{spath});
|
||||||
|
|
||||||
|
const fileContents = try loadFileAlloc(spath, 8, self.allocator);
|
||||||
|
defer self.allocator.free(fileContents);
|
||||||
|
const sci = gpu.GPUShaderCreateInfo{
|
||||||
|
.code = @ptrCast(fileContents.ptr),
|
||||||
|
.entrypoint = "main",
|
||||||
|
.format = self.shaderformat,
|
||||||
|
.code_size = fileContents.len - 1,
|
||||||
|
.stage = stage,
|
||||||
|
.num_samplers = num_samplers,
|
||||||
|
.num_storage_textures = num_storage_textures, // The number of storage textures defined in the shader.
|
||||||
|
.num_storage_buffers = num_storage_buffers, // The number of storage buffers defined in the shader.
|
||||||
|
.num_uniform_buffers = num_uniform_buffers, // The number of uniform buffers defined in the shader.
|
||||||
|
.props = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
return self.device.createGPUShader(&sci);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn loop(self: *@This()) !void {
|
pub fn loop(self: *@This()) !void {
|
||||||
|
|
@ -40,25 +130,53 @@ pub fn loop(self: *@This()) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(self: *@This(), dt: f64) void {
|
fn update(self: *@This(), dt: f64) void {
|
||||||
_ = dt;
|
|
||||||
|
|
||||||
while (sdl3.pollEvent()) |event| {
|
while (sdl3.pollEvent()) |event| {
|
||||||
_ = event;
|
switch (event.type) {
|
||||||
// std.debug.print("{any} \n", .{event});
|
sdl_event.quit => {
|
||||||
|
self.running = false;
|
||||||
|
},
|
||||||
|
else => {},
|
||||||
}
|
}
|
||||||
self.running = true;
|
|
||||||
|
self.draw(dt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn draw(self: *@This(), dt: f64) void {
|
||||||
|
_ = dt;
|
||||||
|
const cmd = self.device.acquireGPUCommandBuffer();
|
||||||
|
var swapchain_texture: *gpu.GPUTexture = undefined;
|
||||||
|
if (cmd.waitAndAcquireGPUSwapchainTexture(self.window, &swapchain_texture, null, null)) {
|
||||||
|
var targetInfo: gpu.GPUColorTargetInfo = std.mem.zeroes(gpu.GPUColorTargetInfo);
|
||||||
|
targetInfo.texture = swapchain_texture;
|
||||||
|
targetInfo.clear_color = .{ .r = 0.1, .g = 0.1, .b = 0.1, .a = 1.0 };
|
||||||
|
targetInfo.load_op = .loadopClear;
|
||||||
|
targetInfo.store_op = .storeopStore;
|
||||||
|
|
||||||
|
const renderpass = cmd.beginGPURenderPass(&targetInfo, 1, null);
|
||||||
|
renderpass.bindGPUGraphicsPipeline(self.pipeline);
|
||||||
|
renderpass.setGPUScissor(&self.scissor);
|
||||||
|
renderpass.drawGPUPrimitives(3, 1, 0, 0);
|
||||||
|
renderpass.endGPURenderPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = cmd.submitGPUCommandBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy(self: *@This()) void {
|
pub fn destroy(self: *@This()) void {
|
||||||
|
sdl3.c.SDL_DestroyWindow(self.window);
|
||||||
|
self.device.releaseWindowFromGPUDevice(self.window);
|
||||||
|
|
||||||
self.allocator.destroy(self);
|
self.allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
std.debug.print("creating context", .{});
|
std.debug.print("hello world... n", .{});
|
||||||
const app = try create(std.heap.c_allocator);
|
const app = try create(std.heap.c_allocator);
|
||||||
try app.loop();
|
try app.loop();
|
||||||
defer app.destroy();
|
defer app.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
const sdl3 = @import("sdl3");
|
const sdl3 = @import("sdl3");
|
||||||
|
const gpu = sdl3.gpu;
|
||||||
|
const sdl_event = sdl3.events;
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,47 @@
|
||||||
const c = @import("c.zig").c;
|
pub const c = @import("c.zig").c;
|
||||||
|
pub const events = @import("events.zig");
|
||||||
|
|
||||||
|
pub const InitOptions = packed struct(c_int) {
|
||||||
|
pad0: u4 = 0, // 0 - 3
|
||||||
|
audio: bool = false, // 4
|
||||||
|
video: bool = false, // 5
|
||||||
|
pad1: u2 = 0, // 6-7
|
||||||
|
pad2: u1 = 0, // 8
|
||||||
|
joystick: bool = false, // 9
|
||||||
|
pad3: u2 = 0, // 10-11
|
||||||
|
haptic: bool = false, // 12
|
||||||
|
gamepad: bool = false,
|
||||||
|
events: bool = false,
|
||||||
|
sensor: bool = false,
|
||||||
|
camera: bool = false,
|
||||||
|
pad4: u3 = 0,
|
||||||
|
pad5: u12 = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const AppResult = enum {
|
||||||
|
app_continue,
|
||||||
|
app_success,
|
||||||
|
app_failure,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const Window = c.SDL_Window;
|
||||||
|
pub const Event = c.SDL_Event;
|
||||||
|
pub const Rect = c.SDL_Rect;
|
||||||
|
|
||||||
|
pub fn init(options: InitOptions) !void {
|
||||||
|
if (!c.SDL_Init(@bitCast(options))) {
|
||||||
|
return error.InitFailed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const EventType = events;
|
||||||
|
|
||||||
|
var gLastEvent: Event = undefined;
|
||||||
|
pub fn pollEvent() ?*Event {
|
||||||
|
if (c.SDL_PollEvent(&gLastEvent)) {
|
||||||
|
return &gLastEvent;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
pub const gpu = @import("gpu.zig");
|
pub const gpu = @import("gpu.zig");
|
||||||
pub const init = @import("init.zig");
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue