xref: /aosp_15_r20/external/deqp/framework/opengl/gluContextInfo.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
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
88     {
89         return true;
90     }
isVertexDynamicLoopSupported(void) const91     virtual bool isVertexDynamicLoopSupported(void) const
92     {
93         return true;
94     }
isFragmentHighPrecisionSupported(void) const95     virtual bool isFragmentHighPrecisionSupported(void) const
96     {
97         return true;
98     }
isFragmentUniformLoopSupported(void) const99     virtual bool isFragmentUniformLoopSupported(void) const
100     {
101         return true;
102     }
isFragmentDynamicLoopSupported(void) const103     virtual bool isFragmentDynamicLoopSupported(void) const
104     {
105         return true;
106     }
107 
108     virtual bool isCompressedTextureFormatSupported(int format) const;
109 
getExtensions(void) const110     const std::vector<std::string> &getExtensions(void) const
111     {
112         return m_extensions;
113     }
114     bool isExtensionSupported(const char *extName) const;
115 
116     bool isES3Compatible() const;
117 
118     static ContextInfo *create(const RenderContext &context);
119 
120 protected:
121     ContextInfo(const RenderContext &context);
122 
123     const RenderContext &m_context;
124 
125 private:
126     ContextInfo(const ContextInfo &other);
127     ContextInfo &operator=(const ContextInfo &other);
128 
129     std::vector<std::string> m_extensions;
130     CompressedTextureFormats m_compressedTextureFormats;
131 };
132 
133 } // namespace glu
134 
135 #endif // _GLUCONTEXTINFO_HPP
136