forked from MoonsideGames/Refresh
Compare commits
6 Commits
4a1e4a49a8
...
3b0774579f
Author | SHA1 | Date |
---|---|---|
Caleb Cornett | 3b0774579f | |
Caleb Cornett | 5ebbd8ac63 | |
Caleb Cornett | 4d90f97b5a | |
Caleb Cornett | 8325ec1882 | |
Caleb Cornett | 1c43b46b4e | |
Caleb Cornett | 7f9ccbe082 |
|
@ -8,8 +8,8 @@ option(BUILD_SHARED_LIBS "Build shared library" ON)
|
||||||
|
|
||||||
# Version
|
# Version
|
||||||
SET(LIB_MAJOR_VERSION "1")
|
SET(LIB_MAJOR_VERSION "1")
|
||||||
SET(LIB_MINOR_VERSION "3")
|
SET(LIB_MINOR_VERSION "2")
|
||||||
SET(LIB_REVISION "0")
|
SET(LIB_REVISION "1")
|
||||||
SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
|
SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
|
||||||
|
|
||||||
# Build Type
|
# Build Type
|
||||||
|
|
|
@ -55,8 +55,8 @@ extern "C" {
|
||||||
/* Version API */
|
/* Version API */
|
||||||
|
|
||||||
#define REFRESH_MAJOR_VERSION 1
|
#define REFRESH_MAJOR_VERSION 1
|
||||||
#define REFRESH_MINOR_VERSION 3
|
#define REFRESH_MINOR_VERSION 2
|
||||||
#define REFRESH_PATCH_VERSION 0
|
#define REFRESH_PATCH_VERSION 1
|
||||||
|
|
||||||
#define REFRESH_COMPILED_VERSION ( \
|
#define REFRESH_COMPILED_VERSION ( \
|
||||||
(REFRESH_MAJOR_VERSION * 100 * 100) + \
|
(REFRESH_MAJOR_VERSION * 100 * 100) + \
|
||||||
|
@ -107,6 +107,15 @@ typedef enum Refresh_StoreOp
|
||||||
REFRESH_STOREOP_DONT_CARE
|
REFRESH_STOREOP_DONT_CARE
|
||||||
} Refresh_StoreOp;
|
} Refresh_StoreOp;
|
||||||
|
|
||||||
|
typedef enum Refresh_ClearOptionsBits
|
||||||
|
{
|
||||||
|
REFRESH_CLEAROPTIONS_COLOR = 0x00000001,
|
||||||
|
REFRESH_CLEAROPTIONS_DEPTH = 0x00000002,
|
||||||
|
REFRESH_CLEAROPTIONS_STENCIL = 0x00000004,
|
||||||
|
} Refresh_ClearOptionsBits;
|
||||||
|
|
||||||
|
typedef uint32_t Refresh_ClearOptions;
|
||||||
|
|
||||||
typedef enum Refresh_IndexElementSize
|
typedef enum Refresh_IndexElementSize
|
||||||
{
|
{
|
||||||
REFRESH_INDEXELEMENTSIZE_16BIT,
|
REFRESH_INDEXELEMENTSIZE_16BIT,
|
||||||
|
@ -598,6 +607,30 @@ REFRESHAPI void Refresh_DestroyDevice(Refresh_Device *device);
|
||||||
|
|
||||||
/* Drawing */
|
/* Drawing */
|
||||||
|
|
||||||
|
/* Clears the targets of the currently bound framebuffer.
|
||||||
|
* If fewer colors are passed than the number of color targets in the
|
||||||
|
* framebuffer, this function will clear the first n color targets.
|
||||||
|
*
|
||||||
|
* NOTE:
|
||||||
|
* It is generally recommended to clear in BeginRenderPass
|
||||||
|
* rather than by calling this function unless necessary.
|
||||||
|
*
|
||||||
|
* clearRect: Area to clear.
|
||||||
|
* options: Bitflags to specify color/depth/stencil buffers for clearing.
|
||||||
|
* colors: An array of color values for the cleared color buffers.
|
||||||
|
* colorCount: The number of colors in the above array.
|
||||||
|
* depthStencil: Depth and stencil values for the cleared depth stencil buffer.
|
||||||
|
*/
|
||||||
|
REFRESHAPI void Refresh_Clear(
|
||||||
|
Refresh_Device *device,
|
||||||
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
|
Refresh_Rect *clearRect,
|
||||||
|
Refresh_ClearOptions options,
|
||||||
|
Refresh_Vec4 *colors,
|
||||||
|
uint32_t colorCount,
|
||||||
|
Refresh_DepthStencilValue depthStencil
|
||||||
|
);
|
||||||
|
|
||||||
/* Draws data from vertex/index buffers with instancing enabled.
|
/* Draws data from vertex/index buffers with instancing enabled.
|
||||||
*
|
*
|
||||||
* baseVertex: The starting offset to read from the vertex buffer.
|
* baseVertex: The starting offset to read from the vertex buffer.
|
||||||
|
@ -1103,22 +1136,17 @@ REFRESHAPI Refresh_CommandBuffer* Refresh_AcquireCommandBuffer(
|
||||||
|
|
||||||
/* Acquires a texture to use for presentation.
|
/* Acquires a texture to use for presentation.
|
||||||
* May return NULL under certain conditions.
|
* May return NULL under certain conditions.
|
||||||
* If NULL, the user must ensure to not use the texture.
|
* If NULL, the user must ensure to not present.
|
||||||
* Once a swapchain texture is acquired,
|
* Once a swapchain texture is acquired,
|
||||||
* it will automatically be presented on command buffer submission.
|
* it will automatically be presented on command buffer submission.
|
||||||
*
|
*
|
||||||
* NOTE:
|
* NOTE:
|
||||||
* It is not recommended to hold a reference to this texture long term.
|
* It is not recommended to hold a reference to this texture long term.
|
||||||
*
|
|
||||||
* pWidth: A pointer to a uint32 that will be filled with the texture width.
|
|
||||||
* pHeight: A pointer to a uint32 that will be filled with the texture height.
|
|
||||||
*/
|
*/
|
||||||
REFRESHAPI Refresh_Texture* Refresh_AcquireSwapchainTexture(
|
REFRESHAPI Refresh_Texture* Refresh_AcquireSwapchainTexture(
|
||||||
Refresh_Device *device,
|
Refresh_Device *device,
|
||||||
Refresh_CommandBuffer *commandBuffer,
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
void *windowHandle,
|
void *windowHandle
|
||||||
uint32_t *pWidth,
|
|
||||||
uint32_t *pHeight
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/* Returns the format of the swapchain for the given window. */
|
/* Returns the format of the swapchain for the given window. */
|
||||||
|
|
|
@ -173,6 +173,27 @@ void Refresh_DestroyDevice(Refresh_Device *device)
|
||||||
device->DestroyDevice(device);
|
device->DestroyDevice(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Refresh_Clear(
|
||||||
|
Refresh_Device *device,
|
||||||
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
|
Refresh_Rect *clearRect,
|
||||||
|
Refresh_ClearOptions options,
|
||||||
|
Refresh_Vec4 *colors,
|
||||||
|
uint32_t colorCount,
|
||||||
|
Refresh_DepthStencilValue depthStencil
|
||||||
|
) {
|
||||||
|
NULL_RETURN(device);
|
||||||
|
device->Clear(
|
||||||
|
device->driverData,
|
||||||
|
commandBuffer,
|
||||||
|
clearRect,
|
||||||
|
options,
|
||||||
|
colors,
|
||||||
|
colorCount,
|
||||||
|
depthStencil
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void Refresh_DrawIndexedPrimitives(
|
void Refresh_DrawIndexedPrimitives(
|
||||||
Refresh_Device *device,
|
Refresh_Device *device,
|
||||||
Refresh_CommandBuffer *commandBuffer,
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
|
@ -734,17 +755,13 @@ Refresh_CommandBuffer* Refresh_AcquireCommandBuffer(
|
||||||
Refresh_Texture* Refresh_AcquireSwapchainTexture(
|
Refresh_Texture* Refresh_AcquireSwapchainTexture(
|
||||||
Refresh_Device *device,
|
Refresh_Device *device,
|
||||||
Refresh_CommandBuffer *commandBuffer,
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
void *windowHandle,
|
void *windowHandle
|
||||||
uint32_t *pWidth,
|
|
||||||
uint32_t *pHeight
|
|
||||||
) {
|
) {
|
||||||
NULL_RETURN_NULL(device);
|
NULL_RETURN_NULL(device);
|
||||||
return device->AcquireSwapchainTexture(
|
return device->AcquireSwapchainTexture(
|
||||||
device->driverData,
|
device->driverData,
|
||||||
commandBuffer,
|
commandBuffer,
|
||||||
windowHandle,
|
windowHandle
|
||||||
pWidth,
|
|
||||||
pHeight
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,6 +168,16 @@ struct Refresh_Device
|
||||||
|
|
||||||
/* Drawing */
|
/* Drawing */
|
||||||
|
|
||||||
|
void (*Clear)(
|
||||||
|
Refresh_Renderer *driverData,
|
||||||
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
|
Refresh_Rect *clearRect,
|
||||||
|
Refresh_ClearOptions options,
|
||||||
|
Refresh_Vec4 *colors,
|
||||||
|
uint32_t colorCount,
|
||||||
|
Refresh_DepthStencilValue depthStencil
|
||||||
|
);
|
||||||
|
|
||||||
void (*DrawInstancedPrimitives)(
|
void (*DrawInstancedPrimitives)(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
Refresh_CommandBuffer *commandBuffer,
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
|
@ -441,9 +451,7 @@ struct Refresh_Device
|
||||||
Refresh_Texture* (*AcquireSwapchainTexture)(
|
Refresh_Texture* (*AcquireSwapchainTexture)(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
Refresh_CommandBuffer *commandBuffer,
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
void *windowHandle,
|
void *windowHandle
|
||||||
uint32_t *pWidth,
|
|
||||||
uint32_t *pHeight
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Refresh_TextureFormat (*GetSwapchainFormat)(
|
Refresh_TextureFormat (*GetSwapchainFormat)(
|
||||||
|
@ -469,6 +477,7 @@ struct Refresh_Device
|
||||||
result->func = name##_##func;
|
result->func = name##_##func;
|
||||||
#define ASSIGN_DRIVER(name) \
|
#define ASSIGN_DRIVER(name) \
|
||||||
ASSIGN_DRIVER_FUNC(DestroyDevice, name) \
|
ASSIGN_DRIVER_FUNC(DestroyDevice, name) \
|
||||||
|
ASSIGN_DRIVER_FUNC(Clear, name) \
|
||||||
ASSIGN_DRIVER_FUNC(DrawIndexedPrimitives, name) \
|
ASSIGN_DRIVER_FUNC(DrawIndexedPrimitives, name) \
|
||||||
ASSIGN_DRIVER_FUNC(DrawInstancedPrimitives, name) \
|
ASSIGN_DRIVER_FUNC(DrawInstancedPrimitives, name) \
|
||||||
ASSIGN_DRIVER_FUNC(DrawPrimitives, name) \
|
ASSIGN_DRIVER_FUNC(DrawPrimitives, name) \
|
||||||
|
|
|
@ -310,7 +310,7 @@ typedef struct D3D11Renderer
|
||||||
IDXGIAdapter1* adapter;
|
IDXGIAdapter1* adapter;
|
||||||
void *d3d11_dll;
|
void *d3d11_dll;
|
||||||
void *dxgi_dll;
|
void *dxgi_dll;
|
||||||
SDL_mutex *contextLock;
|
SDL_mutex *immediateContextMutex;
|
||||||
|
|
||||||
D3D11CommandBufferPool *commandBufferPool;
|
D3D11CommandBufferPool *commandBufferPool;
|
||||||
SDL_mutex *commandBufferAcquisitionMutex;
|
SDL_mutex *commandBufferAcquisitionMutex;
|
||||||
|
@ -629,6 +629,65 @@ static void D3D11_DestroyDevice(
|
||||||
|
|
||||||
/* Drawing */
|
/* Drawing */
|
||||||
|
|
||||||
|
static void D3D11_Clear(
|
||||||
|
Refresh_Renderer* driverData,
|
||||||
|
Refresh_CommandBuffer* commandBuffer,
|
||||||
|
Refresh_Rect* clearRect,
|
||||||
|
Refresh_ClearOptions options,
|
||||||
|
Refresh_Vec4* colors,
|
||||||
|
uint32_t colorCount,
|
||||||
|
Refresh_DepthStencilValue depthStencil
|
||||||
|
) {
|
||||||
|
D3D11Renderer *renderer = (D3D11Renderer*) driverData;
|
||||||
|
D3D11CommandBuffer *cmdbuf = (D3D11CommandBuffer*) commandBuffer;
|
||||||
|
D3D11_CLEAR_FLAG dsClearFlags;
|
||||||
|
float clearColors[4];
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
|
/* FIXME: What should we do about clearRect? */
|
||||||
|
/* FIXME: Do we need to use colorCount or is it always the number of bound RTs? */
|
||||||
|
|
||||||
|
if (options & REFRESH_CLEAROPTIONS_COLOR)
|
||||||
|
{
|
||||||
|
/* Clear color attachments */
|
||||||
|
for (i = 0; i < cmdbuf->numBoundColorAttachments; i += 1)
|
||||||
|
{
|
||||||
|
clearColors[0] = colors[i].x;
|
||||||
|
clearColors[1] = colors[i].y;
|
||||||
|
clearColors[2] = colors[i].z;
|
||||||
|
clearColors[3] = colors[i].w;
|
||||||
|
|
||||||
|
ID3D11DeviceContext_ClearRenderTargetView(
|
||||||
|
cmdbuf->context,
|
||||||
|
cmdbuf->rtViews[i],
|
||||||
|
clearColors
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check which of depth/stencil need to be cleared (if either) */
|
||||||
|
dsClearFlags = 0;
|
||||||
|
if (options & REFRESH_CLEAROPTIONS_DEPTH)
|
||||||
|
{
|
||||||
|
dsClearFlags |= D3D11_CLEAR_DEPTH;
|
||||||
|
}
|
||||||
|
if (options & REFRESH_CLEAROPTIONS_STENCIL)
|
||||||
|
{
|
||||||
|
dsClearFlags |= D3D11_CLEAR_STENCIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dsClearFlags != 0)
|
||||||
|
{
|
||||||
|
ID3D11DeviceContext_ClearDepthStencilView(
|
||||||
|
cmdbuf->context,
|
||||||
|
cmdbuf->dsView,
|
||||||
|
dsClearFlags,
|
||||||
|
depthStencil.depth,
|
||||||
|
(uint8_t) depthStencil.stencil
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void D3D11_DrawInstancedPrimitives(
|
static void D3D11_DrawInstancedPrimitives(
|
||||||
Refresh_Renderer* driverData,
|
Refresh_Renderer* driverData,
|
||||||
Refresh_CommandBuffer* commandBuffer,
|
Refresh_CommandBuffer* commandBuffer,
|
||||||
|
@ -1143,12 +1202,10 @@ static D3D11SwapchainData* D3D11_INTERNAL_FetchSwapchainData(
|
||||||
return swapchainData;
|
return swapchainData;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Refresh_Texture* D3D11_AcquireSwapchainTexture(
|
Refresh_Texture* D3D11_AcquireSwapchainTexture(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
Refresh_CommandBuffer *commandBuffer,
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
void *windowHandle,
|
void *windowHandle
|
||||||
uint32_t *pWidth,
|
|
||||||
uint32_t *pHeight
|
|
||||||
) {
|
) {
|
||||||
D3D11Renderer *renderer = (D3D11Renderer*) driverData;
|
D3D11Renderer *renderer = (D3D11Renderer*) driverData;
|
||||||
D3D11CommandBuffer *cmdbuf = (D3D11CommandBuffer*) commandBuffer;
|
D3D11CommandBuffer *cmdbuf = (D3D11CommandBuffer*) commandBuffer;
|
||||||
|
@ -1184,10 +1241,6 @@ static Refresh_Texture* D3D11_AcquireSwapchainTexture(
|
||||||
/* Let the command buffer know it's associated with this swapchain. */
|
/* Let the command buffer know it's associated with this swapchain. */
|
||||||
cmdbuf->swapchainData = swapchainData;
|
cmdbuf->swapchainData = swapchainData;
|
||||||
|
|
||||||
/* Send the dimensions to the out parameters. */
|
|
||||||
*pWidth = swapchainData->refreshTexture.twod.width;
|
|
||||||
*pHeight = swapchainData->refreshTexture.twod.height;
|
|
||||||
|
|
||||||
/* Return the swapchain texture */
|
/* Return the swapchain texture */
|
||||||
return (Refresh_Texture*) &swapchainData->refreshTexture;
|
return (Refresh_Texture*) &swapchainData->refreshTexture;
|
||||||
}
|
}
|
||||||
|
@ -1232,13 +1285,13 @@ static void D3D11_Submit(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Submit the command list to the immediate context */
|
/* Submit the command list to the immediate context */
|
||||||
SDL_LockMutex(renderer->contextLock);
|
SDL_LockMutex(renderer->immediateContextMutex);
|
||||||
ID3D11DeviceContext_ExecuteCommandList(
|
ID3D11DeviceContext_ExecuteCommandList(
|
||||||
renderer->immediateContext,
|
renderer->immediateContext,
|
||||||
commandList,
|
commandList,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
SDL_UnlockMutex(renderer->contextLock);
|
SDL_UnlockMutex(renderer->immediateContextMutex);
|
||||||
|
|
||||||
/* Now that we're done, either save the command list or release it. */
|
/* Now that we're done, either save the command list or release it. */
|
||||||
if (commandBuffer->fixed)
|
if (commandBuffer->fixed)
|
||||||
|
@ -1256,13 +1309,11 @@ static void D3D11_Submit(
|
||||||
/* Present, if applicable */
|
/* Present, if applicable */
|
||||||
if (commandBuffer->swapchainData)
|
if (commandBuffer->swapchainData)
|
||||||
{
|
{
|
||||||
SDL_LockMutex(renderer->contextLock);
|
|
||||||
IDXGISwapChain_Present(
|
IDXGISwapChain_Present(
|
||||||
commandBuffer->swapchainData->swapchain,
|
commandBuffer->swapchainData->swapchain,
|
||||||
1, /* FIXME: Assumes vsync! */
|
1, /* FIXME: Assumes vsync! */
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
SDL_UnlockMutex(renderer->contextLock);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1407,7 +1458,7 @@ tryCreateDevice:
|
||||||
SDL_memset(renderer->commandBufferPool, 0, sizeof(D3D11CommandBufferPool));
|
SDL_memset(renderer->commandBufferPool, 0, sizeof(D3D11CommandBufferPool));
|
||||||
|
|
||||||
/* Create mutexes */
|
/* Create mutexes */
|
||||||
renderer->contextLock = SDL_CreateMutex();
|
renderer->immediateContextMutex = SDL_CreateMutex();
|
||||||
renderer->commandBufferAcquisitionMutex = SDL_CreateMutex();
|
renderer->commandBufferAcquisitionMutex = SDL_CreateMutex();
|
||||||
|
|
||||||
/* Initialize miscellaneous renderer members */
|
/* Initialize miscellaneous renderer members */
|
||||||
|
|
|
@ -236,6 +236,18 @@ static void TEMPLATE_DestroyDevice(
|
||||||
|
|
||||||
/* Drawing */
|
/* Drawing */
|
||||||
|
|
||||||
|
static void TEMPLATE_Clear(
|
||||||
|
Refresh_Renderer *driverData,
|
||||||
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
|
Refresh_Rect *clearRect,
|
||||||
|
Refresh_ClearOptions options,
|
||||||
|
Refresh_Vec4 *colors,
|
||||||
|
uint32_t colorCount,
|
||||||
|
Refresh_DepthStencilValue depthStencil
|
||||||
|
) {
|
||||||
|
NOT_IMPLEMENTED
|
||||||
|
}
|
||||||
|
|
||||||
static void TEMPLATE_DrawInstancedPrimitives(
|
static void TEMPLATE_DrawInstancedPrimitives(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
Refresh_CommandBuffer *commandBuffer,
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
|
@ -586,9 +598,7 @@ static Refresh_CommandBuffer* TEMPLATE_AcquireCommandBuffer(
|
||||||
Refresh_Texture* TEMPLATE_AcquireSwapchainTexture(
|
Refresh_Texture* TEMPLATE_AcquireSwapchainTexture(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
Refresh_CommandBuffer *commandBuffer,
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
void *windowHandle,
|
void *windowHandle
|
||||||
uint32_t *pWidth,
|
|
||||||
uint32_t *pHeight
|
|
||||||
) {
|
) {
|
||||||
NOT_IMPLEMENTED
|
NOT_IMPLEMENTED
|
||||||
}
|
}
|
||||||
|
|
|
@ -4798,6 +4798,117 @@ static void VULKAN_DestroyDevice(
|
||||||
SDL_free(device);
|
SDL_free(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void VULKAN_Clear(
|
||||||
|
Refresh_Renderer *driverData,
|
||||||
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
|
Refresh_Rect *clearRect,
|
||||||
|
Refresh_ClearOptions options,
|
||||||
|
Refresh_Vec4 *colors,
|
||||||
|
uint32_t colorCount,
|
||||||
|
Refresh_DepthStencilValue depthStencil
|
||||||
|
) {
|
||||||
|
VulkanRenderer* renderer = (VulkanRenderer*) driverData;
|
||||||
|
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
|
||||||
|
|
||||||
|
uint32_t attachmentCount, i;
|
||||||
|
VkClearAttachment clearAttachments[MAX_COLOR_TARGET_BINDINGS + 1];
|
||||||
|
VkClearRect vulkanClearRect;
|
||||||
|
VkClearValue clearValues[4];
|
||||||
|
|
||||||
|
uint8_t shouldClearColor = options & REFRESH_CLEAROPTIONS_COLOR;
|
||||||
|
uint8_t shouldClearDepth = options & REFRESH_CLEAROPTIONS_DEPTH;
|
||||||
|
uint8_t shouldClearStencil = options & REFRESH_CLEAROPTIONS_STENCIL;
|
||||||
|
|
||||||
|
uint8_t shouldClearDepthStencil = (
|
||||||
|
(shouldClearDepth || shouldClearStencil)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!shouldClearColor && !shouldClearDepthStencil)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vulkanClearRect.baseArrayLayer = 0;
|
||||||
|
vulkanClearRect.layerCount = 1;
|
||||||
|
vulkanClearRect.rect.offset.x = clearRect->x;
|
||||||
|
vulkanClearRect.rect.offset.y = clearRect->y;
|
||||||
|
vulkanClearRect.rect.extent.width = clearRect->w;
|
||||||
|
vulkanClearRect.rect.extent.height = clearRect->h;
|
||||||
|
|
||||||
|
attachmentCount = 0;
|
||||||
|
|
||||||
|
if (shouldClearColor)
|
||||||
|
{
|
||||||
|
for (i = 0; i < colorCount; i += 1)
|
||||||
|
{
|
||||||
|
clearValues[i].color.float32[0] = colors[i].x;
|
||||||
|
clearValues[i].color.float32[1] = colors[i].y;
|
||||||
|
clearValues[i].color.float32[2] = colors[i].z;
|
||||||
|
clearValues[i].color.float32[3] = colors[i].w;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < colorCount; i += 1)
|
||||||
|
{
|
||||||
|
clearAttachments[attachmentCount].aspectMask =
|
||||||
|
VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
|
clearAttachments[attachmentCount].colorAttachment =
|
||||||
|
attachmentCount;
|
||||||
|
clearAttachments[attachmentCount].clearValue =
|
||||||
|
clearValues[attachmentCount];
|
||||||
|
attachmentCount += 1;
|
||||||
|
|
||||||
|
/* Do NOT clear the multisample image here!
|
||||||
|
* Vulkan treats them both as the same color attachment.
|
||||||
|
* Vulkan is a very good and not confusing at all API.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldClearDepthStencil)
|
||||||
|
{
|
||||||
|
clearAttachments[attachmentCount].aspectMask = 0;
|
||||||
|
clearAttachments[attachmentCount].colorAttachment = 0;
|
||||||
|
|
||||||
|
if (shouldClearDepth)
|
||||||
|
{
|
||||||
|
if (depthStencil.depth < 0.0f)
|
||||||
|
{
|
||||||
|
depthStencil.depth = 0.0f;
|
||||||
|
}
|
||||||
|
else if (depthStencil.depth > 1.0f)
|
||||||
|
{
|
||||||
|
depthStencil.depth = 1.0f;
|
||||||
|
}
|
||||||
|
clearAttachments[attachmentCount].aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||||
|
clearAttachments[attachmentCount].clearValue.depthStencil.depth = depthStencil.depth;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
clearAttachments[attachmentCount].clearValue.depthStencil.depth = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldClearStencil)
|
||||||
|
{
|
||||||
|
clearAttachments[attachmentCount].aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||||
|
clearAttachments[attachmentCount].clearValue.depthStencil.stencil = depthStencil.stencil;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
clearAttachments[attachmentCount].clearValue.depthStencil.stencil = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
attachmentCount += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer->vkCmdClearAttachments(
|
||||||
|
vulkanCommandBuffer->commandBuffer,
|
||||||
|
attachmentCount,
|
||||||
|
clearAttachments,
|
||||||
|
1,
|
||||||
|
&vulkanClearRect
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static void VULKAN_DrawInstancedPrimitives(
|
static void VULKAN_DrawInstancedPrimitives(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
Refresh_CommandBuffer *commandBuffer,
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
|
@ -8843,9 +8954,7 @@ static VulkanSwapchainData* VULKAN_INTERNAL_FetchSwapchainData(
|
||||||
static Refresh_Texture* VULKAN_AcquireSwapchainTexture(
|
static Refresh_Texture* VULKAN_AcquireSwapchainTexture(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
Refresh_CommandBuffer *commandBuffer,
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
void *windowHandle,
|
void *windowHandle
|
||||||
uint32_t *pWidth,
|
|
||||||
uint32_t *pHeight
|
|
||||||
) {
|
) {
|
||||||
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
|
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
|
||||||
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
|
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
|
||||||
|
@ -8957,9 +9066,6 @@ static Refresh_Texture* VULKAN_AcquireSwapchainTexture(
|
||||||
vulkanCommandBuffer->signalSemaphores[vulkanCommandBuffer->signalSemaphoreCount] = swapchainData->renderFinishedSemaphore;
|
vulkanCommandBuffer->signalSemaphores[vulkanCommandBuffer->signalSemaphoreCount] = swapchainData->renderFinishedSemaphore;
|
||||||
vulkanCommandBuffer->signalSemaphoreCount += 1;
|
vulkanCommandBuffer->signalSemaphoreCount += 1;
|
||||||
|
|
||||||
*pWidth = swapchainData->extent.width;
|
|
||||||
*pHeight = swapchainData->extent.height;
|
|
||||||
|
|
||||||
return (Refresh_Texture*) swapchainTexture;
|
return (Refresh_Texture*) swapchainTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue