MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / AcquireMemory

Method AcquireMemory

Sources/nCine/Graphics/RenderBuffersManager.cpp:65–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63 }
64
65 RenderBuffersManager::Parameters RenderBuffersManager::AcquireMemory(BufferTypes type, std::uint32_t bytes, std::uint32_t alignment)
66 {
67 FATAL_ASSERT_MSG(bytes <= specs_[std::int32_t(type)].maxSize, "Trying to acquire {} bytes when the maximum for buffer type \"{}\" is {}",
68 bytes, bufferTypeToString(type), specs_[std::int32_t(type)].maxSize);
69
70 // Accepting a custom alignment only if it is a multiple of the specification one
71 if (alignment % specs_[std::int32_t(type)].alignment != 0) {
72 alignment = specs_[std::int32_t(type)].alignment;
73 }
74
75 Parameters params;
76
77 for (ManagedBuffer& buffer : buffers_) {
78 if (buffer.type == type) {
79 const std::uint32_t offset = buffer.size - buffer.freeSpace;
80 const std::uint32_t alignAmount = (alignment - offset % alignment) % alignment;
81
82 if (buffer.freeSpace >= bytes + alignAmount) {
83 params.object = buffer.object.get();
84 params.offset = offset + alignAmount;
85 params.size = bytes;
86 buffer.freeSpace -= bytes + alignAmount;
87 params.mapBase = buffer.mapBase;
88 break;
89 }
90 }
91 }
92
93 if (params.object == nullptr) {
94 CreateBuffer(specs_[std::int32_t(type)]);
95 params.object = buffers_.back().object.get();
96 params.offset = 0;
97 params.size = bytes;
98 buffers_.back().freeSpace -= bytes;
99 params.mapBase = buffers_.back().mapBase;
100 }
101
102 return params;
103 }
104
105 void RenderBuffersManager::FlushUnmap()
106 {

Callers

nothing calls this directly

Calls 3

bufferTypeToStringFunction · 0.85
getMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected