diff --git a/include/FNA3D_SysRenderer.h b/include/FNA3D_SysRenderer.h index 33566ef2..eb36429b 100644 --- a/include/FNA3D_SysRenderer.h +++ b/include/FNA3D_SysRenderer.h @@ -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; @@ -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; diff --git a/src/FNA3D_Driver_SDL.c b/src/FNA3D_Driver_SDL.c index 16615000..7c8e0cb1 100644 --- a/src/FNA3D_Driver_SDL.c +++ b/src/FNA3D_Driver_SDL.c @@ -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]) { @@ -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) { @@ -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; @@ -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 */