PageRenderTime 117ms CodeModel.GetById 50ms app.highlight 33ms RepoModel.GetById 17ms app.codeStats 0ms

/opengles/src/Config.cpp

http://ftk.googlecode.com/
C++ | 446 lines | 315 code | 83 blank | 48 comment | 19 complexity | 90f7ae1c6403c657b613a9f7ff1e1311 MD5 | raw file
  1// ==========================================================================
  2//
  3// Config.cpp		Configuration Management Class
  4//					for 3D Rendering Library
  5//
  6// --------------------------------------------------------------------------
  7//
  8// 08-14-2003		Hans-Martin Will	initial version
  9//
 10// --------------------------------------------------------------------------
 11//
 12// Copyright (c) 2004, Hans-Martin Will. All rights reserved.
 13// 
 14// Redistribution and use in source and binary forms, with or without 
 15// modification, are permitted provided that the following conditions are 
 16// met:
 17// 
 18//	 *  Redistributions of source code must retain the above copyright
 19// 		notice, this list of conditions and the following disclaimer. 
 20//   *	Redistributions in binary form must reproduce the above copyright
 21// 		notice, this list of conditions and the following disclaimer in the 
 22// 		documentation and/or other materials provided with the distribution. 
 23// 
 24// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 25// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 26// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 27// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 28// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
 29// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 30// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 31// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 32// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 33// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
 34// THE POSSIBILITY OF SUCH DAMAGE.
 35//
 36// ==========================================================================
 37
 38
 39#include "stdafx.h"
 40#include "Config.h"
 41
 42
 43using namespace EGL;
 44
 45// --------------------------------------------------------------------------
 46// Table of Supported Configurations
 47// --------------------------------------------------------------------------
 48namespace {
 49    const EGL::Config s_AllConfigurations[] = {
 50   	    // ----------------------------------------------------------------------
 51	    // Initial default configuration 
 52	    // RGB 565, as PBuffer or Windows surface
 53	    // ----------------------------------------------------------------------
 54	    Config(
 55		    32,				//	EGLint	bufferSize,
 56		    5,				//	EGLint	redSize,
 57		    6,				//	EGLint	greenSize,
 58		    5,				//	EGLint	blueSize,
 59		    8,				//	EGLint	alphaSize,
 60		    EGL_SLOW_CONFIG,//	EGLint	configCaveat,
 61		    1,				//	EGLint	configID,
 62		    16,				//	EGLint	depthSize,
 63		    0,				//	EGLint	level,
 64		    1024,			//	EGLint	maxPBufferWidth,
 65		    1024,			//	EGLint	maxPBufferHeight,
 66		    1024 * 1024,	//	EGLint	mxPBufferPixels,
 67		    EGL_FALSE,		//	EGLint	nativeRenderable,
 68		    0,				//	EGLint	nativeVisualID,
 69		    EGL_NONE,		//	EGLint	nativeVisualType,
 70		    0,				//	EGLint	sampleBuffers,
 71		    0,				//	EGLint	samples,
 72		    32,				//	EGLint	stencilSize,
 73		    EGL_PBUFFER_BIT | EGL_WINDOW_BIT,//	EGLint	surfaceType,
 74		    EGL_NONE,		//	EGLint	transparentType,
 75		    0,				//	EGLint	transparentRedValue,
 76		    0,				//	EGLint	transparentGreenValue,
 77		    0,				//	EGLint	transparentBlueValue,
 78		    240,			//  EGLint	width,
 79		    320				//  EGLint	height
 80	    )
 81    };
 82
 83    // total number of supported configurations
 84    const int s_NumConfigurations = 1;
 85};
 86
 87Config :: Config(
 88	EGLint	bufferSize,
 89	EGLint	redSize,
 90	EGLint	greenSize,
 91	EGLint	blueSize,
 92	EGLint	alphaSize,
 93	EGLint	configCaveat,
 94	EGLint	configID,
 95	EGLint	depthSize,
 96	EGLint	level,
 97	EGLint	maxPBufferWidth,
 98	EGLint	maxPBufferHeight,
 99	EGLint	mxPBufferPixels,
100	EGLint	nativeRenderable,
101	EGLint	nativeVisualID,
102	EGLint	nativeVisualType,
103	EGLint	sampleBuffers,
104	EGLint	samples,
105	EGLint	stencilSize,
106	EGLint	surfaceType,
107	EGLint	transparentType,
108	EGLint	transparentRedValue,
109	EGLint	transparentGreenValue,
110	EGLint	transparentBlueValue,
111	EGLint	width,
112	EGLint	height):
113	m_BufferSize(bufferSize),
114	m_RedSize(redSize),
115	m_GreenSize(greenSize),
116	m_BlueSize(blueSize),
117	m_AlphaSize(alphaSize),
118	m_ConfigCaveat(configCaveat),
119	m_ConfigID(configID),
120	m_DepthSize(depthSize),
121	m_Level(level),
122	m_MaxPBufferWidth(maxPBufferWidth),
123	m_MaxPBufferHeight(maxPBufferHeight),
124	m_MaxPBufferPixels(mxPBufferPixels),
125	m_NativeRenderable(nativeRenderable),
126	m_NativeVisualID(nativeVisualID),
127	m_NativeVisualType(nativeVisualType),
128	m_SampleBuffers(sampleBuffers),
129	m_Samples(samples),
130	m_StencilSize(stencilSize),
131	m_SurfaceType(surfaceType),
132	m_TransparentType(transparentType),
133	m_TransparentRedValue(transparentRedValue),
134	m_TransparentGreenValue(transparentGreenValue),
135	m_TransparentBlueValue(transparentBlueValue),
136	m_Width(width),
137	m_Height(height)
138{
139}
140
141
142Config :: Config (const Config &other, const EGLint * attribList, const EGLint * validAttributes) {
143	m_BufferSize			= other.m_BufferSize;
144	m_RedSize				= other.m_RedSize;
145	m_GreenSize				= other.m_GreenSize;
146	m_BlueSize				= other.m_BlueSize;
147	m_AlphaSize				= other.m_AlphaSize;
148	m_ConfigCaveat			= other.m_ConfigCaveat;
149	m_ConfigID				= other.m_ConfigID;
150	m_DepthSize				= other.m_DepthSize;
151	m_Level					= other.m_Level;
152	m_MaxPBufferWidth		= other.m_MaxPBufferWidth;
153	m_MaxPBufferHeight		= other.m_MaxPBufferHeight;
154	m_MaxPBufferPixels		= other.m_MaxPBufferPixels;
155	m_NativeRenderable		= other.m_NativeRenderable;
156	m_NativeVisualID		= other.m_NativeVisualID;
157	m_NativeVisualType		= other.m_NativeVisualType;
158	m_SampleBuffers			= other.m_SampleBuffers;
159	m_Samples				= other.m_Samples;
160	m_StencilSize			= other.m_StencilSize;
161	m_SurfaceType			= other.m_SurfaceType;
162	m_TransparentType		= other.m_TransparentType;
163	m_TransparentRedValue	= other.m_TransparentRedValue;
164	m_TransparentGreenValue = other.m_TransparentGreenValue;
165	m_TransparentBlueValue	= other.m_TransparentBlueValue;
166	m_Width					= other.m_Width;
167	m_Height				= other.m_Height;
168
169	if (attribList != 0 && validAttributes != 0) {
170		while (*attribList != EGL_NONE) {
171			if (IsValidAttribute(validAttributes, *attribList)) {
172				SetConfigAttrib(attribList[0], attribList[1]);
173			}
174
175			attribList += 2;
176		}
177	}
178}
179
180
181Config & Config :: operator=(const Config & other) {
182	m_BufferSize			= other.m_BufferSize;
183	m_RedSize				= other.m_RedSize;
184	m_GreenSize				= other.m_GreenSize;
185	m_BlueSize				= other.m_BlueSize;
186	m_AlphaSize				= other.m_AlphaSize;
187	m_ConfigCaveat			= other.m_ConfigCaveat;
188	m_ConfigID				= other.m_ConfigID;
189	m_DepthSize				= other.m_DepthSize;
190	m_Level					= other.m_Level;
191	m_MaxPBufferWidth		= other.m_MaxPBufferWidth;
192	m_MaxPBufferHeight		= other.m_MaxPBufferHeight;
193	m_MaxPBufferPixels		= other.m_MaxPBufferPixels;
194	m_NativeRenderable		= other.m_NativeRenderable;
195	m_NativeVisualID		= other.m_NativeVisualID;
196	m_NativeVisualType		= other.m_NativeVisualType;
197	m_SampleBuffers			= other.m_SampleBuffers;
198	m_Samples				= other.m_Samples;
199	m_StencilSize			= other.m_StencilSize;
200	m_SurfaceType			= other.m_SurfaceType;
201	m_TransparentType		= other.m_TransparentType;
202	m_TransparentRedValue	= other.m_TransparentRedValue;
203	m_TransparentGreenValue = other.m_TransparentGreenValue;
204	m_TransparentBlueValue	= other.m_TransparentBlueValue;
205	m_Width					= other.m_Width;
206	m_Height				= other.m_Height;
207
208	return *this;
209}
210
211
212EGLint Config :: GetConfigAttrib(EGLint attribute) const {
213	switch (attribute) {
214	case EGL_BUFFER_SIZE:
215		return m_BufferSize;
216
217	case EGL_ALPHA_SIZE:
218		return m_AlphaSize;
219
220	case EGL_BLUE_SIZE:
221		return m_BlueSize;
222
223	case EGL_GREEN_SIZE:
224		return m_GreenSize;
225
226	case EGL_RED_SIZE:
227		return m_RedSize;
228
229	case EGL_DEPTH_SIZE:
230		return m_DepthSize;
231
232	case EGL_STENCIL_SIZE:
233		return m_StencilSize;
234
235	case EGL_CONFIG_CAVEAT:
236		return m_ConfigCaveat;
237
238	case EGL_CONFIG_ID:
239		return m_ConfigID;
240
241	case EGL_LEVEL:
242		return m_Level;
243
244	case EGL_MAX_PBUFFER_HEIGHT:
245		return m_MaxPBufferHeight;
246
247	case EGL_MAX_PBUFFER_PIXELS:
248		return m_MaxPBufferPixels;
249
250	case EGL_MAX_PBUFFER_WIDTH:
251		return m_MaxPBufferWidth;
252
253	case EGL_NATIVE_RENDERABLE:
254		return m_NativeRenderable;
255
256	case EGL_NATIVE_VISUAL_ID:
257		return m_NativeVisualID;
258
259	case EGL_NATIVE_VISUAL_TYPE:
260		return m_NativeVisualType;
261
262	case EGL_SAMPLES:
263		return m_Samples;
264
265	case EGL_SAMPLE_BUFFERS:
266		return m_SampleBuffers;
267
268	case EGL_SURFACE_TYPE:
269		return m_SurfaceType;
270
271	case EGL_TRANSPARENT_TYPE:
272		return m_TransparentType;
273
274	case EGL_TRANSPARENT_BLUE_VALUE:
275		return m_TransparentBlueValue;
276
277	case EGL_TRANSPARENT_GREEN_VALUE:
278		return m_TransparentGreenValue;
279
280	case EGL_TRANSPARENT_RED_VALUE:
281		return m_TransparentRedValue;
282
283	case EGL_WIDTH:
284		return m_Width;
285
286	case EGL_HEIGHT:
287		return m_Height;
288
289	default:
290		return EGL_NONE;
291	}
292}
293
294
295void Config :: SetConfigAttrib(EGLint attribute, EGLint value) {
296	switch (attribute) {
297	case EGL_BUFFER_SIZE:
298		m_BufferSize = value;
299		break;
300
301	case EGL_ALPHA_SIZE:
302		m_AlphaSize = value;
303		break;
304
305	case EGL_BLUE_SIZE:
306		m_BlueSize = value;
307		break;
308
309	case EGL_GREEN_SIZE:
310		m_GreenSize = value;
311		break;
312
313	case EGL_RED_SIZE:
314		m_RedSize = value;
315		break;
316
317	case EGL_DEPTH_SIZE:
318		m_DepthSize = value;
319		break;
320
321	case EGL_STENCIL_SIZE:
322		m_StencilSize = value;
323		break;
324
325	case EGL_CONFIG_CAVEAT:
326		m_ConfigCaveat = value;
327		break;
328
329	case EGL_CONFIG_ID:
330		m_ConfigID = value;
331		break;
332
333	case EGL_LEVEL:
334		m_Level = value;
335		break;
336
337	case EGL_MAX_PBUFFER_HEIGHT:
338		m_MaxPBufferHeight = value;
339		break;
340
341	case EGL_MAX_PBUFFER_PIXELS:
342		m_MaxPBufferPixels = value;
343		break;
344
345	case EGL_MAX_PBUFFER_WIDTH:
346		m_MaxPBufferWidth = value;
347		break;
348
349	case EGL_NATIVE_RENDERABLE:
350		m_NativeRenderable = value;
351		break;
352
353	case EGL_NATIVE_VISUAL_ID:
354		m_NativeVisualID = value;
355		break;
356
357	case EGL_NATIVE_VISUAL_TYPE:
358		m_NativeVisualType = value;
359		break;
360
361	case EGL_SAMPLES:
362		m_Samples = value;
363		break;
364
365	case EGL_SAMPLE_BUFFERS:
366		m_SampleBuffers = value;
367		break;
368
369	case EGL_SURFACE_TYPE:
370		m_SurfaceType = value;
371		break;
372
373	case EGL_TRANSPARENT_TYPE:
374		m_TransparentType = value;
375		break;
376
377	case EGL_TRANSPARENT_BLUE_VALUE:
378		m_TransparentBlueValue = value;
379		break;
380
381	case EGL_TRANSPARENT_GREEN_VALUE:
382		m_TransparentGreenValue = value;
383		break;
384
385	case EGL_TRANSPARENT_RED_VALUE:
386		m_TransparentRedValue = value;
387		break;
388
389	case EGL_WIDTH:
390		m_Width = value;
391		break;
392
393	case EGL_HEIGHT:
394		m_Height = value;
395		break;
396
397	}
398}
399
400
401bool Config :: IsValidAttribute(const EGLint * validAttributes, EGLint attribute) {
402	if (validAttributes == 0) {
403		return false;
404	}
405
406	while (*validAttributes != EGL_NONE) {
407		if (*validAttributes == attribute) {
408			return true;
409		}
410
411		validAttributes += 2;
412	}
413
414	return false;
415}
416
417
418EGLBoolean Config :: GetConfigs(EGLConfig * result, EGLint configSize, EGLint * numConfig) {
419
420	if (result == 0) {
421		// special case: inquire number of configurations available
422		*numConfig = s_NumConfigurations;
423		return EGL_TRUE;
424	}
425
426	if (configSize > s_NumConfigurations) {
427		configSize = s_NumConfigurations;
428	}
429
430	for (int index = 0; index < configSize; ++index) {
431		result[index] = &s_AllConfigurations[index];
432	}
433
434	*numConfig = configSize;
435	return EGL_TRUE;
436}
437
438
439EGLBoolean Config :: ChooseConfig(const EGLint * attribList, EGLConfig * result, EGLint configSize, EGLint * numConfig) {
440	// for now, as we only have one configuration available, just return that.
441	// to be a correct implementation, we will have at least to verify that
442	// the attributes specified match that.
443	return GetConfigs(result, configSize, numConfig);
444}
445
446