Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'intern/ghost/intern/GHOST_ContextWGL.cpp')
-rw-r--r--intern/ghost/intern/GHOST_ContextWGL.cpp69
1 files changed, 54 insertions, 15 deletions
diff --git a/intern/ghost/intern/GHOST_ContextWGL.cpp b/intern/ghost/intern/GHOST_ContextWGL.cpp
index cb580f60bd7..eeb6a2469ee 100644
--- a/intern/ghost/intern/GHOST_ContextWGL.cpp
+++ b/intern/ghost/intern/GHOST_ContextWGL.cpp
@@ -63,6 +63,7 @@ static bool is_crappy_intel_card()
GHOST_ContextWGL::GHOST_ContextWGL(
bool stereoVisual,
+ bool alphaBackground,
GHOST_TUns16 numOfAASamples,
HWND hWnd,
HDC hDC,
@@ -78,6 +79,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
@@ -168,7 +170,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;
@@ -194,11 +196,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++;
@@ -239,7 +242,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;
@@ -496,7 +499,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;
@@ -521,8 +527,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)
@@ -538,7 +567,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) {
@@ -549,6 +578,14 @@ int GHOST_ContextWGL::_choose_pixel_format_arb_2(
*numOfAASamples = actualSamples; // set context property to actual value
}
+ if (needAlpha) {
+ iQuery[0] = WGL_ALPHA_BITS_ARB;
+ wglGetPixelFormatAttribivARB(m_hDC, iPixelFormat, 0, 1, iQuery, &alphaBits);
+ if (alphaBits == 0) {
+ fprintf(stderr,
+ "Warning! Unable to find a frame buffer with alpha channel.\n");
+ }
+ }
}
else {
*numOfAASamples = 0;
@@ -674,9 +711,15 @@ int GHOST_ContextWGL::choose_pixel_format(
PFD_DRAW_TO_WINDOW |
PFD_SWAP_COPY | /* support swap copy */
PFD_DOUBLEBUFFER | /* support double-buffering */
- (stereoVisual ? PFD_STEREO : 0), /* support stereo */
+ (stereoVisual ? PFD_STEREO : 0) |/* support stereo */
+ (
+#ifdef WIN32_COMPOSITING
+ needAlpha ? PFD_SUPPORT_COMPOSITION : /* support composition for transparent background */
+#endif
+ 0
+ ),
PFD_TYPE_RGBA, /* color type */
- 24, /* preferred color depth */
+ (needAlpha ? 32 : 24), /* preferred color depth */
0, 0, 0, 0, 0, 0, /* color bits (ignored) */
needAlpha ? 8 : 0, /* alpha buffer */
0, /* alpha shift (ignored) */
@@ -727,11 +770,7 @@ static void reportContextString(const char *name, const char *dummy, const char
GHOST_TSuccess GHOST_ContextWGL::initializeDrawingContext()
{
-#ifdef GHOST_OPENGL_ALPHA
- const bool needAlpha = true;
-#else
- const bool needAlpha = false;
-#endif
+ const bool needAlpha = m_alphaBackground;
#ifdef GHOST_OPENGL_STENCIL
const bool needStencil = true;