• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _TCUWGL_HPP
2 #define _TCUWGL_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Tester Core
5  * ----------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief WGL Utilities.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "gluRenderConfig.hpp"
28 #include "gluRenderContext.hpp"
29 #include "deDynamicLibrary.h"
30 #include "tcuWin32API.h"
31 
32 #include <vector>
33 
34 namespace glu
35 {
36 struct RenderConfig;
37 }
38 
39 namespace tcu
40 {
41 namespace wgl
42 {
43 
44 class Library;
45 class Context;
46 
47 /*--------------------------------------------------------------------*//*!
48  * \brief WGL pixel format info.
49  *//*--------------------------------------------------------------------*/
50 class PixelFormatInfo
51 {
52 public:
53 	enum PixelType
54 	{
55 		PIXELTYPE_RGBA = 0,
56 		PIXELTYPE_RGBA_FLOAT,
57 		PIXELTYPE_RGBA_UNSIGNED_FLOAT,
58 		PIXELTYPE_COLOR_INDEX,
59 		PIXELTYPE_UNKNOWN,
60 
61 		PIXELTYPE_LAST
62 	};
63 
64 	enum SurfaceFlags
65 	{
66 		SURFACE_WINDOW	= (1<<0),
67 		SURFACE_PIXMAP	= (1<<1)
68 	};
69 
70 	enum Acceleration
71 	{
72 		ACCELERATION_NONE = 0,
73 		ACCELERATION_GENERIC,
74 		ACCELERATION_FULL,
75 		ACCELERATION_UNKNOWN,
76 
77 		ACCELERATION_LAST
78 	};
79 
80 	int				pixelFormat;
81 
82 	// From WGL_ARB_pixel_format
83 	deUint32		surfaceTypes;
84 	Acceleration	acceleration;
85 	bool			needPalette;
86 	bool			needSystemPalette;
87 //	bool			swapLayerBuffers;
88 //	SwapMethod		swapMethod; { EXCHANGE, UNDEFINED }
89 	int				numOverlays;
90 	int				numUnderlays;
91 //	bool			transparent;
92 //	int				transparentRedValue;
93 //	int				transparentGreenValue;
94 //	int				transparentBlueValue;
95 //	int				transparentAlphaValue;
96 //	int				transparentIndexValue;
97 //	bool			shareDepth;
98 //	bool			shareStencil;
99 //	bool			shareAccum;
100 //	bool			supportGDI;
101 	bool			supportOpenGL;
102 	bool			doubleBuffer;
103 	bool			stereo;
104 	PixelType		pixelType;
105 
106 //	int				colorBits;
107 	int				redBits;
108 //	int				redShift;
109 	int				greenBits;
110 //	int				greenShift;
111 	int				blueBits;
112 //	int				blueShift;
113 	int				alphaBits;
114 //	int				alphaShift;
115 
116 	int				accumBits;
117 //	int				accumRedBits;
118 //	int				accumGreenBits;
119 //	int				accumBlueBits;
120 //	int				accumAlphaBits;
121 
122 	int				depthBits;
123 	int				stencilBits;
124 
125 	int				numAuxBuffers;
126 
127 	// From WGL_ARB_multisample
128 	int				sampleBuffers;
129 	int				samples;
130 
131 	// From WGL_EXT_colorspace
132 	bool			sRGB;
133 
134 	// \todo [2013-04-14 pyry] Version bits?
135 
PixelFormatInfo(void)136 	PixelFormatInfo (void)
137 		: pixelFormat		(0)
138 		, surfaceTypes		(0)
139 		, acceleration		(ACCELERATION_LAST)
140 		, needPalette		(false)
141 		, needSystemPalette	(false)
142 		, numOverlays		(0)
143 		, numUnderlays		(0)
144 		, supportOpenGL		(false)
145 		, doubleBuffer		(false)
146 		, stereo			(false)
147 		, pixelType			(PIXELTYPE_LAST)
148 		, redBits			(0)
149 		, greenBits			(0)
150 		, blueBits			(0)
151 		, alphaBits			(0)
152 		, accumBits			(0)
153 		, depthBits			(0)
154 		, stencilBits		(0)
155 		, numAuxBuffers		(0)
156 		, sampleBuffers		(0)
157 		, samples			(0)
158 		, sRGB				(false)
159 	{
160 	}
161 };
162 
163 /*--------------------------------------------------------------------*//*!
164  * \brief Core WGL API
165  *
166  * \note Created API objects depend on Core object being live. User is
167  *		 resposible of keeping Core live as long as there are API objects
168  *		 (such as GL contexts) live!
169  *//*--------------------------------------------------------------------*/
170 class Core
171 {
172 public:
173 						Core				(HINSTANCE instance);
174 						~Core				(void);
175 
176 	std::vector<int>	getPixelFormats		(HDC deviceCtx) const;
177 	PixelFormatInfo		getPixelFormatInfo	(HDC deviceCtx, int pixelFormat) const;
178 
179 	// Internal
getLibrary(void) const180 	const Library*		getLibrary			(void) const { return m_library; }
181 
182 private:
183 						Core				(const Core& other);
184 	Core&				operator=			(const Core& other);
185 
186 	Library*			m_library;
187 };
188 
189 //! Function pointer type.
190 typedef void (__stdcall* FunctionPtr) (void);
191 
192 /*--------------------------------------------------------------------*//*!
193  * \brief WGL context
194  *
195  * Context is currently made current to current thread in constructor
196  * and detached in destructor. Thus context should be created in and
197  * accessed from a single thread.
198  *//*--------------------------------------------------------------------*/
199 class Context
200 {
201 public:
202 						Context				(const Core*					core,
203 											 HDC							deviceCtx,
204 											 const Context*					sharedContext,
205 											 glu::ContextType				ctxType,
206 											 int							pixelFormat,
207 											 glu::ResetNotificationStrategy	resetNotificationStrategy);
208 						~Context			(void);
209 
210 	FunctionPtr			getGLFunction		(const char* name) const;
211 
212 	void				makeCurrent			(void);
213 	void				swapBuffers			(void) const;
214 
getDeviceContext(void) const215 	HDC					getDeviceContext	(void) const { return m_deviceCtx;	}
getGLContext(void) const216 	HGLRC				getGLContext		(void) const { return m_context;	}
217 
218 private:
219 						Context				(const Context& other);
220 	Context&			operator=			(const Context& other);
221 
222 	const Core*			m_core;
223 	HDC					m_deviceCtx;
224 	HGLRC				m_context;
225 };
226 
227 //! Utility for selecting config. Returns -1 if no matching pixel format was found.
228 int		choosePixelFormat	(const Core& wgl, HDC deviceCtx, const glu::RenderConfig& config);
229 
230 //! Is pixel format in general supported by dEQP tests?
231 bool	isSupportedByTests	(const PixelFormatInfo& pixelFormatInfo);
232 
233 } // wgl
234 } // tcu
235 
236 #endif // _TCUWGL_HPP
237