Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SysTexture for SDL_GPU backend #229

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions include/FNA3D_SysRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ typedef struct FNA3D_SysRendererEXT
uint32_t queueFamilyIndex;
} vulkan;
#endif /* FNA3D_DRIVER_VULKAN */
#if FNA3D_DRIVER_SDL
struct
{
// FIXME: This definition is incomplete! -kg
SDL_GPUDevice *device;
// Reserved pointers to create space for things we need to expose later, for compatibility
void *reserved1,
*reserved2,
*reserved3,
*reserved4,
*reserved5,
*reserved6;
} sdl;
#endif
uint8_t filler[64];
} renderer;
} FNA3D_SysRendererEXT;
Expand Down Expand Up @@ -131,6 +145,13 @@ typedef struct FNA3D_SysTextureEXT
FNA3D_VULKAN_HANDLE_TYPE view; /* VkImageView */
} vulkan;
#endif /* FNA3D_DRIVER_VULKAN */
#if FNA3D_DRIVER_SDL
struct
{
void /* SDL_GPUTexture */ *texture;
void /* SDL_GPUTextureCreateInfo */ *createInfo;
} sdl;
#endif
uint8_t filler[64];
} texture;
} FNA3D_SysTextureEXT;
Expand Down
34 changes: 29 additions & 5 deletions src/FNA3D_Driver_SDL.c
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,9 @@ static void SDLGPU_INTERNAL_GenerateVertexInputInfo(
{
element = vertexDeclaration.elements[j];
usage = element.vertexElementUsage;
SDL_assert(usage < MOJOSHADER_USAGE_TOTAL);
index = element.usageIndex;
SDL_assert(index < sizeof(attrUse[usage]));

if (attrUse[usage][index])
{
Expand Down Expand Up @@ -1793,7 +1795,9 @@ static void SDLGPU_VerifyVertexSampler(

if (vertShader)
{
samplerType = MOJOSHADER_sdlGetShaderParseData(vertShader)->samplers[index].type;
MOJOSHADER_parseData *parseData = MOJOSHADER_sdlGetShaderParseData(vertShader);
SDL_assert(parseData);
samplerType = parseData->samplers[index].type;

if (samplerType == MOJOSHADER_SAMPLER_2D)
{
Expand Down Expand Up @@ -1855,7 +1859,9 @@ static void SDLGPU_VerifySampler(

if (fragShader)
{
samplerType = MOJOSHADER_sdlGetShaderParseData(fragShader)->samplers[index].type;
MOJOSHADER_parseData* parseData = MOJOSHADER_sdlGetShaderParseData(fragShader);
SDL_assert(parseData);
samplerType = parseData->samplers[index].type;
if (samplerType == MOJOSHADER_SAMPLER_2D)
{
renderer->fragmentTextureSamplerBindings[index].texture = renderer->dummyTexture2D;
Expand Down Expand Up @@ -3994,17 +4000,35 @@ static void SDLGPU_GetSysRenderer(
FNA3D_Renderer *driverData,
FNA3D_SysRendererEXT *sysrenderer
) {
/* TODO */
SDLGPU_Renderer* renderer = (SDLGPU_Renderer*)driverData;

SDL_memset(sysrenderer, '\0', sizeof(FNA3D_SysRendererEXT));
sysrenderer->rendererType = FNA3D_RENDERER_TYPE_SDL_GPU_EXT;
sysrenderer->renderer.sdl.device = renderer->device;
// FIXME: Expose other necessary pointers. -kg
}

static FNA3D_Texture* SDLGPU_CreateSysTexture(
FNA3D_Renderer *driverData,
FNA3D_SysTextureEXT *systexture
) {
/* TODO */
return NULL;
SDLGPU_TextureHandle* result;

if (systexture->rendererType != FNA3D_RENDERER_TYPE_SDL_GPU_EXT)
{
return NULL;
}

result = (SDLGPU_TextureHandle*)SDL_malloc(sizeof(SDLGPU_TextureHandle));
SDL_zerop(result);

SDL_assert(systexture->texture.sdl.texture);
result->texture = systexture->texture.sdl.texture;
SDL_assert(systexture->texture.sdl.createInfo);
result->createInfo = *(SDL_GPUTextureCreateInfo *)systexture->texture.sdl.createInfo;
result->boundAsRenderTarget = 0;

return (FNA3D_Texture*)result;
}

/* Destroy */
Expand Down
Loading