michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #include "SkRefCnt.h" michael@0: michael@0: #ifndef SkWGL_DEFINED michael@0: #define SkWGL_DEFINED michael@0: michael@0: /** michael@0: * Working with WGL extensions can be a pain. Among the reasons is that You must michael@0: * have a GL context to get the proc addresses, but you want to use the procs to michael@0: * create a context in the first place. So you have to create a dummy GL ctx to michael@0: * get the proc addresses. michael@0: * michael@0: * This file helps by providing SkCreateWGLInterface(). It returns a struct of michael@0: * function pointers that it initializes. It also has a helper function to query michael@0: * for WGL extensions. It handles the fact that wglGetExtensionsString is itself michael@0: * an extension. michael@0: */ michael@0: michael@0: #if !defined(WIN32_LEAN_AND_MEAN) michael@0: #define WIN32_LEAN_AND_MEAN michael@0: #define SK_LOCAL_LEAN_AND_MEAN michael@0: #endif michael@0: #include michael@0: #if defined(SK_LOCAL_LEAN_AND_MEAN) michael@0: #undef WIN32_LEAN_AND_MEAN michael@0: #undef SK_LOCAL_LEAN_AND_MEAN michael@0: #endif michael@0: michael@0: #define SK_WGL_DRAW_TO_WINDOW 0x2001 michael@0: #define SK_WGL_ACCELERATION 0x2003 michael@0: #define SK_WGL_SUPPORT_OPENGL 0x2010 michael@0: #define SK_WGL_DOUBLE_BUFFER 0x2011 michael@0: #define SK_WGL_COLOR_BITS 0x2014 michael@0: #define SK_WGL_ALPHA_BITS 0x201B michael@0: #define SK_WGL_STENCIL_BITS 0x2023 michael@0: #define SK_WGL_FULL_ACCELERATION 0x2027 michael@0: #define SK_WGL_SAMPLE_BUFFERS 0x2041 michael@0: #define SK_WGL_SAMPLES 0x2042 michael@0: #define SK_WGL_CONTEXT_MAJOR_VERSION 0x2091 michael@0: #define SK_WGL_CONTEXT_MINOR_VERSION 0x2092 michael@0: #define SK_WGL_CONTEXT_LAYER_PLANE 0x2093 michael@0: #define SK_WGL_CONTEXT_FLAGS 0x2094 michael@0: #define SK_WGL_CONTEXT_PROFILE_MASK 0x9126 michael@0: #define SK_WGL_CONTEXT_DEBUG_BIT 0x0001 michael@0: #define SK_WGL_CONTEXT_FORWARD_COMPATIBLE_BIT 0x0002 michael@0: #define SK_WGL_CONTEXT_CORE_PROFILE_BIT 0x00000001 michael@0: #define SK_WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 michael@0: #define SK_WGL_CONTEXT_ES2_PROFILE_BIT 0x00000004 michael@0: #define SK_ERROR_INVALID_VERSION 0x2095 michael@0: #define SK_ERROR_INVALID_PROFILE 0x2096 michael@0: michael@0: class SkWGLExtensions { michael@0: public: michael@0: SkWGLExtensions(); michael@0: /** michael@0: * Determines if an extensions is available for a given DC. michael@0: * WGL_extensions_string is considered a prerequisite for all other michael@0: * extensions. It is necessary to check this before calling other class michael@0: * functions. michael@0: */ michael@0: bool hasExtension(HDC dc, const char* ext) const; michael@0: michael@0: const char* getExtensionsString(HDC hdc) const; michael@0: BOOL choosePixelFormat(HDC hdc, const int*, const FLOAT*, UINT, int*, UINT*) const; michael@0: BOOL getPixelFormatAttribiv(HDC, int, int, UINT, const int*, int*) const; michael@0: BOOL getPixelFormatAttribfv(HDC hdc, int, int, UINT, const int*, FLOAT*) const; michael@0: HGLRC createContextAttribs(HDC, HGLRC, const int *) const; michael@0: michael@0: /** michael@0: * WGL doesn't have precise rules for the ordering of formats returned michael@0: * by wglChoosePixelFormat. This function helps choose among the set of michael@0: * formats returned by wglChoosePixelFormat. The rules in decreasing michael@0: * priority are: michael@0: * * Choose formats with the smallest sample count that is >= michael@0: * desiredSampleCount (or the largest sample count if all formats have michael@0: * fewer samples than desiredSampleCount.) michael@0: * * Choose formats with the fewest color samples when coverage sampling michael@0: * is available. michael@0: * * If the above rules leave multiple formats, choose the one that michael@0: * appears first in the formats array parameter. michael@0: */ michael@0: int selectFormat(const int formats[], michael@0: int formatCount, michael@0: HDC dc, michael@0: int desiredSampleCount); michael@0: private: michael@0: typedef const char* (WINAPI *GetExtensionsStringProc)(HDC hdc); michael@0: typedef BOOL (WINAPI *ChoosePixelFormatProc)(HDC hdc, const int *, const FLOAT *, UINT, int *, UINT *); michael@0: typedef BOOL (WINAPI *GetPixelFormatAttribivProc)(HDC, int, int, UINT, const int*, int*); michael@0: typedef BOOL (WINAPI *GetPixelFormatAttribfvProc)(HDC hdc, int, int, UINT, const int*, FLOAT*); michael@0: typedef HGLRC (WINAPI *CreateContextAttribsProc)(HDC hDC, HGLRC, const int *); michael@0: michael@0: GetExtensionsStringProc fGetExtensionsString; michael@0: ChoosePixelFormatProc fChoosePixelFormat; michael@0: GetPixelFormatAttribfvProc fGetPixelFormatAttribfv; michael@0: GetPixelFormatAttribivProc fGetPixelFormatAttribiv; michael@0: CreateContextAttribsProc fCreateContextAttribs; michael@0: }; michael@0: michael@0: /** michael@0: * Helper to create an OpenGL context for a DC using WGL. Configs with a sample count >= to michael@0: * msaaSampleCount are preferred but if none is available then a context with a lower sample count michael@0: * (including non-MSAA) will be created. If preferCoreProfile is true but a core profile cannot be michael@0: * created then a compatible profile context will be created. michael@0: */ michael@0: HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, bool preferCoreProfile); michael@0: michael@0: #endif