Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: core/cross/command_buffer/param_cache_cb.cc

Issue 234002: More work in Command Buffers... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « core/cross/command_buffer/param_cache_cb.h ('k') | core/cross/command_buffer/primitive_cb.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2009, Google Inc. 2 * Copyright 2009, Google Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 29 matching lines...) Expand all
40 #include "core/cross/command_buffer/param_cache_cb.h" 40 #include "core/cross/command_buffer/param_cache_cb.h"
41 #include "core/cross/command_buffer/sampler_cb.h" 41 #include "core/cross/command_buffer/sampler_cb.h"
42 #include "command_buffer/common/cross/cmd_buffer_format.h" 42 #include "command_buffer/common/cross/cmd_buffer_format.h"
43 #include "command_buffer/client/cross/cmd_buffer_helper.h" 43 #include "command_buffer/client/cross/cmd_buffer_helper.h"
44 44
45 namespace o3d { 45 namespace o3d {
46 46
47 using command_buffer::CommandBufferEntry; 47 using command_buffer::CommandBufferEntry;
48 using command_buffer::CommandBufferHelper; 48 using command_buffer::CommandBufferHelper;
49 using command_buffer::EffectHelper; 49 using command_buffer::EffectHelper;
50 using command_buffer::ResourceID; 50 using command_buffer::ResourceId;
51 namespace effect_param = command_buffer::effect_param; 51 namespace effect_param = command_buffer::effect_param;
52 52
53 // Base class for ParamHandlers. 53 // Base class for ParamHandlers.
54 class ParamHandlerCB { 54 class ParamHandlerCB {
55 public: 55 public:
56 virtual ~ParamHandlerCB() {} 56 virtual ~ParamHandlerCB() {}
57 virtual void SetValue(CommandBufferHelper *helper) = 0; 57 virtual void SetValue(CommandBufferHelper *helper) = 0;
58 }; 58 };
59 59
60 // Template implementation of ParamHandlerCB. 60 // Template implementation of ParamHandlerCB.
61 template <typename T> 61 template <typename T>
62 class TypedParamHandlerCB : public ParamHandlerCB { 62 class TypedParamHandlerCB : public ParamHandlerCB {
63 public: 63 public:
64 TypedParamHandlerCB(T* param, ResourceID id) 64 TypedParamHandlerCB(T* param, ResourceId id)
65 : param_(param), 65 : param_(param),
66 id_(id) { 66 id_(id) {
67 } 67 }
68 68
69 // Sends the param value to the service. 69 // Sends the param value to the service.
70 // This template definition only works for value types (floatn, matrix, int, 70 // This template definition only works for value types (floatn, matrix, int,
71 // ..., but not textures or samplers). 71 // ..., but not textures or samplers).
72 virtual void SetValue(CommandBufferHelper *helper) { 72 virtual void SetValue(CommandBufferHelper *helper) {
73 typename T::DataType value = param_->value(); 73 typename T::DataType value = param_->value();
74 helper->SetParamDataImmediate(id_, sizeof(value), &value); 74 helper->SetParamDataImmediate(id_, sizeof(value), &value);
75 } 75 }
76 private: 76 private:
77 T* param_; 77 T* param_;
78 ResourceID id_; 78 ResourceId id_;
79 }; 79 };
80 80
81 // Matrices are expected in row major order in the command buffer, so 81 // Matrices are expected in row major order in the command buffer, so
82 // TypedParamHandlerCB<ParamMatrix4> works for row major, and we make a new 82 // TypedParamHandlerCB<ParamMatrix4> works for row major, and we make a new
83 // class for column major. 83 // class for column major.
84 typedef TypedParamHandlerCB<ParamMatrix4> MatrixParamHandlerRowsCB; 84 typedef TypedParamHandlerCB<ParamMatrix4> MatrixParamHandlerRowsCB;
85 85
86 class MatrixParamHandlerColumnsCB : public ParamHandlerCB { 86 class MatrixParamHandlerColumnsCB : public ParamHandlerCB {
87 public: 87 public:
88 MatrixParamHandlerColumnsCB(ParamMatrix4* param, ResourceID id) 88 MatrixParamHandlerColumnsCB(ParamMatrix4* param, ResourceId id)
89 : param_(param), 89 : param_(param),
90 id_(id) { 90 id_(id) {
91 } 91 }
92 92
93 // Sends the param value to the service. 93 // Sends the param value to the service.
94 virtual void SetValue(CommandBufferHelper *helper) { 94 virtual void SetValue(CommandBufferHelper *helper) {
95 Matrix4 value = transpose(param_->value()); 95 Matrix4 value = transpose(param_->value());
96 helper->SetParamDataImmediate(id_, sizeof(value), &value); 96 helper->SetParamDataImmediate(id_, sizeof(value), &value);
97 } 97 }
98 private: 98 private:
99 ParamMatrix4* param_; 99 ParamMatrix4* param_;
100 ResourceID id_; 100 ResourceId id_;
101 }; 101 };
102 102
103 class SamplerParamHandlerCB : public ParamHandlerCB { 103 class SamplerParamHandlerCB : public ParamHandlerCB {
104 public: 104 public:
105 SamplerParamHandlerCB(ParamSampler* param, ResourceID id) 105 SamplerParamHandlerCB(ParamSampler* param, ResourceId id)
106 : param_(param), 106 : param_(param),
107 id_(id) { 107 id_(id) {
108 } 108 }
109 109
110 // Sends the param value to the service. 110 // Sends the param value to the service.
111 virtual void SetValue(CommandBufferHelper *helper) { 111 virtual void SetValue(CommandBufferHelper *helper) {
112 SamplerCB *sampler = down_cast<SamplerCB *>(param_->value()); 112 SamplerCB *sampler = down_cast<SamplerCB *>(param_->value());
113 uint32 value; 113 uint32 value;
114 if (!sampler) { 114 if (!sampler) {
115 // TODO: use error sampler 115 // TODO: use error sampler
116 value = command_buffer::kInvalidResource; 116 value = command_buffer::kInvalidResource;
117 } else { 117 } else {
118 sampler->SetTextureAndStates(); 118 sampler->SetTextureAndStates();
119 value = sampler->resource_id(); 119 value = sampler->resource_id();
120 } 120 }
121 helper->SetParamDataImmediate(id_, sizeof(value), &value); 121 helper->SetParamDataImmediate(id_, sizeof(value), &value);
122 } 122 }
123 private: 123 private:
124 ParamSampler* param_; 124 ParamSampler* param_;
125 ResourceID id_; 125 ResourceId id_;
126 }; 126 };
127 127
128 static ParamHandlerCB *GetHandlerFromParamAndDesc( 128 static ParamHandlerCB *GetHandlerFromParamAndDesc(
129 Param *param, 129 Param *param,
130 const EffectHelper::EffectParamDesc &desc, 130 const EffectHelper::EffectParamDesc &desc,
131 Effect::MatrixLoadOrder matrix_load_order) { 131 Effect::MatrixLoadOrder matrix_load_order) {
132 switch (desc.data_type) { 132 switch (desc.data_type) {
133 case effect_param::MATRIX4: 133 case effect_param::kMatrix4:
134 if (param->IsA(ParamMatrix4::GetApparentClass())) { 134 if (param->IsA(ParamMatrix4::GetApparentClass())) {
135 DCHECK_EQ(sizeof(ParamMatrix4::DataType), desc.data_size); 135 DCHECK_EQ(sizeof(ParamMatrix4::DataType), desc.data_size);
136 ParamMatrix4 *matrix_param = down_cast<ParamMatrix4*>(param); 136 ParamMatrix4 *matrix_param = down_cast<ParamMatrix4*>(param);
137 if (matrix_load_order == Effect::ROW_MAJOR) { 137 if (matrix_load_order == Effect::ROW_MAJOR) {
138 return new MatrixParamHandlerRowsCB(matrix_param, desc.id); 138 return new MatrixParamHandlerRowsCB(matrix_param, desc.id);
139 } else { 139 } else {
140 return new MatrixParamHandlerColumnsCB(matrix_param, desc.id); 140 return new MatrixParamHandlerColumnsCB(matrix_param, desc.id);
141 } 141 }
142 } 142 }
143 break; 143 break;
144 case effect_param::FLOAT1: 144 case effect_param::kFloat1:
145 if (param->IsA(ParamFloat::GetApparentClass())) { 145 if (param->IsA(ParamFloat::GetApparentClass())) {
146 DCHECK_EQ(sizeof(ParamFloat::DataType), desc.data_size); 146 DCHECK_EQ(sizeof(ParamFloat::DataType), desc.data_size);
147 return new TypedParamHandlerCB<ParamFloat>( 147 return new TypedParamHandlerCB<ParamFloat>(
148 down_cast<ParamFloat*>(param), desc.id); 148 down_cast<ParamFloat*>(param), desc.id);
149 } 149 }
150 break; 150 break;
151 case effect_param::FLOAT2: 151 case effect_param::kFloat2:
152 if (param->IsA(ParamFloat2::GetApparentClass())) { 152 if (param->IsA(ParamFloat2::GetApparentClass())) {
153 DCHECK_EQ(sizeof(ParamFloat2::DataType), desc.data_size); 153 DCHECK_EQ(sizeof(ParamFloat2::DataType), desc.data_size);
154 return new TypedParamHandlerCB<ParamFloat2>( 154 return new TypedParamHandlerCB<ParamFloat2>(
155 down_cast<ParamFloat2*>(param), desc.id); 155 down_cast<ParamFloat2*>(param), desc.id);
156 } 156 }
157 break; 157 break;
158 case effect_param::FLOAT3: 158 case effect_param::kFloat3:
159 if (param->IsA(ParamFloat3::GetApparentClass())) { 159 if (param->IsA(ParamFloat3::GetApparentClass())) {
160 DCHECK_EQ(sizeof(ParamFloat3::DataType), desc.data_size); 160 DCHECK_EQ(sizeof(ParamFloat3::DataType), desc.data_size);
161 return new TypedParamHandlerCB<ParamFloat3>( 161 return new TypedParamHandlerCB<ParamFloat3>(
162 down_cast<ParamFloat3*>(param), desc.id); 162 down_cast<ParamFloat3*>(param), desc.id);
163 } 163 }
164 break; 164 break;
165 case effect_param::FLOAT4: 165 case effect_param::kFloat4:
166 if (param->IsA(ParamFloat4::GetApparentClass())) { 166 if (param->IsA(ParamFloat4::GetApparentClass())) {
167 DCHECK_EQ(sizeof(ParamFloat4::DataType), desc.data_size); 167 DCHECK_EQ(sizeof(ParamFloat4::DataType), desc.data_size);
168 return new TypedParamHandlerCB<ParamFloat4>( 168 return new TypedParamHandlerCB<ParamFloat4>(
169 down_cast<ParamFloat4*>(param), desc.id); 169 down_cast<ParamFloat4*>(param), desc.id);
170 } 170 }
171 break; 171 break;
172 case effect_param::INT: 172 case effect_param::kInt:
173 if (param->IsA(ParamInteger::GetApparentClass())) { 173 if (param->IsA(ParamInteger::GetApparentClass())) {
174 DCHECK_EQ(sizeof(ParamInteger::DataType), desc.data_size); 174 DCHECK_EQ(sizeof(ParamInteger::DataType), desc.data_size);
175 return new TypedParamHandlerCB<ParamInteger>( 175 return new TypedParamHandlerCB<ParamInteger>(
176 down_cast<ParamInteger*>(param), desc.id); 176 down_cast<ParamInteger*>(param), desc.id);
177 } 177 }
178 break; 178 break;
179 case effect_param::BOOL: 179 case effect_param::kBool:
180 if (param->IsA(ParamBoolean::GetApparentClass())) { 180 if (param->IsA(ParamBoolean::GetApparentClass())) {
181 DCHECK_EQ(sizeof(ParamBoolean::DataType), desc.data_size); 181 DCHECK_EQ(sizeof(ParamBoolean::DataType), desc.data_size);
182 return new TypedParamHandlerCB<ParamBoolean>( 182 return new TypedParamHandlerCB<ParamBoolean>(
183 down_cast<ParamBoolean*>(param), desc.id); 183 down_cast<ParamBoolean*>(param), desc.id);
184 } 184 }
185 break; 185 break;
186 case effect_param::SAMPLER: 186 case effect_param::kSampler:
187 if (param->IsA(ParamSampler::GetApparentClass())) { 187 if (param->IsA(ParamSampler::GetApparentClass())) {
188 DCHECK_EQ(sizeof(ResourceID), desc.data_size); 188 DCHECK_EQ(sizeof(ResourceId), desc.data_size);
189 return new SamplerParamHandlerCB(down_cast<ParamSampler*>(param), 189 return new SamplerParamHandlerCB(down_cast<ParamSampler*>(param),
190 desc.id); 190 desc.id);
191 } 191 }
192 break; 192 break;
193 default: 193 default:
194 break; 194 break;
195 } 195 }
196 // Do not report an error, it may be valid that the Param didn't match the 196 // Do not report an error, it may be valid that the Param didn't match the
197 // desc, we may still be looking for another match in other nodes. 197 // desc, we may still be looking for another match in other nodes.
198 return NULL; 198 return NULL;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 handlers_.clear(); 277 handlers_.clear();
278 } 278 }
279 279
280 void ParamCacheCB::RunHandlers(CommandBufferHelper *helper) { 280 void ParamCacheCB::RunHandlers(CommandBufferHelper *helper) {
281 for (unsigned int i = 0; i < handlers_.size(); ++i) { 281 for (unsigned int i = 0; i < handlers_.size(); ++i) {
282 handlers_[i]->SetValue(helper); 282 handlers_[i]->SetValue(helper);
283 } 283 }
284 } 284 }
285 285
286 } // namespace o3d 286 } // namespace o3d
OLDNEW
« no previous file with comments | « core/cross/command_buffer/param_cache_cb.h ('k') | core/cross/command_buffer/primitive_cb.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698