• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "glwFunctions.hpp"
27 #include "gluDefs.hpp"
28 
29 #include <vector>
30 #include <string>
31 #include <set>
32 
33 namespace glu
34 {
35 
36 class RenderContext;
37 
38 template <typename T, class ComputeValue>
39 class CachedValue
40 {
41 public:
CachedValue(ComputeValue compute=ComputeValue (),const T & defaultValue=T ())42 	CachedValue (ComputeValue compute = ComputeValue(), const T& defaultValue = T())
43 		: m_compute		(compute)
44 		, m_value		(defaultValue)
45 		, m_isComputed	(false)
46 	{
47 	}
48 
getValue(const RenderContext & context) const49 	const T& getValue (const RenderContext& context) const
50 	{
51 		if (!m_isComputed)
52 		{
53 			m_value			= m_compute(context);
54 			m_isComputed	= true;
55 		}
56 		return m_value;
57 	}
58 
59 private:
60 	ComputeValue	m_compute;
61 	mutable T		m_value;
62 	mutable bool	m_isComputed;
63 };
64 
65 class GetCompressedTextureFormats
66 {
67 public:
68 	std::set<int> operator() (const RenderContext& context) const;
69 };
70 
71 typedef CachedValue<std::set<int>, GetCompressedTextureFormats>	CompressedTextureFormats;
72 
73 bool IsES3Compatible(const glw::Functions& gl);
74 
75 /*--------------------------------------------------------------------*//*!
76  * \brief Context information & limit query.
77  *//*--------------------------------------------------------------------*/
78 class ContextInfo
79 {
80 public:
81 	virtual										~ContextInfo						(void);
82 
83 	virtual int									getInt								(int param) const;
84 	virtual bool								getBool								(int param) const;
85 	virtual const char*							getString							(int param) const;
86 
isVertexUniformLoopSupported(void) const87 	virtual bool								isVertexUniformLoopSupported		(void) const { return true; }
isVertexDynamicLoopSupported(void) const88 	virtual bool								isVertexDynamicLoopSupported		(void) const { return true; }
isFragmentHighPrecisionSupported(void) const89 	virtual bool								isFragmentHighPrecisionSupported	(void) const { return true; }
isFragmentUniformLoopSupported(void) const90 	virtual bool								isFragmentUniformLoopSupported		(void) const { return true; }
isFragmentDynamicLoopSupported(void) const91 	virtual bool								isFragmentDynamicLoopSupported		(void) const { return true; }
92 
93 	virtual bool								isCompressedTextureFormatSupported	(int format) const;
94 
getExtensions(void) const95 	const std::vector<std::string>&				getExtensions						(void) const { return m_extensions; }
96 	bool										isExtensionSupported				(const char* extName) const;
97 
98 	bool											isES3Compatible() const;
99 
100 	static ContextInfo*							create								(const RenderContext& context);
101 
102 protected:
103 												ContextInfo							(const RenderContext& context);
104 
105 	const RenderContext&						m_context;
106 
107 private:
108 												ContextInfo							(const ContextInfo& other);
109 	ContextInfo&								operator=							(const ContextInfo& other);
110 
111 	std::vector<std::string>					m_extensions;
112 	CompressedTextureFormats					m_compressedTextureFormats;
113 };
114 
115 } // glu
116 
117 #endif // _GLUCONTEXTINFO_HPP
118