Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
GH Action committed Dec 17, 2024
1 parent 67b1e72 commit 83b5c7e
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 0 deletions.
112 changes: 112 additions & 0 deletions src/sokol/c/sokol_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -4249,6 +4249,18 @@ SOKOL_GFX_API_DECL sg_sampler_desc sg_query_sampler_defaults(const sg_sampler_de
SOKOL_GFX_API_DECL sg_shader_desc sg_query_shader_defaults(const sg_shader_desc* desc);
SOKOL_GFX_API_DECL sg_pipeline_desc sg_query_pipeline_defaults(const sg_pipeline_desc* desc);
SOKOL_GFX_API_DECL sg_attachments_desc sg_query_attachments_defaults(const sg_attachments_desc* desc);
// assorted query functions
SOKOL_GFX_API_DECL size_t sg_query_buffer_size(sg_buffer buf);
SOKOL_GFX_API_DECL sg_buffer_type sg_query_buffer_type(sg_buffer buf);
SOKOL_GFX_API_DECL sg_usage sg_query_buffer_usage(sg_buffer buf);
SOKOL_GFX_API_DECL sg_image_type sg_query_image_type(sg_image img);
SOKOL_GFX_API_DECL int sg_query_image_width(sg_image img);
SOKOL_GFX_API_DECL int sg_query_image_height(sg_image img);
SOKOL_GFX_API_DECL int sg_query_image_num_slices(sg_image img);
SOKOL_GFX_API_DECL int sg_query_image_num_mipmaps(sg_image img);
SOKOL_GFX_API_DECL sg_pixel_format sg_query_image_pixelformat(sg_image img);
SOKOL_GFX_API_DECL sg_usage sg_query_image_usage(sg_image img);
SOKOL_GFX_API_DECL int sg_query_image_sample_count(sg_image img);

// separate resource allocation and initialization (for async setup)
SOKOL_GFX_API_DECL sg_buffer sg_alloc_buffer(void);
Expand Down Expand Up @@ -19228,6 +19240,33 @@ SOKOL_API_IMPL sg_buffer_desc sg_query_buffer_desc(sg_buffer buf_id) {
return desc;
}

SOKOL_API_IMPL size_t sg_query_buffer_size(sg_buffer buf_id) {
SOKOL_ASSERT(_sg.valid);
const _sg_buffer_t* buf = _sg_lookup_buffer(&_sg.pools, buf_id.id);
if (buf) {
return (size_t)buf->cmn.size;
}
return 0;
}

SOKOL_API_IMPL sg_buffer_type sg_query_buffer_type(sg_buffer buf_id) {
SOKOL_ASSERT(_sg.valid);
const _sg_buffer_t* buf = _sg_lookup_buffer(&_sg.pools, buf_id.id);
if (buf) {
return buf->cmn.type;
}
return _SG_BUFFERTYPE_DEFAULT;
}

SOKOL_API_IMPL sg_usage sg_query_buffer_usage(sg_buffer buf_id) {
SOKOL_ASSERT(_sg.valid);
const _sg_buffer_t* buf = _sg_lookup_buffer(&_sg.pools, buf_id.id);
if (buf) {
return buf->cmn.usage;
}
return _SG_USAGE_DEFAULT;
}

SOKOL_API_IMPL sg_image_desc sg_query_image_desc(sg_image img_id) {
SOKOL_ASSERT(_sg.valid);
sg_image_desc desc;
Expand All @@ -19247,6 +19286,79 @@ SOKOL_API_IMPL sg_image_desc sg_query_image_desc(sg_image img_id) {
return desc;
}

SOKOL_API_IMPL sg_image_type sg_query_image_type(sg_image img_id) {
SOKOL_ASSERT(_sg.valid);
const _sg_image_t* img = _sg_lookup_image(&_sg.pools, img_id.id);
if (img) {
return img->cmn.type;
}
return _SG_IMAGETYPE_DEFAULT;
}

SOKOL_API_IMPL int sg_query_image_width(sg_image img_id) {
SOKOL_ASSERT(_sg.valid);
const _sg_image_t* img = _sg_lookup_image(&_sg.pools, img_id.id);
if (img) {
return img->cmn.width;
}
return 0;
}

SOKOL_API_IMPL int sg_query_image_height(sg_image img_id) {
SOKOL_ASSERT(_sg.valid);
const _sg_image_t* img = _sg_lookup_image(&_sg.pools, img_id.id);
if (img) {
return img->cmn.height;
}
return 0;
}

SOKOL_API_IMPL int sg_query_image_num_slices(sg_image img_id) {
SOKOL_ASSERT(_sg.valid);
const _sg_image_t* img = _sg_lookup_image(&_sg.pools, img_id.id);
if (img) {
return img->cmn.num_slices;
}
return 0;
}

SOKOL_API_IMPL int sg_query_image_num_mipmaps(sg_image img_id) {
SOKOL_ASSERT(_sg.valid);
const _sg_image_t* img = _sg_lookup_image(&_sg.pools, img_id.id);
if (img) {
return img->cmn.num_mipmaps;
}
return 0;
}

SOKOL_API_IMPL sg_pixel_format sg_query_image_pixelformat(sg_image img_id) {
SOKOL_ASSERT(_sg.valid);
const _sg_image_t* img = _sg_lookup_image(&_sg.pools, img_id.id);
if (img) {
return img->cmn.pixel_format;
}
return _SG_PIXELFORMAT_DEFAULT;
}

SOKOL_API_IMPL sg_usage sg_query_image_usage(sg_image img_id) {
SOKOL_ASSERT(_sg.valid);
const _sg_image_t* img = _sg_lookup_image(&_sg.pools, img_id.id);
if (img) {
return img->cmn.usage;
}
return _SG_USAGE_DEFAULT;
}

SOKOL_API_IMPL int sg_query_image_sample_count(sg_image img_id) {
SOKOL_ASSERT(_sg.valid);
SOKOL_ASSERT(_sg.valid);
const _sg_image_t* img = _sg_lookup_image(&_sg.pools, img_id.id);
if (img) {
return img->cmn.sample_count;
}
return 0;
}

SOKOL_API_IMPL sg_sampler_desc sg_query_sampler_desc(sg_sampler smp_id) {
SOKOL_ASSERT(_sg.valid);
sg_sampler_desc desc;
Expand Down
44 changes: 44 additions & 0 deletions src/sokol/gfx.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,50 @@ proc c_queryAttachmentsDefaults(desc:ptr AttachmentsDesc):AttachmentsDesc {.cdec
proc queryAttachmentsDefaults*(desc:AttachmentsDesc):AttachmentsDesc =
c_queryAttachmentsDefaults(addr(desc))

proc c_queryBufferSize(buf:Buffer):int {.cdecl, importc:"sg_query_buffer_size".}
proc queryBufferSize*(buf:Buffer):int =
c_queryBufferSize(buf)

proc c_queryBufferType(buf:Buffer):BufferType {.cdecl, importc:"sg_query_buffer_type".}
proc queryBufferType*(buf:Buffer):BufferType =
c_queryBufferType(buf)

proc c_queryBufferUsage(buf:Buffer):Usage {.cdecl, importc:"sg_query_buffer_usage".}
proc queryBufferUsage*(buf:Buffer):Usage =
c_queryBufferUsage(buf)

proc c_queryImageType(img:Image):ImageType {.cdecl, importc:"sg_query_image_type".}
proc queryImageType*(img:Image):ImageType =
c_queryImageType(img)

proc c_queryImageWidth(img:Image):int32 {.cdecl, importc:"sg_query_image_width".}
proc queryImageWidth*(img:Image):int32 =
c_queryImageWidth(img)

proc c_queryImageHeight(img:Image):int32 {.cdecl, importc:"sg_query_image_height".}
proc queryImageHeight*(img:Image):int32 =
c_queryImageHeight(img)

proc c_queryImageNumSlices(img:Image):int32 {.cdecl, importc:"sg_query_image_num_slices".}
proc queryImageNumSlices*(img:Image):int32 =
c_queryImageNumSlices(img)

proc c_queryImageNumMipmaps(img:Image):int32 {.cdecl, importc:"sg_query_image_num_mipmaps".}
proc queryImageNumMipmaps*(img:Image):int32 =
c_queryImageNumMipmaps(img)

proc c_queryImagePixelformat(img:Image):PixelFormat {.cdecl, importc:"sg_query_image_pixelformat".}
proc queryImagePixelformat*(img:Image):PixelFormat =
c_queryImagePixelformat(img)

proc c_queryImageUsage(img:Image):Usage {.cdecl, importc:"sg_query_image_usage".}
proc queryImageUsage*(img:Image):Usage =
c_queryImageUsage(img)

proc c_queryImageSampleCount(img:Image):int32 {.cdecl, importc:"sg_query_image_sample_count".}
proc queryImageSampleCount*(img:Image):int32 =
c_queryImageSampleCount(img)

proc c_allocBuffer():Buffer {.cdecl, importc:"sg_alloc_buffer".}
proc allocBuffer*():Buffer =
c_allocBuffer()
Expand Down

0 comments on commit 83b5c7e

Please sign in to comment.