1 #ifndef _GLUCONTEXTINFO_HPP
2 #define _GLUCONTEXTINFO_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program OpenGL ES Utilities
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 Context Info Class.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "gluDefs.hpp"
27 
28 #include <vector>
29 #include <string>
30 #include <set>
31 
32 namespace glu
33 {
34 
35 class RenderContext;
36 
37 template <typename T, class ComputeValue>
38 class CachedValue
39 {
40 public:
CachedValue(ComputeValue compute=ComputeValue (),const T & defaultValue=T ())41 	CachedValue (ComputeValue compute = ComputeValue(), const T& defaultValue = T())
42 		: m_compute		(compute)
43 		, m_value		(defaultValue)
44 		, m_isComputed	(false)
45 	{
46 	}
47 
getValue(const RenderContext & context) const48 	const T& getValue (const RenderContext& context) const
49 	{
50 		if (!m_isComputed)
51 		{
52 			m_value			= m_compute(context);
53 			m_isComputed	= true;
54 		}
55 		return m_value;
56 	}
57 
58 private:
59 	ComputeValue	m_compute;
60 	mutable T		m_value;
61 	mutable bool	m_isComputed;
62 };
63 
64 class GetExtensions
65 {
66 public:
67 	std::vector<std::string> operator() (const RenderContext& context) const;
68 };
69 
70 class GetCompressedTextureFormats
71 {
72 public:
73 	std::set<int> operator() (const RenderContext& context) const;
74 };
75 
76 typedef CachedValue<std::vector<std::string>, GetExtensions>	ExtensionList;
77 typedef CachedValue<std::set<int>, GetCompressedTextureFormats>	CompressedTextureFormats;
78 
79 /*--------------------------------------------------------------------*//*!
80  * \brief Context information & limit query.
81  *//*--------------------------------------------------------------------*/
82 class ContextInfo
83 {
84 public:
85 	virtual										~ContextInfo						(void);
86 
87 	virtual int									getInt								(int param) const;
88 	virtual bool								getBool								(int param) const;
89 	virtual const char*							getString							(int param) const;
90 
isVertexUniformLoopSupported(void) const91 	virtual bool								isVertexUniformLoopSupported		(void) const { return true; }
isVertexDynamicLoopSupported(void) const92 	virtual bool								isVertexDynamicLoopSupported		(void) const { return true; }
isFragmentHighPrecisionSupported(void) const93 	virtual bool								isFragmentHighPrecisionSupported	(void) const { return true; }
isFragmentUniformLoopSupported(void) const94 	virtual bool								isFragmentUniformLoopSupported		(void) const { return true; }
isFragmentDynamicLoopSupported(void) const95 	virtual bool								isFragmentDynamicLoopSupported		(void) const { return true; }
96 
97 	virtual bool								isCompressedTextureFormatSupported	(int format) const;
98 
getExtensions(void) const99 	const std::vector<std::string>&				getExtensions						(void) const { return m_extensions.getValue(m_context); }
100 	bool										isExtensionSupported				(const char* extName) const;
101 
102 	static ContextInfo*							create								(const RenderContext& context);
103 
104 protected:
105 												ContextInfo							(const RenderContext& context);
106 
107 	const RenderContext&						m_context;
108 
109 private:
110 												ContextInfo							(const ContextInfo& other);
111 	ContextInfo&								operator=							(const ContextInfo& other);
112 
113 	ExtensionList								m_extensions;
114 	CompressedTextureFormats					m_compressedTextureFormats;
115 };
116 
117 } // glu
118 
119 #endif // _GLUCONTEXTINFO_HPP
120