180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2011 Google Inc. 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkRefCnt.h" 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef SkWGL_DEFINED 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SkWGL_DEFINED 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/** 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Working with WGL extensions can be a pain. Among the reasons is that You must 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * have a GL context to get the proc addresses, but you want to use the procs to 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * create a context in the first place. So you have to create a dummy GL ctx to 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * get the proc addresses. 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * This file helps by providing SkCreateWGLInterface(). It returns a struct of 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * function pointers that it initializes. It also has a helper function to query 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * for WGL extensions. It handles the fact that wglGetExtensionsString is itself 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * an extension. 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if !defined(WIN32_LEAN_AND_MEAN) 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru #define WIN32_LEAN_AND_MEAN 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru #define SK_LOCAL_LEAN_AND_MEAN 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 30910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger#include <windows.h> 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if defined(SK_LOCAL_LEAN_AND_MEAN) 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru #undef WIN32_LEAN_AND_MEAN 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru #undef SK_LOCAL_LEAN_AND_MEAN 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_DRAW_TO_WINDOW 0x2001 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_ACCELERATION 0x2003 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_SUPPORT_OPENGL 0x2010 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_DOUBLE_BUFFER 0x2011 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_COLOR_BITS 0x2014 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_ALPHA_BITS 0x201B 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_STENCIL_BITS 0x2023 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_FULL_ACCELERATION 0x2027 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_SAMPLE_BUFFERS 0x2041 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_SAMPLES 0x2042 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_CONTEXT_MAJOR_VERSION 0x2091 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_CONTEXT_MINOR_VERSION 0x2092 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_CONTEXT_LAYER_PLANE 0x2093 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_CONTEXT_FLAGS 0x2094 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_CONTEXT_PROFILE_MASK 0x9126 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_CONTEXT_DEBUG_BIT 0x0001 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_CONTEXT_FORWARD_COMPATIBLE_BIT 0x0002 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_CONTEXT_CORE_PROFILE_BIT 0x00000001 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_WGL_CONTEXT_ES2_PROFILE_BIT 0x00000004 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_ERROR_INVALID_VERSION 0x2095 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SK_ERROR_INVALID_PROFILE 0x2096 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkWGLExtensions { 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic: 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkWGLExtensions(); 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Determines if an extensions is available for a given DC. 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * WGL_extensions_string is considered a prerequisite for all other 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * extensions. It is necessary to check this before calling other class 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * functions. 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool hasExtension(HDC dc, const char* ext) const; 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const char* getExtensionsString(HDC hdc) const; 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru BOOL choosePixelFormat(HDC hdc, const int*, const FLOAT*, UINT, int*, UINT*) const; 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru BOOL getPixelFormatAttribiv(HDC, int, int, UINT, const int*, int*) const; 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru BOOL getPixelFormatAttribfv(HDC hdc, int, int, UINT, const int*, FLOAT*) const; 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru HGLRC createContextAttribs(HDC, HGLRC, const int *) const; 7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * WGL doesn't have precise rules for the ordering of formats returned 7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * by wglChoosePixelFormat. This function helps choose among the set of 7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * formats returned by wglChoosePixelFormat. The rules in decreasing 8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * priority are: 8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * * Choose formats with the smallest sample count that is >= 8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * desiredSampleCount (or the largest sample count if all formats have 8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * fewer samples than desiredSampleCount.) 8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * * Choose formats with the fewest color samples when coverage sampling 8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * is available. 8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * * If the above rules leave multiple formats, choose the one that 8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * appears first in the formats array parameter. 8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int selectFormat(const int formats[], 9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int formatCount, 9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru HDC dc, 9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int desiredSampleCount); 9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate: 9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru typedef const char* (WINAPI *GetExtensionsStringProc)(HDC hdc); 9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru typedef BOOL (WINAPI *ChoosePixelFormatProc)(HDC hdc, const int *, const FLOAT *, UINT, int *, UINT *); 9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru typedef BOOL (WINAPI *GetPixelFormatAttribivProc)(HDC, int, int, UINT, const int*, int*); 9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru typedef BOOL (WINAPI *GetPixelFormatAttribfvProc)(HDC hdc, int, int, UINT, const int*, FLOAT*); 9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru typedef HGLRC (WINAPI *CreateContextAttribsProc)(HDC hDC, HGLRC, const int *); 9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GetExtensionsStringProc fGetExtensionsString; 10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru ChoosePixelFormatProc fChoosePixelFormat; 10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GetPixelFormatAttribfvProc fGetPixelFormatAttribfv; 10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GetPixelFormatAttribivProc fGetPixelFormatAttribiv; 10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru CreateContextAttribsProc fCreateContextAttribs; 10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 107096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger/** 108096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger * Helper to create an OpenGL context for a DC using WGL. Configs with a sample count >= to 109096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger * msaaSampleCount are preferred but if none is available then a context with a lower sample count 110096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger * (including non-MSAA) will be created. If preferCoreProfile is true but a core profile cannot be 111096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger * created then a compatible profile context will be created. 112096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger */ 113096defe64d408e54474fe19f418c95bf1a554fc7Derek SollenbergerHGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, bool preferCoreProfile); 114096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger 11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 116