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 22b36a9 commit aecbf75
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/gfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3469,6 +3469,17 @@ pub mod ffi {
pub fn sg_query_shader_defaults(desc: *const ShaderDesc) -> ShaderDesc;
pub fn sg_query_pipeline_defaults(desc: *const PipelineDesc) -> PipelineDesc;
pub fn sg_query_attachments_defaults(desc: *const AttachmentsDesc) -> AttachmentsDesc;
pub fn sg_query_buffer_size(buf: Buffer) -> usize;
pub fn sg_query_buffer_type(buf: Buffer) -> BufferType;
pub fn sg_query_buffer_usage(buf: Buffer) -> Usage;
pub fn sg_query_image_type(img: Image) -> ImageType;
pub fn sg_query_image_width(img: Image) -> i32;
pub fn sg_query_image_height(img: Image) -> i32;
pub fn sg_query_image_num_slices(img: Image) -> i32;
pub fn sg_query_image_num_mipmaps(img: Image) -> i32;
pub fn sg_query_image_pixelformat(img: Image) -> PixelFormat;
pub fn sg_query_image_usage(img: Image) -> Usage;
pub fn sg_query_image_sample_count(img: Image) -> i32;
pub fn sg_alloc_buffer() -> Buffer;
pub fn sg_alloc_image() -> Image;
pub fn sg_alloc_sampler() -> Sampler;
Expand Down Expand Up @@ -3809,6 +3820,50 @@ pub fn query_attachments_defaults(desc: &AttachmentsDesc) -> AttachmentsDesc {
unsafe { ffi::sg_query_attachments_defaults(desc) }
}
#[inline]
pub fn query_buffer_size(buf: Buffer) -> usize {
unsafe { ffi::sg_query_buffer_size(buf) }
}
#[inline]
pub fn query_buffer_type(buf: Buffer) -> BufferType {
unsafe { ffi::sg_query_buffer_type(buf) }
}
#[inline]
pub fn query_buffer_usage(buf: Buffer) -> Usage {
unsafe { ffi::sg_query_buffer_usage(buf) }
}
#[inline]
pub fn query_image_type(img: Image) -> ImageType {
unsafe { ffi::sg_query_image_type(img) }
}
#[inline]
pub fn query_image_width(img: Image) -> i32 {
unsafe { ffi::sg_query_image_width(img) }
}
#[inline]
pub fn query_image_height(img: Image) -> i32 {
unsafe { ffi::sg_query_image_height(img) }
}
#[inline]
pub fn query_image_num_slices(img: Image) -> i32 {
unsafe { ffi::sg_query_image_num_slices(img) }
}
#[inline]
pub fn query_image_num_mipmaps(img: Image) -> i32 {
unsafe { ffi::sg_query_image_num_mipmaps(img) }
}
#[inline]
pub fn query_image_pixelformat(img: Image) -> PixelFormat {
unsafe { ffi::sg_query_image_pixelformat(img) }
}
#[inline]
pub fn query_image_usage(img: Image) -> Usage {
unsafe { ffi::sg_query_image_usage(img) }
}
#[inline]
pub fn query_image_sample_count(img: Image) -> i32 {
unsafe { ffi::sg_query_image_sample_count(img) }
}
#[inline]
pub fn alloc_buffer() -> Buffer {
unsafe { ffi::sg_alloc_buffer() }
}
Expand Down
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

0 comments on commit aecbf75

Please sign in to comment.