1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef GPU_COMMAND_BUFFER_CLIENT_PROGRAM_INFO_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_CLIENT_PROGRAM_INFO_MANAGER_H_
13 #include "base/containers/hash_tables.h"
14 #include "base/gtest_prod_util.h"
15 #include "base/synchronization/lock.h"
16 #include "gles2_impl_export.h"
17 #include "gpu/command_buffer/client/gles2_implementation.h"
22 // Manages info about OpenGL ES Programs.
23 class GLES2_IMPL_EXPORT ProgramInfoManager
{
26 ~ProgramInfoManager();
28 void CreateInfo(GLuint program
);
30 void DeleteInfo(GLuint program
);
33 GLES2Implementation
* gl
, GLuint program
, GLenum pname
, GLint
* params
);
35 GLint
GetAttribLocation(
36 GLES2Implementation
* gl
, GLuint program
, const char* name
);
38 GLint
GetUniformLocation(
39 GLES2Implementation
* gl
, GLuint program
, const char* name
);
41 GLint
GetFragDataLocation(
42 GLES2Implementation
* gl
, GLuint program
, const char* name
);
45 GLES2Implementation
* gl
, GLuint program
, GLuint index
, GLsizei bufsize
,
46 GLsizei
* length
, GLint
* size
, GLenum
* type
, char* name
);
48 bool GetActiveUniform(
49 GLES2Implementation
* gl
, GLuint program
, GLuint index
, GLsizei bufsize
,
50 GLsizei
* length
, GLint
* size
, GLenum
* type
, char* name
);
52 GLuint
GetUniformBlockIndex(
53 GLES2Implementation
* gl
, GLuint program
, const char* name
);
55 bool GetActiveUniformBlockName(
56 GLES2Implementation
* gl
, GLuint program
, GLuint index
,
57 GLsizei buf_size
, GLsizei
* length
, char* name
);
59 bool GetActiveUniformBlockiv(
60 GLES2Implementation
* gl
, GLuint program
, GLuint index
,
61 GLenum pname
, GLint
* params
);
63 // Attempt to update the |index| uniform block binding.
64 // It's no op if the program does not exist, or the |index| uniform block
65 // is not in the cache, or binding >= GL_MAX_UNIFORM_BUFFER_BINDINGS.
66 void UniformBlockBinding(
67 GLES2Implementation
* gl
, GLuint program
, GLuint index
, GLuint binding
);
69 bool GetTransformFeedbackVarying(
70 GLES2Implementation
* gl
, GLuint program
, GLuint index
, GLsizei bufsize
,
71 GLsizei
* length
, GLsizei
* size
, GLenum
* type
, char* name
);
73 bool GetUniformIndices(
74 GLES2Implementation
* gl
, GLuint program
, GLsizei count
,
75 const char* const* names
, GLuint
* indices
);
77 bool GetActiveUniformsiv(
78 GLES2Implementation
* gl
, GLuint program
, GLsizei count
,
79 const GLuint
* indices
, GLenum pname
, GLint
* params
);
82 friend class ProgramInfoManagerTest
;
84 FRIEND_TEST_ALL_PREFIXES(ProgramInfoManagerTest
, UpdateES2
);
85 FRIEND_TEST_ALL_PREFIXES(ProgramInfoManagerTest
, UpdateES3UniformBlocks
);
86 FRIEND_TEST_ALL_PREFIXES(ProgramInfoManagerTest
,
87 UpdateES3TransformFeedbackVaryings
);
88 FRIEND_TEST_ALL_PREFIXES(ProgramInfoManagerTest
,
89 GetActiveUniformsivCached
);
91 enum ProgramInfoType
{
94 kES3TransformFeedbackVaryings
,
99 // Need GLES2_IMPL_EXPORT for tests.
100 class GLES2_IMPL_EXPORT Program
{
103 UniformInfo(GLsizei _size
, GLenum _type
, const std::string
& _name
);
110 std::vector
<GLint
> element_locations
;
122 struct VertexAttrib
{
123 VertexAttrib(GLsizei _size
, GLenum _type
, const std::string
& _name
,
132 struct UniformBlock
{
138 std::vector
<GLuint
> active_uniform_indices
;
139 GLboolean referenced_by_vertex_shader
;
140 GLboolean referenced_by_fragment_shader
;
143 struct TransformFeedbackVarying
{
144 TransformFeedbackVarying();
145 ~TransformFeedbackVarying();
155 const VertexAttrib
* GetAttribInfo(GLint index
) const;
157 GLint
GetAttribLocation(const std::string
& name
) const;
159 const UniformInfo
* GetUniformInfo(GLint index
) const;
161 // Gets the location of a uniform by name.
162 GLint
GetUniformLocation(const std::string
& name
) const;
163 // Gets the index of a uniform by name. Return INVALID_INDEX in failure.
164 GLuint
GetUniformIndex(const std::string
& name
) const;
167 GLsizei count
, const GLuint
* indices
, GLenum pname
, GLint
* params
);
169 GLint
GetFragDataLocation(const std::string
& name
) const;
170 void CacheFragDataLocation(const std::string
& name
, GLint loc
);
172 bool GetProgramiv(GLenum pname
, GLint
* params
);
174 // Gets the index of a uniform block by name.
175 GLuint
GetUniformBlockIndex(const std::string
& name
) const;
176 const UniformBlock
* GetUniformBlock(GLuint index
) const;
177 // Update the binding if the |index| uniform block is in the cache.
178 void UniformBlockBinding(GLuint index
, GLuint binding
);
180 const TransformFeedbackVarying
* GetTransformFeedbackVarying(
183 // Updates the ES2 only program info after a successful link.
184 void UpdateES2(const std::vector
<int8
>& result
);
186 // Updates the ES3 UniformBlock info after a successful link.
187 void UpdateES3UniformBlocks(const std::vector
<int8
>& result
);
189 // Updates the ES3 Uniformsiv info after a successful link.
190 void UpdateES3Uniformsiv(const std::vector
<int8
>& result
);
192 // Updates the ES3 TransformFeedbackVaryings info after a successful link.
193 void UpdateES3TransformFeedbackVaryings(const std::vector
<int8
>& result
);
195 bool IsCached(ProgramInfoType type
) const;
200 GLsizei max_attrib_name_length_
;
203 std::vector
<VertexAttrib
> attrib_infos_
;
205 GLsizei max_uniform_name_length_
;
207 // Uniform info by index.
208 std::vector
<UniformInfo
> uniform_infos_
;
210 // This is true if glLinkProgram was successful last time it was called.
213 // BELOW ARE ES3 ONLY INFORMATION.
215 bool cached_es3_uniform_blocks_
;
217 uint32_t active_uniform_block_max_name_length_
;
219 // Uniform blocks by index.
220 std::vector
<UniformBlock
> uniform_blocks_
;
222 bool cached_es3_transform_feedback_varyings_
;
224 uint32_t transform_feedback_varying_max_length_
;
226 // TransformFeedback varyings by index.
227 std::vector
<TransformFeedbackVarying
> transform_feedback_varyings_
;
229 bool cached_es3_uniformsiv_
;
231 std::vector
<UniformES3
> uniforms_es3_
;
233 base::hash_map
<std::string
, GLint
> frag_data_locations_
;
236 Program
* GetProgramInfo(
237 GLES2Implementation
* gl
, GLuint program
, ProgramInfoType type
);
239 typedef base::hash_map
<GLuint
, Program
> ProgramInfoMap
;
241 ProgramInfoMap program_infos_
;
243 mutable base::Lock lock_
;
249 #endif // GPU_COMMAND_BUFFER_CLIENT_PROGRAM_INFO_MANAGER_H_