45 static const Uniform CombineMatrices(
const Uniform& old_value,
46 const Uniform& new_value) {
53 Uniform result = old_value;
54 result.SetValue(m0 * m1);
68 class ShaderInputRegistry::StaticData {
72 : registry_count_(0), largest_registry_size_(0) {}
75 int32_t GetRegistryCount()
const {
76 return registry_count_;
80 int32_t GetUniqueId()
const {
81 return ++registry_count_;
85 int32_t GetLargestRegistrySize()
const {
86 return largest_registry_size_;
91 void UpdateLargestRegistrySize(int32_t size)
const {
92 int32_t largest_size = largest_registry_size_.load();
93 bool succeeded =
false;
97 while (size > largest_size && !succeeded) {
98 succeeded = largest_registry_size_.compare_exchange_strong(
106 mutable std::atomic<int32_t> registry_count_;
109 mutable std::atomic<int32_t> largest_registry_size_;
120 class ShaderInputRegistry::StaticGlobalRegistryData {
123 StaticGlobalRegistryData()
138 global_registry_->Add(
UniformSpec(
"uModelviewMatrix",
140 "Cumulative modelview matrix.",
148 return global_registry_;
165 : uniform_specs_(kUniformAdded,
168 attribute_specs_(*this),
171 id_ = GetStaticData()->GetUniqueId();
178 const SpecMapType::const_iterator it = spec_map_.find(name);
179 if (it == spec_map_.end()) {
181 const size_t num_includes = includes_.size();
182 for (
size_t i = 0; i < num_includes; ++i)
198 if (reg.
Get() ==
this) {
199 LOG(
ERROR) <<
"Can't include registry " << reg->GetId() <<
" in registry "
200 <<
GetId() <<
" because a registry cannot include itself";
207 for (SpecMapType::const_iterator it = specs.begin(); it != specs.end();
209 if (reg->Contains(it->first)) {
210 LOG(
ERROR) <<
"Can't include registry " << reg->GetId() <<
" in registry "
211 <<
GetId() <<
" because they or their includes both define the"
212 <<
" shader input '" << it->first <<
"'";
217 includes_.push_back(reg);
226 bool duplicates_found =
false;
228 const size_t num_includes = includes_.size();
229 for (
size_t i = 0; i < num_includes; ++i) {
230 const SpecMapType& included_specs = includes_[i]->GetAllSpecEntries();
232 for (SpecMapType::const_iterator it = included_specs.begin();
233 it != included_specs.end(); ++it) {
234 if (specs.count(it->first)) {
235 LOG(
WARNING) <<
"Registry " << specs[it->first].registry_id
236 <<
" defines duplicate input '" << it->first <<
"' which"
237 <<
" is also defined in registry "
238 << it->second.registry_id;
239 duplicates_found =
true;
242 specs.insert(included_specs.begin(), included_specs.end());
244 return !duplicates_found;
248 ShaderInputRegistry::GetMutableSpecs() {
249 return &attribute_specs_;
253 ShaderInputRegistry::GetMutableSpecs() {
254 return uniform_specs_.GetMutable();
258 ShaderInputRegistry::GetAllSpecEntries()
const {
259 SpecMapType specs = spec_map_;
260 const size_t num_includes = includes_.size();
261 for (
size_t i = 0; i < num_includes; ++i) {
262 const SpecMapType& included_specs = includes_[i]->GetAllSpecEntries();
263 specs.insert(included_specs.begin(), included_specs.end());
269 ION_API
const base::AllocDeque<ShaderInputRegistry::AttributeSpec>&
271 return attribute_specs_;
277 return uniform_specs_.Get();
281 return GetStaticGlobalRegistryData()->GetGlobalRegistry();
284 void ShaderInputRegistry::UpdateLargestRegistrySize(
size_t size) {
285 GetStaticData()->UpdateLargestRegistrySize(static_cast<int32_t>(size));
288 ShaderInputRegistry::StaticData* ShaderInputRegistry::GetStaticData() {
290 return s_static_data;
293 ShaderInputRegistry::StaticGlobalRegistryData*
294 ShaderInputRegistry::GetStaticGlobalRegistryData() {
296 s_static_registry_data);
297 return s_static_registry_data;
Matrix< 4, float > Matrix4f
#define ION_DECLARE_SAFE_STATIC_POINTER(type, variable)
Declare a static non-array pointer and calls a default constructor.
#define LOG(severity)
Logs the streamed message unconditionally with a severity of severity.
T * Get() const
Returns a raw pointer to the instance, which may be NULL.
This class can be used in place of std::deque to allow an Ion Allocator to be used for memory allocat...
#define DCHECK_EQ(val1, val2)
base::ReferentPtr< ShaderInputRegistry >::Type ShaderInputRegistryPtr
Convenience typedef for shared pointer to a ShaderInputRegistry.
kLongTerm is used for objects that have persistent lifetimes, such as managers.
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...