File: UniformBuffer.h

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (87 lines) | stat: -rw-r--r-- 2,498 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#pragma once


#include "graphics/2d.h"
#include "UniformAligner.h"

namespace graphics {
namespace util {

class UniformBufferManager;

/**
 * @brief Manages a uniform buffer memory range
 *
 * This class will be used by the uniform buffer manager for allowing user code direct access to uniform buffer memory.
 * This also contains a UniformAligner which can be used for making sure that the data is aligned properly for GPU
 * access.
 */
class UniformBuffer {
	UniformBufferManager* _parent = nullptr;
	size_t _parent_offset         = 0;

	gr_buffer_handle _buffer_handle;

	UniformAligner _aligner;

  public:
	UniformBuffer();
	UniformBuffer(UniformBufferManager* parent, size_t parent_offset, void* data_buffer, size_t buffer_size,
	              size_t element_size, size_t header_size, size_t element_alignment);
	~UniformBuffer();

	UniformBuffer(const UniformBuffer&) = delete;
	UniformBuffer& operator=(const UniformBuffer&) = delete;

	UniformBuffer(UniformBuffer&&) = default;
	UniformBuffer& operator=(UniformBuffer&&) = default;

	inline UniformAligner& aligner() {
		return _aligner;
	}

	/**
	 * @brief Gets the buffer handle for use with gr_bind_uniform_buffer.
	 * @return The buffer handle
	 */
	gr_buffer_handle bufferHandle();

	/**
	 * @brief Submits the data from the uniform aligner to the underlying buffer object.
	 *
	 * This should be called when you are done building the uniform data.
	 */
	void submitData();

	/**
	 * @brief Given the offset into the memory buffer, returns the total offset in the buffer object
	 *
	 * This should be used for retrieving the correct offset for gr_bind_uniform_buffer.
	 *
	 * @param localOffset The offset into the local memory buffer (e.g. the return value of
	 * 	UniformAligner::getCurrentOffset)
	 * @return The absolute offset in the uniform buffer object.
	 */
	size_t getBufferOffset(size_t localOffset);

	/**
	 * @brief Gets the absolute offset to the specified element in the aligner
	 * This should be used for retrieving the correct offset for gr_bind_uniform_buffer.
	 *
	 * @param index The element index to be retrieved
	 * @return The absolute offset in the uniform buffer object.
	 */
	size_t getAlignerElementOffset(size_t index);

	/**
	 * @brief Gets the absolute offset of the current element in the aligner
	 * This should be used for retrieving the correct offset for gr_bind_uniform_buffer.
	 *
	 * @return The absolute offset in the uniform buffer object.
	 */
	size_t getCurrentAlignerOffset();
};

}
}