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

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

Issue 212018: Change command buffer client code to use structures.... (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/effect_cb.cc ('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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 static const unsigned int kEntryCount =
74 (sizeof(typename T::DataType) + 3) / 4;
75 CommandBufferEntry args[2 + kEntryCount];
76 typename T::DataType value = param_->value(); 73 typename T::DataType value = param_->value();
77 args[0].value_uint32 = id_; 74 helper->SetParamDataImmediate(id_, sizeof(value), &value);
78 args[1].value_uint32 = sizeof(value);
79 memcpy(args + 2, &value, sizeof(value));
80 helper->AddCommand(command_buffer::SET_PARAM_DATA_IMMEDIATE,
81 2 + kEntryCount, args);
82 } 75 }
83 private: 76 private:
84 T* param_; 77 T* param_;
85 ResourceID id_; 78 ResourceID id_;
86 }; 79 };
87 80
88 // 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
89 // TypedParamHandlerCB<ParamMatrix4> works for row major, and we make a new 82 // TypedParamHandlerCB<ParamMatrix4> works for row major, and we make a new
90 // class for column major. 83 // class for column major.
91 typedef TypedParamHandlerCB<ParamMatrix4> MatrixParamHandlerRowsCB; 84 typedef TypedParamHandlerCB<ParamMatrix4> MatrixParamHandlerRowsCB;
92 85
93 class MatrixParamHandlerColumnsCB : public ParamHandlerCB { 86 class MatrixParamHandlerColumnsCB : public ParamHandlerCB {
94 public: 87 public:
95 MatrixParamHandlerColumnsCB(ParamMatrix4* param, ResourceID id) 88 MatrixParamHandlerColumnsCB(ParamMatrix4* param, ResourceID id)
96 : param_(param), 89 : param_(param),
97 id_(id) { 90 id_(id) {
98 } 91 }
99 92
100 // Sends the param value to the service. 93 // Sends the param value to the service.
101 virtual void SetValue(CommandBufferHelper *helper) { 94 virtual void SetValue(CommandBufferHelper *helper) {
102 CommandBufferEntry args[18];
103 Matrix4 value = transpose(param_->value()); 95 Matrix4 value = transpose(param_->value());
104 args[0].value_uint32 = id_; 96 helper->SetParamDataImmediate(id_, sizeof(value), &value);
105 args[1].value_uint32 = sizeof(value);
106 memcpy(args + 2, &value, sizeof(value));
107 helper->AddCommand(command_buffer::SET_PARAM_DATA_IMMEDIATE, 18, args);
108 } 97 }
109 private: 98 private:
110 ParamMatrix4* param_; 99 ParamMatrix4* param_;
111 ResourceID id_; 100 ResourceID id_;
112 }; 101 };
113 102
114 class SamplerParamHandlerCB : public ParamHandlerCB { 103 class SamplerParamHandlerCB : public ParamHandlerCB {
115 public: 104 public:
116 SamplerParamHandlerCB(ParamSampler* param, ResourceID id) 105 SamplerParamHandlerCB(ParamSampler* param, ResourceID id)
117 : param_(param), 106 : param_(param),
118 id_(id) { 107 id_(id) {
119 } 108 }
120 109
121 // Sends the param value to the service. 110 // Sends the param value to the service.
122 virtual void SetValue(CommandBufferHelper *helper) { 111 virtual void SetValue(CommandBufferHelper *helper) {
123 SamplerCB *sampler = down_cast<SamplerCB *>(param_->value()); 112 SamplerCB *sampler = down_cast<SamplerCB *>(param_->value());
124 CommandBufferEntry args[3]; 113 uint32 value;
125 args[0].value_uint32 = id_;
126 args[1].value_uint32 = sizeof(ResourceID);
127 if (!sampler) { 114 if (!sampler) {
128 // TODO: use error sampler 115 // TODO: use error sampler
129 args[2].value_uint32 = command_buffer::kInvalidResource; 116 value = command_buffer::kInvalidResource;
130 } else { 117 } else {
131 sampler->SetTextureAndStates(); 118 sampler->SetTextureAndStates();
132 args[2].value_uint32 = sampler->resource_id(); 119 value = sampler->resource_id();
133 } 120 }
134 helper->AddCommand(command_buffer::SET_PARAM_DATA_IMMEDIATE, 3, args); 121 helper->SetParamDataImmediate(id_, sizeof(value), &value);
135 } 122 }
136 private: 123 private:
137 ParamSampler* param_; 124 ParamSampler* param_;
138 ResourceID id_; 125 ResourceID id_;
139 }; 126 };
140 127
141 static ParamHandlerCB *GetHandlerFromParamAndDesc( 128 static ParamHandlerCB *GetHandlerFromParamAndDesc(
142 Param *param, 129 Param *param,
143 const EffectHelper::EffectParamDesc &desc, 130 const EffectHelper::EffectParamDesc &desc,
144 Effect::MatrixLoadOrder matrix_load_order) { 131 Effect::MatrixLoadOrder matrix_load_order) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 handlers_.clear(); 277 handlers_.clear();
291 } 278 }
292 279
293 void ParamCacheCB::RunHandlers(CommandBufferHelper *helper) { 280 void ParamCacheCB::RunHandlers(CommandBufferHelper *helper) {
294 for (unsigned int i = 0; i < handlers_.size(); ++i) { 281 for (unsigned int i = 0; i < handlers_.size(); ++i) {
295 handlers_[i]->SetValue(helper); 282 handlers_[i]->SetValue(helper);
296 } 283 }
297 } 284 }
298 285
299 } // namespace o3d 286 } // namespace o3d
OLDNEW
« no previous file with comments | « core/cross/command_buffer/effect_cb.cc ('k') | core/cross/command_buffer/primitive_cb.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698