From 89a5bdbcf1b8de05fa27302a78ea3037b6ec0426 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sun, 20 Jul 2014 16:19:43 -0700 Subject: [PATCH] Add gs_device_type function This allows a programatic way of determining the type of graphics module currently active. --- libobs-d3d11/d3d11-subsystem.cpp | 5 +++++ libobs-opengl/gl-subsystem.c | 5 +++++ libobs/graphics/device-exports.h | 1 + libobs/graphics/graphics-imports.c | 1 + libobs/graphics/graphics-internal.h | 1 + libobs/graphics/graphics.c | 5 +++++ libobs/graphics/graphics.h | 4 ++++ 7 files changed, 22 insertions(+) diff --git a/libobs-d3d11/d3d11-subsystem.cpp b/libobs-d3d11/d3d11-subsystem.cpp index c0ac9758e..b4b19f4c8 100644 --- a/libobs-d3d11/d3d11-subsystem.cpp +++ b/libobs-d3d11/d3d11-subsystem.cpp @@ -423,6 +423,11 @@ const char *device_name(void) return "Direct3D 11"; } +int device_type(void) +{ + return GS_DEVICE_DIRECT3D_11; +} + const char *device_preprocessor_name(void) { return "_D3D11"; diff --git a/libobs-opengl/gl-subsystem.c b/libobs-opengl/gl-subsystem.c index cf35a8d62..84f0e989e 100644 --- a/libobs-opengl/gl-subsystem.c +++ b/libobs-opengl/gl-subsystem.c @@ -187,6 +187,11 @@ const char *device_name(void) return "OpenGL"; } +int device_type(void) +{ + return GS_DEVICE_OPENGL; +} + const char *device_preprocessor_name(void) { return "_OPENGL"; diff --git a/libobs/graphics/device-exports.h b/libobs/graphics/device-exports.h index 3c961876d..50eb67979 100644 --- a/libobs/graphics/device-exports.h +++ b/libobs/graphics/device-exports.h @@ -24,6 +24,7 @@ extern "C" { #endif EXPORT const char *device_name(void); +EXPORT int device_type(void); EXPORT const char *device_preprocessor_name(void); EXPORT device_t device_create(struct gs_init_data *data); EXPORT void device_destroy(device_t device); diff --git a/libobs/graphics/graphics-imports.c b/libobs/graphics/graphics-imports.c index 1215341e8..281a62a20 100644 --- a/libobs/graphics/graphics-imports.c +++ b/libobs/graphics/graphics-imports.c @@ -41,6 +41,7 @@ bool load_graphics_imports(struct gs_exports *exports, void *module, bool success = true; GRAPHICS_IMPORT(device_name); + GRAPHICS_IMPORT(device_type); GRAPHICS_IMPORT(device_preprocessor_name); GRAPHICS_IMPORT(device_create); GRAPHICS_IMPORT(device_destroy); diff --git a/libobs/graphics/graphics-internal.h b/libobs/graphics/graphics-internal.h index 758abcb0a..626d45353 100644 --- a/libobs/graphics/graphics-internal.h +++ b/libobs/graphics/graphics-internal.h @@ -25,6 +25,7 @@ struct gs_exports { const char *(*device_name)(void); + int (*device_type)(void); const char *(*device_preprocessor_name)(void); device_t (*device_create)(struct gs_init_data *data); void (*device_destroy)(device_t device); diff --git a/libobs/graphics/graphics.c b/libobs/graphics/graphics.c index 13b54289e..2849c73b4 100644 --- a/libobs/graphics/graphics.c +++ b/libobs/graphics/graphics.c @@ -220,6 +220,11 @@ const char *gs_device_name(void) return thread_graphics ? thread_graphics->exports.device_name() : NULL; } +int gs_device_type(void) +{ + return thread_graphics ? thread_graphics->exports.device_type() : -1; +} + static inline struct matrix4 *top_matrix(graphics_t graphics) { return graphics ? diff --git a/libobs/graphics/graphics.h b/libobs/graphics/graphics.h index 640e69373..6ff4fe2ff 100644 --- a/libobs/graphics/graphics.h +++ b/libobs/graphics/graphics.h @@ -416,7 +416,11 @@ struct gs_init_data { uint32_t adapter; }; +#define GS_DEVICE_OPENGL 1 +#define GS_DEVICE_DIRECT3D_11 2 + EXPORT const char *gs_device_name(void); +EXPORT int gs_device_type(void); EXPORT int gs_create(graphics_t *graphics, const char *module, struct gs_init_data *data);