Home | History | Annotate | Download | only in win32
      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 "gluRenderContext.hpp"
     28 #include "deDynamicLibrary.h"
     29 #include "tcuWin32API.h"
     30 
     31 #include <vector>
     32 
     33 namespace glu
     34 {
     35 struct RenderConfig;
     36 }
     37 
     38 namespace tcu
     39 {
     40 namespace wgl
     41 {
     42 
     43 class Library;
     44 class Context;
     45 
     46 /*--------------------------------------------------------------------*//*!
     47  * \brief WGL pixel format info.
     48  *//*--------------------------------------------------------------------*/
     49 class PixelFormatInfo
     50 {
     51 public:
     52 	enum PixelType
     53 	{
     54 		PIXELTYPE_RGBA = 0,
     55 		PIXELTYPE_RGBA_FLOAT,
     56 		PIXELTYPE_RGBA_UNSIGNED_FLOAT,
     57 		PIXELTYPE_COLOR_INDEX,
     58 		PIXELTYPE_UNKNOWN,
     59 
     60 		PIXELTYPE_LAST
     61 	};
     62 
     63 	enum SurfaceFlags
     64 	{
     65 		SURFACE_WINDOW	= (1<<0),
     66 		SURFACE_PIXMAP	= (1<<1)
     67 	};
     68 
     69 	enum Acceleration
     70 	{
     71 		ACCELERATION_NONE = 0,
     72 		ACCELERATION_GENERIC,
     73 		ACCELERATION_FULL,
     74 		ACCELERATION_UNKNOWN,
     75 
     76 		ACCELERATION_LAST
     77 	};
     78 
     79 	int				pixelFormat;
     80 
     81 	// From WGL_ARB_pixel_format
     82 	deUint32		surfaceTypes;
     83 	Acceleration	acceleration;
     84 //	bool			needPalette;
     85 //	bool			needSystemPalette;
     86 //	bool			swapLayerBuffers;
     87 //	SwapMethod		swapMethod; { EXCHANGE, UNDEFINED }
     88 //	int				numOverlays;
     89 //	int				numUnderlays;
     90 //	bool			transparent;
     91 //	int				transparentRedValue;
     92 //	int				transparentGreenValue;
     93 //	int				transparentBlueValue;
     94 //	int				transparentAlphaValue;
     95 //	int				transparentIndexValue;
     96 //	bool			shareDepth;
     97 //	bool			shareStencil;
     98 //	bool			shareAccum;
     99 //	bool			supportGDI;
    100 	bool			supportOpenGL;
    101 	bool			doubleBuffer;
    102 //	bool			stereo;
    103 	PixelType		pixelType;
    104 
    105 //	int				colorBits;
    106 	int				redBits;
    107 //	int				redShift;
    108 	int				greenBits;
    109 //	int				greenShift;
    110 	int				blueBits;
    111 //	int				blueShift;
    112 	int				alphaBits;
    113 //	int				alphaShift;
    114 
    115 //	int				accumBits;
    116 //	int				accumRedBits;
    117 //	int				accumGreenBits;
    118 //	int				accumBlueBits;
    119 //	int				accumAlphaBits;
    120 
    121 	int				depthBits;
    122 	int				stencilBits;
    123 
    124 //	int				numAuxBuffers;
    125 
    126 	// From WGL_ARB_multisample
    127 	int				sampleBuffers;
    128 	int				samples;
    129 
    130 	// \todo [2013-04-14 pyry] Version bits?
    131 
    132 	PixelFormatInfo (void)
    133 		: pixelFormat	(0)
    134 		, surfaceTypes	(0)
    135 		, acceleration	(ACCELERATION_LAST)
    136 		, supportOpenGL	(false)
    137 		, doubleBuffer	(false)
    138 		, pixelType		(PIXELTYPE_LAST)
    139 		, redBits		(0)
    140 		, greenBits		(0)
    141 		, blueBits		(0)
    142 		, alphaBits		(0)
    143 		, depthBits		(0)
    144 		, stencilBits	(0)
    145 		, sampleBuffers	(0)
    146 		, samples		(0)
    147 	{
    148 	}
    149 };
    150 
    151 /*--------------------------------------------------------------------*//*!
    152  * \brief Core WGL API
    153  *
    154  * \note Created API objects depend on Core object being live. User is
    155  *		 resposible of keeping Core live as long as there are API objects
    156  *		 (such as GL contexts) live!
    157  *//*--------------------------------------------------------------------*/
    158 class Core
    159 {
    160 public:
    161 						Core				(HINSTANCE instance);
    162 						~Core				(void);
    163 
    164 	std::vector<int>	getPixelFormats		(HDC deviceCtx) const;
    165 	PixelFormatInfo		getPixelFormatInfo	(HDC deviceCtx, int pixelFormat) const;
    166 
    167 	// Internal
    168 	const Library*		getLibrary			(void) const { return m_library; }
    169 
    170 private:
    171 						Core				(const Core& other);
    172 	Core&				operator=			(const Core& other);
    173 
    174 	Library*			m_library;
    175 };
    176 
    177 //! Function pointer type.
    178 typedef void (__stdcall* FunctionPtr) (void);
    179 
    180 /*--------------------------------------------------------------------*//*!
    181  * \brief WGL context
    182  *
    183  * Context is currently made current to current thread in constructor
    184  * and detached in destructor. Thus context should be created in and
    185  * accessed from a single thread.
    186  *//*--------------------------------------------------------------------*/
    187 class Context
    188 {
    189 public:
    190 						Context				(const Core* core, HDC deviceCtx, glu::ContextType ctxType, int pixelFormat);
    191 						~Context			(void);
    192 
    193 	FunctionPtr			getGLFunction		(const char* name) const;
    194 
    195 	void				swapBuffers			(void) const;
    196 
    197 	HDC					getDeviceContext	(void) const { return m_deviceCtx;	}
    198 	HGLRC				getGLContext		(void) const { return m_context;	}
    199 
    200 private:
    201 						Context				(const Context& other);
    202 	Context&			operator=			(const Context& other);
    203 
    204 	const Core*			m_core;
    205 	HDC					m_deviceCtx;
    206 	HGLRC				m_context;
    207 };
    208 
    209 //! Utility for selecting config. Returns -1 if no matching pixel format was found.
    210 int		choosePixelFormat	(const Core& wgl, HDC deviceCtx, const glu::RenderConfig& config);
    211 
    212 } // wgl
    213 } // tcu
    214 
    215 #endif // _TCUWGL_HPP
    216