Explorar o código

Added setInstanceCount.

Branimir Karadžić %!s(int64=7) %!d(string=hai) anos
pai
achega
00b6beab16
Modificáronse 6 ficheiros con 40 adicións e 1 borrados
  1. 6 0
      include/bgfx/bgfx.h
  2. 3 0
      include/bgfx/c99/bgfx.h
  3. 1 0
      include/bgfx/c99/platform.h
  4. 1 1
      include/bgfx/defines.h
  5. 23 0
      src/bgfx.cpp
  6. 6 0
      src/bgfx_p.h

+ 6 - 0
include/bgfx/bgfx.h

@@ -1303,6 +1303,9 @@ namespace bgfx
 			, uint32_t _num
 			);
 
+		///
+		void setInstanceCount(uint32_t _numInstances);
+
 		/// Set texture stage for draw primitive.
 		///
 		/// @param[in] _stage Texture unit.
@@ -3633,6 +3636,9 @@ namespace bgfx
 		, uint32_t _num
 		);
 
+	///
+	void setInstanceCount(uint32_t _numInstances);
+
 	/// Set texture stage for draw primitive.
 	///
 	/// @param[in] _stage Texture unit.

+ 3 - 0
include/bgfx/c99/bgfx.h

@@ -992,6 +992,9 @@ BGFX_C_API void bgfx_set_instance_data_from_vertex_buffer(bgfx_vertex_buffer_han
 /**/
 BGFX_C_API void bgfx_set_instance_data_from_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num);
 
+/**/
+BGFX_C_API void bgfx_set_instance_count(uint32_t _numInstances);
+
 /**/
 BGFX_C_API void bgfx_set_texture(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags);
 

+ 1 - 0
include/bgfx/c99/platform.h

@@ -187,6 +187,7 @@ typedef struct bgfx_interface_vtbl
     void (*encoder_set_instance_data_buffer)(struct bgfx_encoder_s* _encoder, const bgfx_instance_data_buffer_t* _idb, uint32_t _start, uint32_t _num);
     void (*encoder_set_instance_data_from_vertex_buffer)(struct bgfx_encoder_s* _encoder, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num);
     void (*encoder_set_instance_data_from_dynamic_vertex_buffer)(struct bgfx_encoder_s* _encoder, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num);
+    void (*encoder_set_instance_count)(struct bgfx_encoder_s* _encoder, uint32_t _numInstance);
     void (*encoder_set_texture)(struct bgfx_encoder_s* _encoder, uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags);
     void (*encoder_touch)(struct bgfx_encoder_s* _encoder, bgfx_view_id_t _id);
     void (*encoder_submit)(struct bgfx_encoder_s* _encoder, bgfx_view_id_t _id, bgfx_program_handle_t _handle, int32_t _depth, bool _preserveState);

+ 1 - 1
include/bgfx/defines.h

@@ -6,7 +6,7 @@
 #ifndef BGFX_DEFINES_H_HEADER_GUARD
 #define BGFX_DEFINES_H_HEADER_GUARD
 
-#define BGFX_API_VERSION UINT32_C(80)
+#define BGFX_API_VERSION UINT32_C(82)
 
 /// Color RGB/alpha/depth write. When it's not specified write will be disabled.
 #define BGFX_STATE_WRITE_R                 UINT64_C(0x0000000000000001) //!< Enable R write.

+ 23 - 0
src/bgfx.cpp

@@ -3179,6 +3179,12 @@ namespace bgfx
 			) );
 	}
 
+	void Encoder::setInstanceCount(uint32_t _numInstances)
+	{
+		BGFX_CHECK_CAPS(BGFX_CAPS_VERTEX_ID, "Auto generated instances are not supported!");
+		BGFX_ENCODER(setInstanceCount(_numInstances) );
+	}
+
 	void Encoder::setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags)
 	{
 		BGFX_CHECK_HANDLE("setTexture/UniformHandle", s_ctx->m_uniformHandle, _sampler);
@@ -4351,6 +4357,12 @@ namespace bgfx
 		s_ctx->m_encoder0->setInstanceDataBuffer(_handle, _startVertex, _num);
 	}
 
+	void setInstanceCount(uint32_t _numInstances)
+	{
+		BGFX_CHECK_API_THREAD();
+		s_ctx->m_encoder0->setInstanceCount(_numInstances);
+	}
+
 	void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags)
 	{
 		BGFX_CHECK_API_THREAD();
@@ -5480,6 +5492,11 @@ BGFX_C_API void bgfx_set_instance_data_from_dynamic_vertex_buffer(bgfx_dynamic_v
 	bgfx::setInstanceDataBuffer(handle.cpp, _startVertex, _num);
 }
 
+BGFX_C_API void bgfx_set_instance_count(uint32_t _numInstances)
+{
+	bgfx::setInstanceCount(_numInstances);
+}
+
 BGFX_C_API void bgfx_set_texture(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags)
 {
 	union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } sampler = { _sampler };
@@ -5683,6 +5700,11 @@ BGFX_C_API void bgfx_encoder_set_instance_data_from_dynamic_vertex_buffer(bgfx_e
 	BGFX_ENCODER(setInstanceDataBuffer(handle.cpp, _startVertex, _num) );
 }
 
+BGFX_C_API void bgfx_encoder_set_instance_count(bgfx_encoder_s* _encoder, uint32_t _numInstances)
+{
+	BGFX_ENCODER(setVertexCount(_numInstances) );
+}
+
 BGFX_C_API void bgfx_encoder_set_texture(bgfx_encoder_s* _encoder, uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags)
 {
 	union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } sampler = { _sampler };
@@ -5937,6 +5959,7 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version)
 	BGFX_IMPORT_FUNC(encoder_set_instance_data_buffer)                     \
 	BGFX_IMPORT_FUNC(encoder_set_instance_data_from_vertex_buffer)         \
 	BGFX_IMPORT_FUNC(encoder_set_instance_data_from_dynamic_vertex_buffer) \
+	BGFX_IMPORT_FUNC(encoder_set_instance_count)                           \
 	BGFX_IMPORT_FUNC(encoder_set_texture)                                  \
 	BGFX_IMPORT_FUNC(encoder_touch)                                        \
 	BGFX_IMPORT_FUNC(encoder_submit)                                       \

+ 6 - 0
src/bgfx_p.h

@@ -2290,6 +2290,12 @@ namespace bgfx
 			m_draw.m_instanceDataBuffer = _handle;
 		}
 
+		void setInstanceCount(uint32_t _numInstances)
+		{
+			BX_CHECK(!isValid(m_draw.m_instanceDataBuffer), "Instance buffer already set.");
+			m_draw.m_numInstances = _numInstances;
+		}
+
 		void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags)
 		{
 			Binding& bind = m_bind.m_bind[_stage];