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 uint32_t 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 181 { 182 return m_library; 183 } 184 185 private: 186 Core(const Core &other); 187 Core &operator=(const Core &other); 188 189 Library *m_library; 190 }; 191 192 //! Function pointer type. 193 typedef void(__stdcall *FunctionPtr)(void); 194 195 /*--------------------------------------------------------------------*//*! 196 * \brief WGL context 197 * 198 * Context is currently made current to current thread in constructor 199 * and detached in destructor. Thus context should be created in and 200 * accessed from a single thread. 201 *//*--------------------------------------------------------------------*/ 202 class Context 203 { 204 public: 205 Context(const Core *core, HDC deviceCtx, const Context *sharedContext, glu::ContextType ctxType, int pixelFormat, 206 glu::ResetNotificationStrategy resetNotificationStrategy); 207 ~Context(void); 208 209 FunctionPtr getGLFunction(const char *name) const; 210 211 void makeCurrent(void); 212 void swapBuffers(void) const; 213 getDeviceContext(void) const214 HDC getDeviceContext(void) const 215 { 216 return m_deviceCtx; 217 } getGLContext(void) const218 HGLRC getGLContext(void) const 219 { 220 return m_context; 221 } 222 223 private: 224 Context(const Context &other); 225 Context &operator=(const Context &other); 226 227 const Core *m_core; 228 HDC m_deviceCtx; 229 HGLRC m_context; 230 }; 231 232 //! Utility for selecting config. Returns -1 if no matching pixel format was found. 233 int choosePixelFormat(const Core &wgl, HDC deviceCtx, const glu::RenderConfig &config); 234 235 //! Is pixel format in general supported by dEQP tests? 236 bool isSupportedByTests(const PixelFormatInfo &pixelFormatInfo); 237 238 } // namespace wgl 239 } // namespace tcu 240 241 #endif // _TCUWGL_HPP 242