Added SDL_RenderGetMetalLayer() and SDL_RenderGetMetalCommandEncoder()
authorSam Lantinga <slouken@libsdl.org>
Fri, 08 Dec 2017 14:30:10 -0800
changeset 117444d97d8cdaa90
parent 11743 3af68ade4d30
child 11745 bb8a8a1996d1
Added SDL_RenderGetMetalLayer() and SDL_RenderGetMetalCommandEncoder()
include/SDL_render.h
src/dynapi/SDL_dynapi_overrides.h
src/dynapi/SDL_dynapi_procs.h
src/render/SDL_render.c
src/render/SDL_sysrender.h
src/render/metal/SDL_render_metal.m
     1.1 --- a/include/SDL_render.h	Fri Dec 08 13:20:20 2017 -0800
     1.2 +++ b/include/SDL_render.h	Fri Dec 08 14:30:10 2017 -0800
     1.3 @@ -898,6 +898,27 @@
     1.4   */
     1.5  extern DECLSPEC int SDLCALL SDL_GL_UnbindTexture(SDL_Texture *texture);
     1.6  
     1.7 +/**
     1.8 + *  \brief Get the CAMetalLayer associated with the given Metal renderer
     1.9 + *
    1.10 + *  \param renderer The renderer to query
    1.11 + *
    1.12 + *  \return CAMetalLayer* on success, or NULL if the renderer isn't a Metal renderer
    1.13 + *
    1.14 + *  \sa SDL_RenderGetMetalCommandEncoder()
    1.15 + */
    1.16 +extern DECLSPEC void *SDLCALL SDL_RenderGetMetalLayer(SDL_Renderer * renderer);
    1.17 +
    1.18 +/**
    1.19 + *  \brief Get the Metal command encoder for the current frame
    1.20 + *
    1.21 + *  \param renderer The renderer to query
    1.22 + *
    1.23 + *  \return id<MTLRenderCommandEncoder> on success, or NULL if the renderer isn't a Metal renderer
    1.24 + *
    1.25 + *  \sa SDL_RenderGetMetalLayer()
    1.26 + */
    1.27 +extern DECLSPEC void *SDLCALL SDL_RenderGetMetalCommandEncoder(SDL_Renderer * renderer);
    1.28  
    1.29  /* Ends C function definitions when using C++ */
    1.30  #ifdef __cplusplus
     2.1 --- a/src/dynapi/SDL_dynapi_overrides.h	Fri Dec 08 13:20:20 2017 -0800
     2.2 +++ b/src/dynapi/SDL_dynapi_overrides.h	Fri Dec 08 14:30:10 2017 -0800
     2.3 @@ -663,3 +663,5 @@
     2.4  #define SDL_SetYUVConversionMode SDL_SetYUVConversionMode_REAL
     2.5  #define SDL_GetYUVConversionMode SDL_GetYUVConversionMode_REAL
     2.6  #define SDL_GetYUVConversionModeForResolution SDL_GetYUVConversionModeForResolution_REAL
     2.7 +#define SDL_RenderGetMetalLayer SDL_RenderGetMetalLayer_REAL
     2.8 +#define SDL_RenderGetMetalCommandEncoder SDL_RenderGetMetalCommandEncoder_REAL
     3.1 --- a/src/dynapi/SDL_dynapi_procs.h	Fri Dec 08 13:20:20 2017 -0800
     3.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Fri Dec 08 14:30:10 2017 -0800
     3.3 @@ -697,3 +697,5 @@
     3.4  SDL_DYNAPI_PROC(void,SDL_SetYUVConversionMode,(SDL_YUV_CONVERSION_MODE a),(a),)
     3.5  SDL_DYNAPI_PROC(SDL_YUV_CONVERSION_MODE,SDL_GetYUVConversionMode,(void),(),return)
     3.6  SDL_DYNAPI_PROC(SDL_YUV_CONVERSION_MODE,SDL_GetYUVConversionModeForResolution,(int a, int b),(a,b),return)
     3.7 +SDL_DYNAPI_PROC(void*,SDL_RenderGetMetalLayer,(SDL_Renderer *a),(a),return)
     3.8 +SDL_DYNAPI_PROC(void*,SDL_RenderGetMetalCommandEncoder,(SDL_Renderer *a),(a),return)
     4.1 --- a/src/render/SDL_render.c	Fri Dec 08 13:20:20 2017 -0800
     4.2 +++ b/src/render/SDL_render.c	Fri Dec 08 14:30:10 2017 -0800
     4.3 @@ -2123,6 +2123,28 @@
     4.4      return SDL_Unsupported();
     4.5  }
     4.6  
     4.7 +void *
     4.8 +SDL_RenderGetMetalLayer(SDL_Renderer * renderer)
     4.9 +{
    4.10 +    CHECK_RENDERER_MAGIC(renderer, NULL);
    4.11 +
    4.12 +    if (renderer->GetMetalLayer) {
    4.13 +        return renderer->GetMetalLayer(renderer);
    4.14 +    }
    4.15 +    return NULL;
    4.16 +}
    4.17 +
    4.18 +void *
    4.19 +SDL_RenderGetMetalCommandEncoder(SDL_Renderer * renderer)
    4.20 +{
    4.21 +    CHECK_RENDERER_MAGIC(renderer, NULL);
    4.22 +
    4.23 +    if (renderer->GetMetalCommandEncoder) {
    4.24 +        return renderer->GetMetalCommandEncoder(renderer);
    4.25 +    }
    4.26 +    return NULL;
    4.27 +}
    4.28 +
    4.29  static SDL_BlendMode
    4.30  SDL_GetShortBlendMode(SDL_BlendMode blendMode)
    4.31  {
     5.1 --- a/src/render/SDL_sysrender.h	Fri Dec 08 13:20:20 2017 -0800
     5.2 +++ b/src/render/SDL_sysrender.h	Fri Dec 08 14:30:10 2017 -0800
     5.3 @@ -123,6 +123,9 @@
     5.4      int (*GL_BindTexture) (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh);
     5.5      int (*GL_UnbindTexture) (SDL_Renderer * renderer, SDL_Texture *texture);
     5.6  
     5.7 +    void *(*GetMetalLayer) (SDL_Renderer * renderer);
     5.8 +    void *(*GetMetalCommandEncoder) (SDL_Renderer * renderer);
     5.9 +
    5.10      /* The current renderer info */
    5.11      SDL_RendererInfo info;
    5.12  
     6.1 --- a/src/render/metal/SDL_render_metal.m	Fri Dec 08 13:20:20 2017 -0800
     6.2 +++ b/src/render/metal/SDL_render_metal.m	Fri Dec 08 14:30:10 2017 -0800
     6.3 @@ -81,6 +81,8 @@
     6.4  static void METAL_RenderPresent(SDL_Renderer * renderer);
     6.5  static void METAL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
     6.6  static void METAL_DestroyRenderer(SDL_Renderer * renderer);
     6.7 +static void *METAL_GetMetalLayer(SDL_Renderer * renderer);
     6.8 +static void *METAL_GetMetalCommandEncoder(SDL_Renderer * renderer);
     6.9  
    6.10  SDL_RenderDriver METAL_RenderDriver = {
    6.11      METAL_CreateRenderer,
    6.12 @@ -328,6 +330,8 @@
    6.13      renderer->RenderPresent = METAL_RenderPresent;
    6.14      renderer->DestroyTexture = METAL_DestroyTexture;
    6.15      renderer->DestroyRenderer = METAL_DestroyRenderer;
    6.16 +    renderer->GetMetalLayer = METAL_GetMetalLayer;
    6.17 +    renderer->GetMetalCommandEncoder = METAL_GetMetalCommandEncoder;
    6.18  
    6.19      renderer->info = METAL_RenderDriver.info;
    6.20      renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
    6.21 @@ -786,6 +790,19 @@
    6.22      SDL_free(renderer);
    6.23  }}
    6.24  
    6.25 +void *METAL_GetMetalLayer(SDL_Renderer * renderer)
    6.26 +{ @autoreleasepool {
    6.27 +    METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
    6.28 +    return (__bridge void*)data.mtllayer;
    6.29 +}}
    6.30 +
    6.31 +void *METAL_GetMetalCommandEncoder(SDL_Renderer * renderer)
    6.32 +{ @autoreleasepool {
    6.33 +    METAL_ActivateRenderer(renderer);
    6.34 +    METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
    6.35 +    return (__bridge void*)data.mtlcmdencoder;
    6.36 +}}
    6.37 +
    6.38  #endif /* SDL_VIDEO_RENDER_METAL && !SDL_RENDER_DISABLED */
    6.39  
    6.40  /* vi: set ts=4 sw=4 expandtab: */