[Bf-blender-cvs] [bd99046] decklink: Player: new -a option to enable alpha on frame buffer.

Benoit Bolsee noreply at git.blender.org
Thu Apr 9 09:59:12 CEST 2015


Commit: bd9904615bae8bf0002d3268d0004be72f0d5922
Author: Benoit Bolsee
Date:   Thu Apr 9 09:41:52 2015 +0200
Branches: decklink
https://developer.blender.org/rBbd9904615bae8bf0002d3268d0004be72f0d5922

Player: new -a option to enable alpha on frame buffer.

A new option '-a' can be passed to the blenderplayer. It forces the
framebuffer to have an alpha channel. As the background color is applied
with 0 alpha, ImageViewport will return an image with transparent
background (provided alpha is set to True on the ImageViewport object).
This is useful in combination with DeckLink to generate a key frame
with transparent background.
Without the -a option, the frame buffer has no alpha channel and
ImageViewport always returns an opaque image, no matter what.
This should be working in Windows and Linux, but only Windows is tested at
present.
Note that although the frame buffer has alpha, the player window is still
rendered opaque. Transparency of the window is possible using the
'compositing' functions of Windows and the code is already there for that
(look for WIN32_COMPOSITING) but is not enabled because 1) it doesn't work
so well 2) it requires a DLL that is only available on Vista and up.

===================================================================

M	CMakeLists.txt
M	intern/ghost/CMakeLists.txt
M	intern/ghost/GHOST_ISystem.h
M	intern/ghost/GHOST_Types.h
M	intern/ghost/intern/GHOST_ContextGLX.cpp
M	intern/ghost/intern/GHOST_ContextGLX.h
M	intern/ghost/intern/GHOST_ContextWGL.cpp
M	intern/ghost/intern/GHOST_ContextWGL.h
M	intern/ghost/intern/GHOST_System.cpp
M	intern/ghost/intern/GHOST_System.h
M	intern/ghost/intern/GHOST_SystemWin32.cpp
M	intern/ghost/intern/GHOST_SystemX11.cpp
M	intern/ghost/intern/GHOST_WindowWin32.cpp
M	intern/ghost/intern/GHOST_WindowWin32.h
M	intern/ghost/intern/GHOST_WindowX11.cpp
M	intern/ghost/intern/GHOST_WindowX11.h
M	source/gameengine/GamePlayer/ghost/GPG_Application.cpp
M	source/gameengine/GamePlayer/ghost/GPG_Application.h
M	source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
M	source/gameengine/Ketsji/KX_KetsjiEngine.cpp
M	source/gameengine/Ketsji/KX_KetsjiEngine.h
M	source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d0a9b7f..8d9d8f5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -247,6 +247,7 @@ option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)"
 if(WITH_X11)
 	option(WITH_X11_XINPUT    "Enable X11 Xinput (tablet support and unicode input)"  ON)
 	option(WITH_X11_XF86VMODE "Enable X11 video mode switching"                       ON)
+	option(WITH_X11_ALPHA     "Enable X11 transparent background"                     ON)
 endif()
 
 if(UNIX AND NOT APPLE)
@@ -674,6 +675,7 @@ if(WITH_GHOST_SDL OR WITH_HEADLESS)
 	set(WITH_X11           OFF)
 	set(WITH_X11_XINPUT    OFF)
 	set(WITH_X11_XF86VMODE OFF)
+	set(WITH_X11_ALPHA     OFF)
 	set(WITH_GHOST_XDND    OFF)
 	set(WITH_INPUT_IME     OFF)
 endif()
@@ -790,6 +792,16 @@ if(WITH_X11)
 		endif()
 	endif()
 
+	if(WITH_X11_ALPHA)
+		find_library(X11_Xrender_LIB Xrender  ${X11_LIB_SEARCH_PATH})
+		mark_as_advanced(X11_Xrender_LIB)
+		if (X11_Xrender_LIB)
+			list(APPEND PLATFORM_LINKLIBS ${X11_Xrender_LIB})
+		else()
+			set(WITH_X11_ALPHA OFF)
+		endif()
+	endif()
+
 endif()
 
 if(UNIX AND NOT APPLE)
@@ -2836,6 +2848,7 @@ if(FIRST_RUN)
 
 	info_cfg_text("System Options:")
 	info_cfg_option(WITH_INSTALL_PORTABLE)
+	info_cfg_option(WITH_X11_ALPHA)
 	info_cfg_option(WITH_X11_XF86VMODE)
 	info_cfg_option(WITH_X11_XINPUT)
 	info_cfg_option(WITH_MEM_JEMALLOC)
diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt
index 761bcb4..e709459 100644
--- a/intern/ghost/CMakeLists.txt
+++ b/intern/ghost/CMakeLists.txt
@@ -228,6 +228,10 @@ elseif(WITH_X11)
 		)
 	endif()
 
+	if(WITH_X11_ALPHA)
+		add_definitions(-DWITH_X11_ALPHA)
+	endif()
+
 	if(WITH_INPUT_NDOF)
 		list(APPEND SRC
 			intern/GHOST_NDOFManagerX11.cpp
diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h
index 93ccc0f..3aaab74 100644
--- a/intern/ghost/GHOST_ISystem.h
+++ b/intern/ghost/GHOST_ISystem.h
@@ -1,5 +1,4 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
+/* ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -241,8 +240,9 @@ public:
 	 * \param   height          The height the window.
 	 * \param   state           The state of the window when opened.
 	 * \param   type            The type of drawing context installed in this window.
-	 * \param   stereoVisual    Create a stereo visual for quad buffered stereo.
-	 * \param   numOfAASamples  Number of samples used for AA (zero if no AA)
+	 * \param   stereoVisual    (in glSettings) Create a stereo visual for quad buffered stereo.
+	 * \param   alphaBackground (in glSettings) Enable transparency of the window with the display background
+	 * \param   numOfAASamples  (in glSettings) Number of samples used for AA (zero if no AA)
 	 * \param   parentWindow    Parent (embedder) window
 	 * \return  The new window (or 0 if creation failed).
 	 */
@@ -277,7 +277,7 @@ public:
 	 */
 	virtual GHOST_TSuccess beginFullScreen(
 	        const GHOST_DisplaySetting& setting, GHOST_IWindow **window,
-	        const bool stereoVisual, const GHOST_TUns16 numOfAASamples = 0) = 0;
+	        const bool stereoVisual, const bool alphaBackground = 0, const GHOST_TUns16 numOfAASamples = 0) = 0;
 
 	/**
 	 * Updates the resolution while in fullscreen mode.
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index eccbaad..b93949d 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -57,7 +57,8 @@ typedef struct {
 
 typedef enum {
 	GHOST_glStereoVisual = (1 << 0),
-	GHOST_glWarnSupport  = (1 << 1)
+	GHOST_glWarnSupport  = (1 << 1),
+	GHOST_glAlphaBackground = (1 << 2),
 } GHOST_GLFlags;
 
 
diff --git a/intern/ghost/intern/GHOST_ContextGLX.cpp b/intern/ghost/intern/GHOST_ContextGLX.cpp
index c4e1346..5adac99 100644
--- a/intern/ghost/intern/GHOST_ContextGLX.cpp
+++ b/intern/ghost/intern/GHOST_ContextGLX.cpp
@@ -39,6 +39,7 @@
 #include <cassert>
 #include <cstdio>
 #include <cstring>
+#include <iostream>
 
 
 #ifdef WITH_GLEW_MX
@@ -55,6 +56,7 @@ GHOST_ContextGLX::GHOST_ContextGLX(
         Window window,
         Display *display,
         XVisualInfo *visualInfo,
+        GLXFBConfig fbconfig,
         int contextProfileMask,
         int contextMajorVersion,
         int contextMinorVersion,
@@ -63,6 +65,7 @@ GHOST_ContextGLX::GHOST_ContextGLX(
     : GHOST_Context(stereoVisual, numOfAASamples),
       m_display(display),
       m_visualInfo(visualInfo),
+      m_fbconfig(fbconfig),
       m_window(window),
       m_contextProfileMask(contextProfileMask),
       m_contextMajorVersion(contextMajorVersion),
@@ -152,7 +155,25 @@ GHOST_TSuccess GHOST_ContextGLX::initializeDrawingContext()
 	XIOErrorHandler old_handler_io = XSetIOErrorHandler(GHOST_X11_ApplicationIOErrorHandler);
 #endif
 
-	m_context = glXCreateContext(m_display, m_visualInfo, s_sharedContext, True);
+
+#ifdef WITH_X11_ALPHA
+	if(m_fbconfig
+	   && (glXCreateContextAttribsARB ||
+		   (glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddressARB((const GLubyte *)"glXCreateContextAttribsARB")) != NULL)
+	   ) {
+		std::cout << "Detected GLXEW_ARB_create_context" << std::endl;
+		int context_attribs[] =
+		{
+			GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
+			GLX_CONTEXT_MINOR_VERSION_ARB, 0,
+			//GLX_CONTEXT_FLAGS_ARB        , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
+			None
+		};
+		m_context = glXCreateContextAttribsARB( m_display, m_fbconfig, 0, True, context_attribs );
+	}
+#endif
+	if (!m_context)
+		m_context = glXCreateContext(m_display, m_visualInfo, s_sharedContext, True);
 
 	GHOST_TSuccess success;
 
diff --git a/intern/ghost/intern/GHOST_ContextGLX.h b/intern/ghost/intern/GHOST_ContextGLX.h
index b33c0b5..4e2ff51 100644
--- a/intern/ghost/intern/GHOST_ContextGLX.h
+++ b/intern/ghost/intern/GHOST_ContextGLX.h
@@ -70,6 +70,7 @@ public:
 	        Window window,
 	        Display *display,
 	        XVisualInfo *visualInfo,
+	        GLXFBConfig fbconfig,
 	        int contextProfileMask,
 	        int contextMajorVersion,
 	        int contextMinorVersion,
@@ -132,6 +133,7 @@ private:
 
 	Display *m_display;
 	XVisualInfo *m_visualInfo;
+	GLXFBConfig m_fbconfig;
 	Window   m_window;
 
 	const int m_contextProfileMask;
diff --git a/intern/ghost/intern/GHOST_ContextWGL.cpp b/intern/ghost/intern/GHOST_ContextWGL.cpp
index 4f4cab7..c5a3cf8 100644
--- a/intern/ghost/intern/GHOST_ContextWGL.cpp
+++ b/intern/ghost/intern/GHOST_ContextWGL.cpp
@@ -64,6 +64,7 @@ static bool is_crappy_intel_card()
 
 GHOST_ContextWGL::GHOST_ContextWGL(
         bool stereoVisual,
+		bool alphaBackground,
         GHOST_TUns16 numOfAASamples,
         HWND hWnd,
         HDC hDC,
@@ -79,6 +80,7 @@ GHOST_ContextWGL::GHOST_ContextWGL(
       m_contextMajorVersion(contextMajorVersion),
       m_contextMinorVersion(contextMinorVersion),
       m_contextFlags(contextFlags),
+	  m_alphaBackground(alphaBackground),
       m_contextResetNotificationStrategy(contextResetNotificationStrategy),
       m_hGLRC(NULL)
 #ifdef WITH_GLEW_MX
@@ -169,7 +171,7 @@ GHOST_TSuccess GHOST_ContextWGL::activateDrawingContext()
 /* Ron Fosner's code for weighting pixel formats and forcing software.
  * See http://www.opengl.org/resources/faq/technical/weight.cpp
  */
-static int weight_pixel_format(PIXELFORMATDESCRIPTOR &pfd)
+static int weight_pixel_format(PIXELFORMATDESCRIPTOR &pfd, PIXELFORMATDESCRIPTOR &preferredPFD)
 {
 	int weight = 0;
 
@@ -195,11 +197,12 @@ static int weight_pixel_format(PIXELFORMATDESCRIPTOR &pfd)
 
 	weight += pfd.cColorBits -  8;
 
-#ifdef GHOST_OPENGL_ALPHA
-	if (pfd.cAlphaBits > 0)
+	if (preferredPFD.cAlphaBits > 0 && pfd.cAlphaBits > 0)
+		weight++;
+#ifdef WIN32_COMPOSITING
+	if ((preferredPFD.dwFlags & PFD_SUPPORT_COMPOSITION) && (pfd.dwFlags & PFD_SUPPORT_COMPOSITION))
 		weight++;
 #endif
-
 #ifdef GHOST_OPENGL_STENCIL
 	if (pfd.cStencilBits >= 8)
 		weight++;
@@ -240,7 +243,7 @@ static int choose_pixel_format_legacy(HDC hDC, PIXELFORMATDESCRIPTOR &preferredP
 
 		WIN32_CHK(check == lastPFD);
 
-		int w = weight_pixel_format(pfd);
+		int w = weight_pixel_format(pfd, preferredPFD);
 
 		if (w > weight) {
 			weight = w;
@@ -497,7 +500,10 @@ int GHOST_ContextWGL::_choose_pixel_format_arb_2(
 {
 	std::vector<int> iAttributes;
 
+#define _MAX_PIXEL_FORMATS 32
+
 	int iPixelFormat = 0;
+	int iPixelFormats[_MAX_PIXEL_FORMATS];
 
 	int samples;
 
@@ -522,8 +528,31 @@ int GHOST_ContextWGL::_choose_pixel_format_arb_2(
 		        sRGB);
 
 		UINT nNumFormats;
-		WIN32_CHK(wglChoosePixelFormatARB(m_hDC, &(iAttributes[0]), NULL, 1, &iPixelFormat, &nNumFormats));
-
+		WIN32_CHK(wglChoosePixelFormatARB(m_hDC, &(iAttributes[0]), NULL, _MAX_PIXEL_FORMATS, iPixelFormats, &nNumFormats));
+
+#ifdef WIN32_COMPOSITING
+		if (needAlpha && nNumFormats) {
+			// scan through all pixel format to make sure one supports compositing
+			PIXELFORMATDESCRIPTOR pfd;
+			int i;
+
+			for (i = 0; i < nNumFormats; i++) {
+				if (DescribePixelFormat(m_hDC, iPixelFormats[i], sizeof(PIXELFORMATDESCRIPTOR), &pfd)) {
+					if (pfd.dwFlags & PFD_SUPPORT_COMPOSITION) {
+						iPixelFormat = iPixelFormats[i];
+						break;
+					}
+				}
+			}
+			if (i == nNumFormats) {
+				fprintf(stderr,
+						"Warning! Unable to find a pixel format with compositing capability.\n");
+				iPixelFormat = iPixelFormats[0];
+			}
+		}
+		else
+#endif
+			iPixelFormat = iPixelFormats[0];
 		/* total number of formats that match (regardless of size of iPixelFormat array)
 		 * see: WGL_ARB_pixel_format extension spec */
 		if (nNumFormats > 0)
@@ -539,7 +568,7 @@ int GHOST_ContextWGL::_choose_pixel_format_arb_2(
 	// check how many samples were actually gotten
 	if (iPixelFormat != 0) {
 		int iQuery[] = { WGL_SAMPLES_ARB };
-		int actualSamples;
+		int actualSamples, alphaBits;
 		wglGetPixelFormatAttribivARB(m_hDC, iPixelFormat, 0, 1, iQuery, &actualSamples);
 
 		if (actualSamples != numOfAASamples) {
@@ -550,6 +579,14 @@ int GHOST_ContextWGL::_choose_pixel_format_arb_2(
 
 			m_numOfAASamples = actualSamples; // set context property to actual value
 		}
+		if (needAlpha) {
+			iQuery[0] = WGL_ALPHA_BITS_ARB;
+			wglGetPixelFormatAttribivARB(m_hDC

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list