LWJGL Forum

Please login or register.

Login with username, password and session length

Author Topic: No setter in various BGFX classes  (Read 424 times)

bcbradle

  • Newbie
  • *
  • Offline Offline
  • Posts: 17
No setter in various BGFX classes
« on: June 10, 2017, 12:43:58 »

Specifically

  • BGFXTransform
  • BGFXTextureInfo
  • BGFXMemory
  • BGFXCallbackInterface
  • BGFXInstanceDataBuffer

BGFXTransform is required as an argument to:
  • bgfx_alloc_transform

BGFXInstanceDataBuffer is required as an argument to:
  • bgfx_set_instance_data_buffer

BGFXTextureInfo is required as an argument to:
  • bgfx_calc_texture_size
  • bgfx_create_texture

BGFXMemory is required as an argument to:
  • bgfx_create_dynamic_index_buffer_mem
  • bgfx_create_dynamic_vertex_buffer_mem
  • bgfx_create_index_buffer
  • bgfx_create_shader
  • bgfx_create_texture_2d
  • bgfx_create_texture_3d
  • bgfx_create_texture
  • bgfx_create_dynamic_vertex_buffer
  • bgfx_update_dynamic_index_buffer
  • bgfx_update_dynamic_vertex_buffer
  • bgfx_update_texture_2d
  • bgfx_update_texture_3d
  • bgfx_update_texture_cube

BGFXCallbackInterface is required as an argument to:
  • bgfx_init

Since these functions take these structures as arguments then either the function depends on the values within the structures or the contents of the structure will be mutated imperatively.

Can you tell me which of the above are dependencies for their respective functions and which are not?

Also, in the cases for which the functions depend on the the values within the structures, how would I set the state of the structures without a setter? Can you give me examples for those cases?

I know I'm asking a lot here, but I'm just trying to understand how this is put together.
Logged

spasi

  • Administrator
  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 1908
Re: No setter in various BGFX classes
« Reply #1 on: June 10, 2017, 19:50:12 »

Disclaimer: I haven't used bgfx for anything serious, the below information is based on the public API and documentation. I have verified non-obvious cases by looking into bgfx's source, but please do let me know if you think I've misunderstood something.

BGFXTransform is required as an argument to:
  • bgfx_alloc_transform

You allocate a BGFXTransform, but you do not fill it with anything. The call to bgfx_alloc_transform will initialize the struct with a data pointer that's internal to bgfx. You then access the pointer with .data(), returning a FloatBuffer (wrapping 4 x 4 x .num() floats) which is obviously mutable.

BGFXInstanceDataBuffer is required as an argument to:
  • bgfx_set_instance_data_buffer

BGFXInstanceDataBuffer instances are created with bgfx_alloc_instance_data_buffer. No member should be modified, except the contents of the .data() buffer. A BGFXInstanceDataBuffer instance is deallocated after a call to bgfx_set_instance_data_buffer.

BGFXTextureInfo is required as an argument to:
  • bgfx_calc_texture_size
  • bgfx_create_texture

In both functions, the _info parameter is an output parameter.

BGFXMemory is required as an argument to:
  • bgfx_create_dynamic_index_buffer_mem
  • bgfx_create_dynamic_vertex_buffer_mem
  • bgfx_create_index_buffer
  • bgfx_create_shader
  • bgfx_create_texture_2d
  • bgfx_create_texture_3d
  • bgfx_create_texture
  • bgfx_create_dynamic_vertex_buffer
  • bgfx_update_dynamic_index_buffer
  • bgfx_update_dynamic_vertex_buffer
  • bgfx_update_texture_2d
  • bgfx_update_texture_3d
  • bgfx_update_texture_cube

BGFXMemory is already mutable. Note that there's a setter for data only, the size member is populated automatically based on the buffer size. If that is inconvenient somehow, you can use the "unsafe" static setters (ndata & nsize).

BGFXCallbackInterface is required as an argument to:
  • bgfx_init

BGFXCallbackInterface is already mutable. See the vtbl(BGFXCallbackVtbl value) method.
Logged

CoDi

  • Newbie
  • *
  • Offline Offline
  • Posts: 40
Re: No setter in various BGFX classes
« Reply #2 on: August 11, 2017, 09:48:02 »

Yes, the bgfx API is a little more involved. As a general rule (there might be bugs of course), if there's no setter, you are not supposed to fill in any properties yourself.

BGFXMemory instances can be created with bgfx_alloc, bgfx_copy, bgfx_make_ref and bgfx_make_ref_release.

I recommend to have a look at the samples in lwjgl3-demos. They also show how to setup the callback interface.
Logged