From 36ca5cbd182a0a76d4d4bad77e45494341153bc7 Mon Sep 17 00:00:00 2001 From: Mike Popoloski Date: Sat, 25 Apr 2015 13:20:52 -0400 Subject: [PATCH 1/2] Exposing flags param for C99 buffer creation methods. --- include/bgfx.c99.h | 8 ++++---- src/bgfx.cpp | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/bgfx.c99.h b/include/bgfx.c99.h index 59928105..5bf95a17 100644 --- a/include/bgfx.c99.h +++ b/include/bgfx.c99.h @@ -692,7 +692,7 @@ BGFX_C_API void bgfx_dbg_text_image(uint16_t _x, uint16_t _y, uint16_t _width, u * NOTE: * Only 16-bit index buffer is supported. */ -BGFX_C_API bgfx_index_buffer_handle_t bgfx_create_index_buffer(const bgfx_memory_t* _mem); +BGFX_C_API bgfx_index_buffer_handle_t bgfx_create_index_buffer(const bgfx_memory_t* _mem, uint8_t _flags); /** * Destroy static index buffer. @@ -723,7 +723,7 @@ BGFX_C_API void bgfx_destroy_vertex_buffer(bgfx_vertex_buffer_handle_t _handle); * NOTE: * Only 16-bit index buffer is supported. */ -BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(uint32_t _num); +BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(uint32_t _num, uint8_t _flags); /** * Create dynamic index buffer and initialized it. @@ -733,7 +733,7 @@ BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(u * NOTE: * Only 16-bit index buffer is supported. */ -BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_mem(const bgfx_memory_t* _mem); +BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_mem(const bgfx_memory_t* _mem, uint8_t _flags); /** * Update dynamic index buffer. @@ -764,7 +764,7 @@ BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer * @param _mem Vertex buffer data. * @param _decl Vertex declaration. */ -BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer_mem(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl); +BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer_mem(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint8_t _flags); /** * Update dynamic vertex buffer. diff --git a/src/bgfx.cpp b/src/bgfx.cpp index e602f7db..4d54d0bc 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -3163,10 +3163,10 @@ BGFX_C_API void bgfx_dbg_text_image(uint16_t _x, uint16_t _y, uint16_t _width, u bgfx::dbgTextImage(_x, _y, _width, _height, _data, _pitch); } -BGFX_C_API bgfx_index_buffer_handle_t bgfx_create_index_buffer(const bgfx_memory_t* _mem) +BGFX_C_API bgfx_index_buffer_handle_t bgfx_create_index_buffer(const bgfx_memory_t* _mem, uint8_t _flags) { union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle; - handle.cpp = bgfx::createIndexBuffer( (const bgfx::Memory*)_mem); + handle.cpp = bgfx::createIndexBuffer( (const bgfx::Memory*)_mem, _flags); return handle.c; } @@ -3190,17 +3190,17 @@ BGFX_C_API void bgfx_destroy_vertex_buffer(bgfx_vertex_buffer_handle_t _handle) bgfx::destroyVertexBuffer(handle.cpp); } -BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(uint32_t _num) +BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(uint32_t _num, uint8_t _flags) { union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle; - handle.cpp = bgfx::createDynamicIndexBuffer(_num); + handle.cpp = bgfx::createDynamicIndexBuffer(_num, _flags); return handle.c; } -BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_mem(const bgfx_memory_t* _mem) +BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_mem(const bgfx_memory_t* _mem, uint8_t _flags) { union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle; - handle.cpp = bgfx::createDynamicIndexBuffer( (const bgfx::Memory*)_mem); + handle.cpp = bgfx::createDynamicIndexBuffer( (const bgfx::Memory*)_mem, _flags); return handle.c; } @@ -3224,11 +3224,11 @@ BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer return handle.c; } -BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer_mem(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl) +BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer_mem(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint8_t _flags) { const bgfx::VertexDecl& decl = *(const bgfx::VertexDecl*)_decl; union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle; - handle.cpp = bgfx::createDynamicVertexBuffer( (const bgfx::Memory*)_mem, decl); + handle.cpp = bgfx::createDynamicVertexBuffer( (const bgfx::Memory*)_mem, decl, _flags); return handle.c; } From 9677f4a37c4800873952fb0d0c1e05fa0d85f551 Mon Sep 17 00:00:00 2001 From: Mike Popoloski Date: Sat, 25 Apr 2015 13:30:47 -0400 Subject: [PATCH 2/2] Updating C99 API to support scaled textures. --- include/bgfx.c99.h | 30 ++++++++++++++++++++++++++++++ src/bgfx.cpp | 14 ++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/bgfx.c99.h b/include/bgfx.c99.h index 5bf95a17..fa01f3ed 100644 --- a/include/bgfx.c99.h +++ b/include/bgfx.c99.h @@ -150,6 +150,17 @@ typedef enum bgfx_uniform_type } bgfx_uniform_type_t; +typedef enum bgfx_backbuffer_ratio +{ + BGFX_BACKBUFFER_RATIO_NONE, + BGFX_BACKBUFFER_RATIO_EQUAL, + BGFX_BACKBUFFER_RATIO_HALF, + BGFX_BACKBUFFER_RATIO_QUARTER, + BGFX_BACKBUFFER_RATIO_EIGHTH, + BGFX_BACKBUFFER_RATIO_SIXTEENTH, + BGFX_BACKBUFFER_RATIO_DOUBLE +} bgfx_backbuffer_ratio_t; + #define BGFX_HANDLE_T(_name) \ typedef struct _name { uint16_t idx; } _name##_t; @@ -935,6 +946,16 @@ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem, */ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem); +/** +* Create 2D texture that scales with backbuffer size. +* +* @param _ratio +* @param _numMips +* @param _format +* @param _flags +*/ +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_ratio_t _ratio, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags); + /** * Create 3D texture. * @@ -1039,6 +1060,15 @@ BGFX_C_API void bgfx_destroy_texture(bgfx_texture_handle_t _handle); */ BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer(uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, uint32_t _textureFlags); +/** +* Create frame buffer that scales with backbuffer size. +* +* @param _ratio Backbuffer ratio. +* @param _format Texture format. +* @param _textureFlags Texture flags. +*/ +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_scaled(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint32_t _textureFlags); + /** * Create frame buffer. * diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 4d54d0bc..f82eff81 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -3343,6 +3343,13 @@ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_ return handle.c; } +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_ratio_t _ratio, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; + handle.cpp = bgfx::createTexture2D(bgfx::BackbufferRatio::Enum(_ratio), _numMips, bgfx::TextureFormat::Enum(_format), _flags); + return handle.c; +} + BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem) { union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; @@ -3388,6 +3395,13 @@ BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer(uint16_t _width, return handle.c; } +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_scaled(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint32_t _textureFlags) +{ + union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle; + handle.cpp = bgfx::createFrameBuffer(bgfx::BackbufferRatio::Enum(_ratio), bgfx::TextureFormat::Enum(_format), _textureFlags); + return handle.c; +} + BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_handles(uint8_t _num, bgfx_texture_handle_t* _handles, bool _destroyTextures) { union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle;