blob: 35c93f68dcffd644d9ed7043b17770d7348e2469 [file] [log] [blame]
bsalomon@google.combd7c6412011-12-01 16:34:28 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#include "SkRefCnt.h"
10
11#ifndef SkWGL_DEFINED
12#define SkWGL_DEFINED
13
14/**
15 * Working with WGL extensions can be a pain. Among the reasons is that You must
16 * have a GL context to get the proc addresses, but you want to use the procs to
17 * create a context in the first place. So you have to create a dummy GL ctx to
18 * get the proc addresses.
19 *
20 * This file helps by providing SkCreateWGLInterface(). It returns a struct of
21 * function pointers that it initializes. It also has a helper function to query
22 * for WGL extensions. It handles the fact that wglGetExtensionsString is itself
23 * an extension.
24 */
25
26#if !defined(WIN32_LEAN_AND_MEAN)
27 #define WIN32_LEAN_AND_MEAN
28 #define SK_LOCAL_LEAN_AND_MEAN
29#endif
30#include <Windows.h>
31#if defined(SK_LOCAL_LEAN_AND_MEAN)
32 #undef WIN32_LEAN_AND_MEAN
33 #undef SK_LOCAL_LEAN_AND_MEAN
34#endif
35
36#define SK_WGL_DRAW_TO_WINDOW_ARB 0x2001
37#define SK_WGL_ACCELERATION_ARB 0x2003
38#define SK_WGL_SUPPORT_OPENGL_ARB 0x2010
39#define SK_WGL_DOUBLE_BUFFER_ARB 0x2011
40#define SK_WGL_COLOR_BITS_ARB 0x2014
41#define SK_WGL_ALPHA_BITS_ARB 0x201B
42#define SK_WGL_STENCIL_BITS_ARB 0x2023
43#define SK_WGL_FULL_ACCELERATION_ARB 0x2027
44#define SK_WGL_SAMPLE_BUFFERS_ARB 0x2041
45#define SK_WGL_SAMPLES_ARB 0x2042
46#define SK_WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
47#define SK_WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
48#define SK_WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
49#define SK_WGL_CONTEXT_FLAGS_ARB 0x2094
50#define SK_WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
51#define SK_WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
52#define SK_WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
53#define SK_WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
54#define SK_WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
55#define SK_WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004
56#define SK_ERROR_INVALID_VERSION_ARB 0x2095
57#define SK_ERROR_INVALID_PROFILE_ARB 0x2096
58
59class SkWGLExtensions {
60public:
61 SkWGLExtensions();
62 /**
63 * Determines if an extensions is available for a given DC.
64 * WGL_ARB_extensions_string is considered a prerequisite for all other
65 * extensions. It is necessary to check this before calling other class
66 * functions.
67 */
68 bool hasExtension(HDC dc, const char* ext) const;
69
70 const char* getExtensionsString(HDC hdc) const;
71 BOOL choosePixelFormat(HDC hdc, const int*, const FLOAT*, UINT, int*, UINT*) const;
72 BOOL getPixelFormatAttribiv(HDC, int, int, UINT, const int*, int*) const;
73 BOOL getPixelFormatAttribfv(HDC hdc, int, int, UINT, const int*, FLOAT*) const;
74 HGLRC createContextAttribs(HDC, HGLRC, const int *) const;
75
76private:
77 typedef const char* (WINAPI *GetExtensionsStringProc)(HDC hdc);
78 typedef BOOL (WINAPI *ChoosePixelFormatProc)(HDC hdc, const int *, const FLOAT *, UINT, int *, UINT *);
79 typedef BOOL (WINAPI *GetPixelFormatAttribivProc)(HDC, int, int, UINT, const int*, int*);
80 typedef BOOL (WINAPI *GetPixelFormatAttribfvProc)(HDC hdc, int, int, UINT, const int*, FLOAT*);
81 typedef HGLRC (WINAPI *CreateContextAttribsProc)(HDC hDC, HGLRC, const int *);
82
83 GetExtensionsStringProc fGetExtensionsString;
84 ChoosePixelFormatProc fChoosePixelFormat;
85 GetPixelFormatAttribfvProc fGetPixelFormatAttribfv;
86 GetPixelFormatAttribivProc fGetPixelFormatAttribiv;
87 CreateContextAttribsProc fCreateContextAttribs;
88};
89
90#endif