Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / gpu / command_buffer / client / program_info_manager.h
blob6f8a745c0b89d9af2106f1500d148842afad799f
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_
8 #include <GLES3/gl3.h>
10 #include <string>
11 #include <vector>
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"
19 namespace gpu {
20 namespace gles2 {
22 // Manages info about OpenGL ES Programs.
23 class GLES2_IMPL_EXPORT ProgramInfoManager {
24 public:
25 ProgramInfoManager();
26 ~ProgramInfoManager();
28 void CreateInfo(GLuint program);
30 void DeleteInfo(GLuint program);
32 bool GetProgramiv(
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);
44 bool GetActiveAttrib(
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);
81 private:
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 {
92 kES2,
93 kES3UniformBlocks,
94 kES3TransformFeedbackVaryings,
95 kES3Uniformsiv,
96 kNone,
99 // Need GLES2_IMPL_EXPORT for tests.
100 class GLES2_IMPL_EXPORT Program {
101 public:
102 struct UniformInfo {
103 UniformInfo(GLsizei _size, GLenum _type, const std::string& _name);
104 ~UniformInfo();
106 GLsizei size;
107 GLenum type;
108 bool is_array;
109 std::string name;
110 std::vector<GLint> element_locations;
112 struct UniformES3 {
113 UniformES3();
114 ~UniformES3();
116 GLint block_index;
117 GLint offset;
118 GLint array_stride;
119 GLint matrix_stride;
120 GLint is_row_major;
122 struct VertexAttrib {
123 VertexAttrib(GLsizei _size, GLenum _type, const std::string& _name,
124 GLint _location);
125 ~VertexAttrib();
127 GLsizei size;
128 GLenum type;
129 GLint location;
130 std::string name;
132 struct UniformBlock {
133 UniformBlock();
134 ~UniformBlock();
136 GLuint binding;
137 GLuint data_size;
138 std::vector<GLuint> active_uniform_indices;
139 GLboolean referenced_by_vertex_shader;
140 GLboolean referenced_by_fragment_shader;
141 std::string name;
143 struct TransformFeedbackVarying {
144 TransformFeedbackVarying();
145 ~TransformFeedbackVarying();
147 GLsizei size;
148 GLenum type;
149 std::string name;
152 Program();
153 ~Program();
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;
166 bool GetUniformsiv(
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(
181 GLuint index) const;
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;
197 private:
198 bool cached_es2_;
200 GLsizei max_attrib_name_length_;
202 // Attrib by index.
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.
211 bool link_status_;
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_;
246 } // namespace gles2
247 } // namespace gpu
249 #endif // GPU_COMMAND_BUFFER_CLIENT_PROGRAM_INFO_MANAGER_H_