瀏覽代碼

Added SDL_PROP_TEXTURE_GPU_TEXTURE_POINTER

Sam Lantinga 6 天之前
父節點
當前提交
a4b180f515
共有 2 個文件被更改,包括 9 次插入1 次删除
  1. 6 0
      include/SDL3/SDL_render.h
  2. 3 1
      src/render/gpu/SDL_render_gpu.c

+ 6 - 0
include/SDL3/SDL_render.h

@@ -856,6 +856,11 @@ extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureWithProperties(SDL_Re
  * - `SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_TARGET_NUMBER`: the GLenum for the
  *   texture target (`GL_TEXTURE_2D`, `GL_TEXTURE_EXTERNAL_OES`, etc)
  *
+ * With the gpu renderer:
+ *
+ * - `SDL_PROP_TEXTURE_GPU_TEXTURE_POINTER`: the SDL_GPUTexture associated with
+ *   the texture
+ *
  * \param texture the texture to query.
  * \returns a valid property ID on success or 0 on failure; call
  *          SDL_GetError() for more information.
@@ -892,6 +897,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetTextureProperties(SDL_Textur
 #define SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_V_NUMBER         "SDL.texture.opengles2.texture_v"
 #define SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_TARGET_NUMBER    "SDL.texture.opengles2.target"
 #define SDL_PROP_TEXTURE_VULKAN_TEXTURE_NUMBER              "SDL.texture.vulkan.texture"
+#define SDL_PROP_TEXTURE_GPU_TEXTURE_POINTER                "SDL.texture.gpu.texture"
 
 /**
  * Get the renderer that created an SDL_Texture.

+ 3 - 1
src/render/gpu/SDL_render_gpu.c

@@ -233,11 +233,13 @@ static bool GPU_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_
 
     data->format = format;
     data->texture = SDL_CreateGPUTexture(renderdata->device, &tci);
-
     if (!data->texture) {
         return false;
     }
 
+    SDL_PropertiesID props = SDL_GetTextureProperties(texture);
+    SDL_SetPointerProperty(props, SDL_PROP_TEXTURE_GPU_TEXTURE_POINTER, data->texture);
+
     if (texture->format == SDL_PIXELFORMAT_RGBA32 || texture->format == SDL_PIXELFORMAT_BGRA32) {
         data->shader = FRAG_SHADER_TEXTURE_RGBA;
     } else {