瀏覽代碼

Merge pull request #2064 from jpark37/bgra-swap-chain

D3D swap chain enhancements
Jim 6 年之前
父節點
當前提交
09c7ec487b
共有 5 個文件被更改,包括 38 次插入59 次删除
  1. 1 1
      UI/qt-display.cpp
  2. 36 8
      libobs-d3d11/d3d11-subsystem.cpp
  3. 1 0
      libobs-opengl/gl-windows.c
  4. 0 47
      libobs-opengl/gl-x11.c
  5. 0 3
      libobs/graphics/graphics.c

+ 1 - 1
UI/qt-display.cpp

@@ -86,7 +86,7 @@ void OBSQTDisplay::CreateDisplay()
 	gs_init_data info = {};
 	info.cx = size.width();
 	info.cy = size.height();
-	info.format = GS_RGBA;
+	info.format = GS_BGRA;
 	info.zsformat = GS_ZS_NONE;
 
 	QTToGSWindow(winId(), info.window);

+ 36 - 8
libobs-d3d11/d3d11-subsystem.cpp

@@ -72,18 +72,41 @@ gs_obj::~gs_obj()
 		next->prev_next = prev_next;
 }
 
-static inline void make_swap_desc(DXGI_SWAP_CHAIN_DESC &desc,
-				  const gs_init_data *data)
+static inline void make_swap_desc_common(DXGI_SWAP_CHAIN_DESC &desc,
+					 const gs_init_data *data,
+					 UINT num_backbuffers,
+					 DXGI_SWAP_EFFECT effect)
 {
 	memset(&desc, 0, sizeof(desc));
-	desc.BufferCount = data->num_backbuffers;
-	desc.BufferDesc.Format = ConvertGSTextureFormat(data->format);
 	desc.BufferDesc.Width = data->cx;
 	desc.BufferDesc.Height = data->cy;
+	desc.BufferDesc.Format = ConvertGSTextureFormat(data->format);
+	desc.SampleDesc.Count = 1;
 	desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+	desc.BufferCount = num_backbuffers;
 	desc.OutputWindow = (HWND)data->window.hwnd;
-	desc.SampleDesc.Count = 1;
 	desc.Windowed = true;
+	desc.SwapEffect = effect;
+}
+
+static inline void make_swap_desc_win7(DXGI_SWAP_CHAIN_DESC &desc,
+				       const gs_init_data *data)
+{
+	UINT num_backbuffers = data->num_backbuffers;
+	if (num_backbuffers == 0)
+		num_backbuffers = 1;
+	make_swap_desc_common(desc, data, num_backbuffers,
+			      DXGI_SWAP_EFFECT_DISCARD);
+}
+
+static inline void make_swap_desc_win10(DXGI_SWAP_CHAIN_DESC &desc,
+					const gs_init_data *data)
+{
+	UINT num_backbuffers = data->num_backbuffers;
+	if (num_backbuffers == 0)
+		num_backbuffers = 2;
+	make_swap_desc_common(desc, data, num_backbuffers,
+			      DXGI_SWAP_EFFECT_FLIP_DISCARD);
 }
 
 void gs_swap_chain::InitTarget(uint32_t cx, uint32_t cy)
@@ -168,11 +191,16 @@ gs_swap_chain::gs_swap_chain(gs_device *device, const gs_init_data *data)
 {
 	HRESULT hr;
 
-	make_swap_desc(swapDesc, data);
+	make_swap_desc_win10(swapDesc, data);
 	hr = device->factory->CreateSwapChain(device->device, &swapDesc,
 					      swap.Assign());
-	if (FAILED(hr))
-		throw HRError("Failed to create swap chain", hr);
+	if (FAILED(hr)) {
+		make_swap_desc_win7(swapDesc, data);
+		hr = device->factory->CreateSwapChain(device->device, &swapDesc,
+						      swap.Assign());
+		if (FAILED(hr))
+			throw HRError("Failed to create swap chain", hr);
+	}
 
 	/* Ignore Alt+Enter */
 	device->factory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER);

+ 1 - 0
libobs-opengl/gl-windows.c

@@ -41,6 +41,7 @@ static inline int get_color_format_bits(enum gs_color_format format)
 {
 	switch ((uint32_t)format) {
 	case GS_RGBA:
+	case GS_BGRA:
 		return 32;
 	default:
 		return 0;

+ 0 - 47
libobs-opengl/gl-x11.c

@@ -95,53 +95,6 @@ struct gl_platform {
 	GLXPbuffer pbuffer;
 };
 
-static void print_info_stuff(const struct gs_init_data *info)
-{
-	blog(LOG_INFO,
-	     "X and Y: %i %i\n"
-	     "Backbuffers: %i\n"
-	     "Color Format: %i\n"
-	     "ZStencil Format: %i\n"
-	     "Adapter: %i\n",
-	     info->cx, info->cy, info->num_backbuffers, info->format,
-	     info->zsformat, info->adapter);
-}
-/* The following utility functions are copied verbatim from WGL code.
- * GLX and WGL are more similar than most people realize. */
-
-/* For now, only support basic 32bit formats for graphics output. */
-static inline int get_color_format_bits(enum gs_color_format format)
-{
-	switch ((uint32_t)format) {
-	case GS_RGBA:
-		return 32;
-	default:
-		return 0;
-	}
-}
-
-static inline int get_depth_format_bits(enum gs_zstencil_format zsformat)
-{
-	switch ((uint32_t)zsformat) {
-	case GS_Z16:
-		return 16;
-	case GS_Z24_S8:
-		return 24;
-	default:
-		return 0;
-	}
-}
-
-static inline int get_stencil_format_bits(enum gs_zstencil_format zsformat)
-{
-	switch ((uint32_t)zsformat) {
-	case GS_Z24_S8:
-		return 8;
-	default:
-		return 0;
-	}
-}
-
 /*
  * Since we cannot take advantage of the asynchronous nature of xcb,
  * all of the helper functions are synchronous but thread-safe.

+ 0 - 3
libobs/graphics/graphics.c

@@ -1272,9 +1272,6 @@ gs_swapchain_t *gs_swapchain_create(const struct gs_init_data *data)
 	if (!gs_valid_p("gs_swapchain_create", data))
 		return NULL;
 
-	if (new_data.num_backbuffers == 0)
-		new_data.num_backbuffers = 1;
-
 	return graphics->exports.device_swapchain_create(graphics->device,
 							 &new_data);
 }