texture creation uses one function + Refresh_TextureCreateInfo

pull/1/head
cosmonaut 2021-01-14 01:52:45 -08:00
parent 79bc36d99d
commit 56f4c3c2c4
4 changed files with 33 additions and 235 deletions

View File

@ -519,6 +519,18 @@ typedef struct Refresh_ShaderModuleCreateInfo
const uint32_t *byteCode; const uint32_t *byteCode;
} Refresh_ShaderModuleCreateInfo; } Refresh_ShaderModuleCreateInfo;
typedef struct Refresh_TextureCreateInfo
{
uint32_t width;
uint32_t height;
uint32_t depth;
uint32_t isCube;
Refresh_SampleCount sampleCount;
uint32_t levelCount;
Refresh_ColorFormat format;
Refresh_TextureUsageFlags usageFlags;
} Refresh_TextureCreateInfo;
/* Pipeline state structures */ /* Pipeline state structures */
typedef struct Refresh_ShaderStageState typedef struct Refresh_ShaderStageState
@ -856,64 +868,12 @@ REFRESHAPI Refresh_ShaderModule* Refresh_CreateShaderModule(
Refresh_ShaderModuleCreateInfo *shaderModuleCreateInfo Refresh_ShaderModuleCreateInfo *shaderModuleCreateInfo
); );
/* Creates a 2D texture. /* Returns an allocated Refresh_Texture* object. Note that the contents of
*
* format: The pixel format of the texture data.
* width: The width of the texture image.
* height: The height of the texture image.
* levelCount: The number of mipmap levels to allocate.
* usageFlags: Specifies how the texture will be used.
*
* Returns an allocated Refresh_Texture* object. Note that the contents of
* the texture are undefined until SetData is called. * the texture are undefined until SetData is called.
*/ */
REFRESHAPI Refresh_Texture* Refresh_CreateTexture2D( REFRESHAPI Refresh_Texture* Refresh_CreateTexture(
Refresh_Device *device, Refresh_Device *device,
Refresh_ColorFormat format, Refresh_TextureCreateInfo *textureCreateInfo
uint32_t width,
uint32_t height,
uint32_t levelCount,
Refresh_TextureUsageFlags usageFlags
);
/* Creates a 3D texture.
*
* format: The pixel format of the texture data.
* width: The width of the texture image.
* height: The height of the texture image.
* depth: The depth of the texture image.
* levelCount: The number of mipmap levels to allocate.
* usageFlags: Specifies how the texture will be used.
*
* Returns an allocated Refresh_Texture* object. Note that the contents of
* the texture are undefined until SetData is called.
*/
REFRESHAPI Refresh_Texture* Refresh_CreateTexture3D(
Refresh_Device *device,
Refresh_ColorFormat format,
uint32_t width,
uint32_t height,
uint32_t depth,
uint32_t levelCount,
Refresh_TextureUsageFlags usageFlags
);
/* Creates a texture cube.
*
* format: The pixel format of the texture data.
* size: The length of the cube side.
* levelCount: The number of mipmap levels to allocate.
* usageFlags: Specifies how the texture will be used.
*
* Returns an allocated Refresh_Texture* object. Note that the contents of
* the texture are undefined until SetData is called.
*/
REFRESHAPI Refresh_Texture* Refresh_CreateTextureCube(
Refresh_Device *device,
Refresh_ColorFormat format,
uint32_t size,
uint32_t levelCount,
Refresh_TextureUsageFlags usageFlags
); );
/* Creates a color target. /* Creates a color target.

View File

@ -338,60 +338,14 @@ Refresh_ShaderModule* Refresh_CreateShaderModule(
); );
} }
Refresh_Texture* Refresh_CreateTexture2D( Refresh_Texture* Refresh_CreateTexture(
Refresh_Device *device, Refresh_Device *device,
Refresh_ColorFormat format, Refresh_TextureCreateInfo *textureCreateInfo
uint32_t width,
uint32_t height,
uint32_t levelCount,
Refresh_TextureUsageFlags usageFlags
) { ) {
NULL_RETURN_NULL(device); NULL_RETURN_NULL(device);
return device->CreateTexture2D( return device->CreateTexture(
device->driverData, device->driverData,
format, textureCreateInfo
width,
height,
levelCount,
usageFlags
);
}
Refresh_Texture* Refresh_CreateTexture3D(
Refresh_Device *device,
Refresh_ColorFormat format,
uint32_t width,
uint32_t height,
uint32_t depth,
uint32_t levelCount,
Refresh_TextureUsageFlags usageFlags
) {
NULL_RETURN_NULL(device);
return device->CreateTexture3D(
device->driverData,
format,
width,
height,
depth,
levelCount,
usageFlags
);
}
Refresh_Texture* Refresh_CreateTextureCube(
Refresh_Device *device,
Refresh_ColorFormat format,
uint32_t size,
uint32_t levelCount,
Refresh_TextureUsageFlags usageFlags
) {
NULL_RETURN_NULL(device);
return device->CreateTextureCube(
device->driverData,
format,
size,
levelCount,
usageFlags
); );
} }

View File

@ -249,31 +249,9 @@ struct Refresh_Device
Refresh_ShaderModuleCreateInfo *shaderModuleCreateInfo Refresh_ShaderModuleCreateInfo *shaderModuleCreateInfo
); );
Refresh_Texture* (*CreateTexture2D)( Refresh_Texture* (*CreateTexture)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_ColorFormat format, Refresh_TextureCreateInfo *textureCreateInfo
uint32_t width,
uint32_t height,
uint32_t levelCount,
Refresh_TextureUsageFlags usageFlags
);
Refresh_Texture* (*CreateTexture3D)(
Refresh_Renderer *driverData,
Refresh_ColorFormat format,
uint32_t width,
uint32_t height,
uint32_t depth,
uint32_t levelCount,
Refresh_TextureUsageFlags usageFlags
);
Refresh_Texture* (*CreateTextureCube)(
Refresh_Renderer *driverData,
Refresh_ColorFormat format,
uint32_t size,
uint32_t levelCount,
Refresh_TextureUsageFlags usageFlags
); );
Refresh_ColorTarget* (*CreateColorTarget)( Refresh_ColorTarget* (*CreateColorTarget)(
@ -543,9 +521,7 @@ struct Refresh_Device
ASSIGN_DRIVER_FUNC(CreateSampler, name) \ ASSIGN_DRIVER_FUNC(CreateSampler, name) \
ASSIGN_DRIVER_FUNC(CreateFramebuffer, name) \ ASSIGN_DRIVER_FUNC(CreateFramebuffer, name) \
ASSIGN_DRIVER_FUNC(CreateShaderModule, name) \ ASSIGN_DRIVER_FUNC(CreateShaderModule, name) \
ASSIGN_DRIVER_FUNC(CreateTexture2D, name) \ ASSIGN_DRIVER_FUNC(CreateTexture, name) \
ASSIGN_DRIVER_FUNC(CreateTexture3D, name) \
ASSIGN_DRIVER_FUNC(CreateTextureCube, name) \
ASSIGN_DRIVER_FUNC(CreateColorTarget, name) \ ASSIGN_DRIVER_FUNC(CreateColorTarget, name) \
ASSIGN_DRIVER_FUNC(CreateDepthStencilTarget, name) \ ASSIGN_DRIVER_FUNC(CreateDepthStencilTarget, name) \
ASSIGN_DRIVER_FUNC(CreateBuffer, name) \ ASSIGN_DRIVER_FUNC(CreateBuffer, name) \

View File

@ -5570,13 +5570,9 @@ static uint8_t VULKAN_INTERNAL_CreateTexture(
return 1; return 1;
} }
static Refresh_Texture* VULKAN_CreateTexture2D( static Refresh_Texture* VULKAN_CreateTexture(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_ColorFormat format, Refresh_TextureCreateInfo *textureCreateInfo
uint32_t width,
uint32_t height,
uint32_t levelCount,
Refresh_TextureUsageFlags usageFlags
) { ) {
VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanRenderer *renderer = (VulkanRenderer*) driverData;
VulkanTexture *result; VulkanTexture *result;
@ -5586,7 +5582,7 @@ static Refresh_Texture* VULKAN_CreateTexture2D(
VK_IMAGE_USAGE_TRANSFER_SRC_BIT VK_IMAGE_USAGE_TRANSFER_SRC_BIT
); );
if (usageFlags & REFRESH_TEXTUREUSAGE_COLOR_TARGET_BIT) if (textureCreateInfo->usageFlags & REFRESH_TEXTUREUSAGE_COLOR_TARGET_BIT)
{ {
imageUsageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; imageUsageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
} }
@ -5595,109 +5591,21 @@ static Refresh_Texture* VULKAN_CreateTexture2D(
VULKAN_INTERNAL_CreateTexture( VULKAN_INTERNAL_CreateTexture(
renderer, renderer,
width, textureCreateInfo->width,
height, textureCreateInfo->height,
1, textureCreateInfo->depth,
0, textureCreateInfo->isCube,
VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT,
levelCount, textureCreateInfo->levelCount,
RefreshToVK_SurfaceFormat[format], RefreshToVK_SurfaceFormat[textureCreateInfo->format],
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_ASPECT_COLOR_BIT,
VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_TILING_OPTIMAL,
VK_IMAGE_TYPE_2D, VK_IMAGE_TYPE_2D,
imageUsageFlags, imageUsageFlags,
usageFlags, textureCreateInfo->usageFlags,
result result
); );
result->colorFormat = format; result->colorFormat = textureCreateInfo->format;
return (Refresh_Texture*) result;
}
static Refresh_Texture* VULKAN_CreateTexture3D(
Refresh_Renderer *driverData,
Refresh_ColorFormat format,
uint32_t width,
uint32_t height,
uint32_t depth,
uint32_t levelCount,
Refresh_TextureUsageFlags usageFlags
) {
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
VulkanTexture *result;
VkImageUsageFlags imageUsageFlags = (
VK_IMAGE_USAGE_SAMPLED_BIT |
VK_IMAGE_USAGE_TRANSFER_DST_BIT |
VK_IMAGE_USAGE_TRANSFER_SRC_BIT
);
if (usageFlags & REFRESH_TEXTUREUSAGE_COLOR_TARGET_BIT)
{
imageUsageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
}
result = (VulkanTexture*) SDL_malloc(sizeof(VulkanTexture));
VULKAN_INTERNAL_CreateTexture(
renderer,
width,
height,
depth,
0,
VK_SAMPLE_COUNT_1_BIT,
levelCount,
RefreshToVK_SurfaceFormat[format],
VK_IMAGE_ASPECT_COLOR_BIT,
VK_IMAGE_TILING_OPTIMAL,
VK_IMAGE_TYPE_3D,
imageUsageFlags,
usageFlags,
result
);
result->colorFormat = format;
return (Refresh_Texture*) result;
}
static Refresh_Texture* VULKAN_CreateTextureCube(
Refresh_Renderer *driverData,
Refresh_ColorFormat format,
uint32_t size,
uint32_t levelCount,
Refresh_TextureUsageFlags usageFlags
) {
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
VulkanTexture *result;
VkImageUsageFlags imageUsageFlags = (
VK_IMAGE_USAGE_SAMPLED_BIT |
VK_IMAGE_USAGE_TRANSFER_DST_BIT |
VK_IMAGE_USAGE_TRANSFER_SRC_BIT
);
if (usageFlags & REFRESH_TEXTUREUSAGE_COLOR_TARGET_BIT)
{
imageUsageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
}
result = (VulkanTexture*) SDL_malloc(sizeof(VulkanTexture));
VULKAN_INTERNAL_CreateTexture(
renderer,
size,
size,
1,
1,
VK_SAMPLE_COUNT_1_BIT,
levelCount,
RefreshToVK_SurfaceFormat[format],
VK_IMAGE_ASPECT_COLOR_BIT,
VK_IMAGE_TILING_OPTIMAL,
VK_IMAGE_TYPE_2D,
imageUsageFlags,
usageFlags,
result
);
result->colorFormat = format;
return (Refresh_Texture*) result; return (Refresh_Texture*) result;
} }