add some utilities for double buffering
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "stdlib.h"
|
||||
#include "utils/gryphn_error_code.h"
|
||||
#include "utils/lists/gryphn_array_list.h"
|
||||
#include <core/gryphn_handles.h>
|
||||
|
||||
typedef enum gnIndexType {
|
||||
@@ -30,8 +31,11 @@ struct gnBuffer_t {
|
||||
gnBufferInfo info;
|
||||
};
|
||||
#endif
|
||||
typedef void* gnBufferMemory;
|
||||
GN_ARRAY_LIST(gnBuffer);
|
||||
GN_ARRAY_LIST(gnBufferMemory);
|
||||
|
||||
gnReturnCode gnCreateBuffer(gnBufferHandle* buffer, gnOutputDeviceHandle device, gnBufferInfo info);
|
||||
void gnBufferData(gnBufferHandle buffer, size_t dataSize, void* data);
|
||||
void* gnMapBuffer(gnBufferHandle buffer);
|
||||
void gnBufferData(gnBufferHandle buffer, size_t dataSize, gnBufferMemory data);
|
||||
gnBufferMemory gnMapBuffer(gnBufferHandle buffer);
|
||||
void gnDestroyBuffer(gnBufferHandle buffer);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include "gryphn_command_buffer.h"
|
||||
#include "core/gryphn_platform_functions.h"
|
||||
|
||||
gnReturnCode gnCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool) {
|
||||
gnReturnCode gnCommandPoolAllocateCommandBuffersFromPointer(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
buffers[i] = malloc(sizeof(struct gnCommandBuffer_t));
|
||||
buffers[i]->commandPool = commandPool;
|
||||
@@ -9,6 +9,14 @@ gnReturnCode gnCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* buffers,
|
||||
return commandPool->commandFunctions->_gnCommandPoolAllocateCommandBuffers(buffers, count, commandPool);
|
||||
}
|
||||
|
||||
gnReturnCode gnCommandPoolAllocateCommandBuffersFromList(gnCommandBufferArrayList buffers, uint32_t count, gnCommandPoolHandle commandPool) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
buffers.data[i] = malloc(sizeof(struct gnCommandBuffer_t));
|
||||
buffers.data[i]->commandPool = commandPool;
|
||||
}
|
||||
return gnCommandPoolAllocateCommandBuffersFromPointer(buffers.data, count, commandPool);
|
||||
}
|
||||
|
||||
void gnResetCommandBuffer(gnCommandBufferHandle commandBuffer) {
|
||||
commandBuffer->commandPool->commandFunctions->_gnResetCommandBuffer(commandBuffer);
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "stdint.h"
|
||||
#include "utils/gryphn_error_code.h"
|
||||
#include "utils/lists/gryphn_array_list.h"
|
||||
#include "core/gryphn_handles.h"
|
||||
|
||||
#ifdef GN_REVEAL_IMPL
|
||||
@@ -10,7 +11,17 @@ struct gnCommandBuffer_t {
|
||||
};
|
||||
#endif
|
||||
|
||||
gnReturnCode gnCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool);
|
||||
GN_ARRAY_LIST(gnCommandBuffer);
|
||||
|
||||
gnReturnCode gnCommandPoolAllocateCommandBuffersFromPointer(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool);
|
||||
// will reserve the space for ${count} number of elements
|
||||
gnReturnCode gnCommandPoolAllocateCommandBuffersFromList(gnCommandBufferArrayList buffers, uint32_t count, gnCommandPoolHandle commandPool);
|
||||
|
||||
#define gnCommandPoolAllocateCommandBuffers(buffers, count, commandPool) \
|
||||
_Generic((buffers), \
|
||||
gnCommandBufferArrayList: gnCommandPoolAllocateCommandBuffersFromList, \
|
||||
default: gnCommandPoolAllocateCommandBuffersFromPointer \
|
||||
)(buffers, count, commandPool)
|
||||
|
||||
void gnResetCommandBuffer(gnCommandBufferHandle commandBuffer);
|
||||
gnReturnCode gnBeginCommandBuffer(gnCommandBufferHandle commandBuffer);
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include "stdint.h"
|
||||
#include "utils/gryphn_bool.h"
|
||||
#include "utils/gryphn_error_code.h"
|
||||
#include "utils/lists/gryphn_array_list.h"
|
||||
#include "core/gryphn_handles.h"
|
||||
|
||||
#ifdef GN_REVEAL_IMPL
|
||||
@@ -11,6 +12,7 @@ struct gnFence_t {
|
||||
gnBool signaled;
|
||||
};
|
||||
#endif
|
||||
GN_ARRAY_LIST(gnFence);
|
||||
|
||||
gnReturnCode gnCreateFence(gnFenceHandle* fence, gnOutputDeviceHandle device);
|
||||
void gnSignalFence(gnFenceHandle fence);
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "core/gryphn_handles.h"
|
||||
#include "utils/gryphn_error_code.h"
|
||||
#include "utils/lists/gryphn_array_list.h"
|
||||
|
||||
#ifdef GN_REVEAL_IMPL
|
||||
struct gnSemaphore_t {
|
||||
@@ -8,6 +9,7 @@ struct gnSemaphore_t {
|
||||
gnOutputDeviceHandle device;
|
||||
};
|
||||
#endif
|
||||
GN_ARRAY_LIST(gnSemaphore);
|
||||
|
||||
gnReturnCode gnCreateSemaphore(gnSemaphore* semaphore, struct gnOutputDevice_t* device);
|
||||
void gnDestroySemaphore(gnSemaphore semaphore);
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "stdint.h"
|
||||
#include "stdlib.h"
|
||||
#include "utils/lists/gryphn_array_list.h"
|
||||
#include "core/gryphn_handles.h"
|
||||
|
||||
typedef struct gnBufferUniformInfo {
|
||||
@@ -16,5 +17,6 @@ struct gnUniform_t {
|
||||
gnUniformPool pool;
|
||||
};
|
||||
#endif
|
||||
GN_ARRAY_LIST(gnUniform)
|
||||
|
||||
void gnUpdateBufferUniform(gnUniform uniform, gnBufferUniformInfo bufferInfo);
|
||||
|
@@ -11,11 +11,15 @@ gnReturnCode gnCreateUniformPool(gnUniformPool* pool, gnDeviceHandle device) {
|
||||
}
|
||||
|
||||
// you own this memory now
|
||||
gnUniform* gnUniformPoolAllocateUniforms(gnUniformPool pool, const gnUniformLayout layout) {
|
||||
gnUniformArrayList gnUniformPoolAllocateUniforms(gnUniformPool pool, const gnUniformLayout layout, uint32_t count) {
|
||||
gnUniform* uniforms = pool->device->deviceFunctions->_gnUniformPoolAllocateUniforms(pool, layout);
|
||||
for (int i = 0; i < layout.uniformBindingCount; i++)
|
||||
uniforms[i]->pool = pool;
|
||||
return uniforms;
|
||||
|
||||
gnUniformArrayList list = gnUniformArrayListCreate();
|
||||
gnUniformArrayListResize(&list, layout.uniformBindingCount);
|
||||
for (int i = 0; i < layout.uniformBindingCount; i++) list.data[i] = uniforms[i];
|
||||
return list;
|
||||
}
|
||||
|
||||
void gnDestroyUniformPool(gnUniformPool pool) {
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include "core/gryphn_handles.h"
|
||||
#include "utils/gryphn_error_code.h"
|
||||
#include "core/uniforms/gryphn_uniform_layout.h"
|
||||
#include "core/uniforms/gryphn_uniform.h"
|
||||
|
||||
#ifdef GN_REVEAL_IMPL
|
||||
struct gnUniformPool_t {
|
||||
@@ -11,5 +12,5 @@ struct gnUniformPool_t {
|
||||
#endif
|
||||
|
||||
gnReturnCode gnCreateUniformPool(gnUniformPool* pool, gnDeviceHandle device);
|
||||
gnUniform* gnUniformPoolAllocateUniforms(gnUniformPool pool, const gnUniformLayout layout);
|
||||
gnUniformArrayList gnUniformPoolAllocateUniforms(gnUniformPool pool, const gnUniformLayout layout);
|
||||
void gnDestroyUniformPool(gnUniformPool pool);
|
||||
|
Reference in New Issue
Block a user