OLD | NEW |
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 RPCShmHandle shm = CreateShm(kShmSize); | 105 RPCShmHandle shm = CreateShm(kShmSize); |
106 void *shm_address = MapShm(shm, kShmSize); | 106 void *shm_address = MapShm(shm, kShmSize); |
107 unsigned int shm_id = proxy.RegisterSharedMemory(shm, kShmSize); | 107 unsigned int shm_id = proxy.RegisterSharedMemory(shm, kShmSize); |
108 | 108 |
109 { | 109 { |
110 CommandBufferHelper cmd_buffer(&proxy); | 110 CommandBufferHelper cmd_buffer(&proxy); |
111 cmd_buffer.Init(500); | 111 cmd_buffer.Init(500); |
112 | 112 |
113 // Clear the buffers. | 113 // Clear the buffers. |
114 RGBA color = {0.2f, 0.2f, 0.2f, 1.f}; | 114 RGBA color = {0.2f, 0.2f, 0.2f, 1.f}; |
115 cmd_buffer.Clear(GAPIInterface::COLOR | GAPIInterface::DEPTH, | 115 cmd_buffer.Clear(command_buffer::kColor | command_buffer::kDepth, |
116 color.red, color.green, color.blue, color.alpha, | 116 color.red, color.green, color.blue, color.alpha, |
117 1.f, 0); | 117 1.f, 0); |
118 | 118 |
119 const ResourceID vertex_buffer_id = 1; | 119 const ResourceId vertex_buffer_id = 1; |
120 const ResourceID vertex_struct_id = 1; | 120 const ResourceId vertex_struct_id = 1; |
121 | 121 |
122 static const CustomVertex vertices[4] = { | 122 static const CustomVertex vertices[4] = { |
123 {-.5f, -.5f, 0.f, 1.f, 0, 0}, | 123 {-.5f, -.5f, 0.f, 1.f, 0, 0}, |
124 {.5f, -.5f, 0.f, 1.f, 1, 0}, | 124 {.5f, -.5f, 0.f, 1.f, 1, 0}, |
125 {-.5f, .5f, 0.f, 1.f, 0, 1}, | 125 {-.5f, .5f, 0.f, 1.f, 0, 1}, |
126 {.5f, .5f, 0.f, 1.f, 1, 1}, | 126 {.5f, .5f, 0.f, 1.f, 1, 1}, |
127 }; | 127 }; |
128 cmd_buffer.CreateVertexBuffer(vertex_buffer_id, sizeof(vertices), 0); | 128 cmd_buffer.CreateVertexBuffer(vertex_buffer_id, sizeof(vertices), |
| 129 vertex_buffer::kNone); |
129 | 130 |
130 memcpy(shm_address, vertices, sizeof(vertices)); | 131 memcpy(shm_address, vertices, sizeof(vertices)); |
131 cmd_buffer.SetVertexBufferData( | 132 cmd_buffer.SetVertexBufferData( |
132 vertex_buffer_id, 0, sizeof(vertices), shm_id, 0); | 133 vertex_buffer_id, 0, sizeof(vertices), shm_id, 0); |
133 unsigned int token = cmd_buffer.InsertToken(); | 134 unsigned int token = cmd_buffer.InsertToken(); |
134 | 135 |
135 cmd_buffer.CreateVertexStruct(vertex_struct_id, 2); | 136 cmd_buffer.CreateVertexStruct(vertex_struct_id, 2); |
136 | 137 |
137 // Set POSITION input stream | 138 // Set POSITION input stream |
138 cmd_buffer.SetVertexInput(vertex_struct_id, 0, vertex_buffer_id, 0, | 139 cmd_buffer.SetVertexInput(vertex_struct_id, 0, vertex_buffer_id, 0, |
139 vertex_struct::POSITION, 0, | 140 vertex_struct::kPosition, 0, |
140 vertex_struct::FLOAT4, sizeof(CustomVertex)); | 141 vertex_struct::kFloat4, sizeof(CustomVertex)); |
141 | 142 |
142 // Set TEXCOORD0 input stream | 143 // Set TEXCOORD0 input stream |
143 cmd_buffer.SetVertexInput(vertex_struct_id, 1, vertex_buffer_id, 16, | 144 cmd_buffer.SetVertexInput(vertex_struct_id, 1, vertex_buffer_id, 16, |
144 vertex_struct::TEX_COORD, 0, | 145 vertex_struct::kTexCoord, 0, |
145 vertex_struct::FLOAT2, sizeof(CustomVertex)); | 146 vertex_struct::kFloat2, sizeof(CustomVertex)); |
146 | 147 |
147 // wait for previous transfer to be executed, so that we can re-use the | 148 // wait for previous transfer to be executed, so that we can re-use the |
148 // transfer shared memory buffer. | 149 // transfer shared memory buffer. |
149 cmd_buffer.WaitForToken(token); | 150 cmd_buffer.WaitForToken(token); |
150 memcpy(shm_address, effect_data, sizeof(effect_data)); | 151 memcpy(shm_address, effect_data, sizeof(effect_data)); |
151 const ResourceID effect_id = 1; | 152 const ResourceId effect_id = 1; |
152 cmd_buffer.CreateEffect(effect_id, sizeof(effect_data), shm_id, 0); | 153 cmd_buffer.CreateEffect(effect_id, sizeof(effect_data), shm_id, 0); |
153 token = cmd_buffer.InsertToken(); | 154 token = cmd_buffer.InsertToken(); |
154 | 155 |
155 // Create a 4x4 2D texture. | 156 // Create a 4x4 2D texture. |
156 const ResourceID texture_id = 1; | 157 const ResourceId texture_id = 1; |
157 cmd_buffer.CreateTexture2d(texture_id, 4, 4, 1, texture::ARGB8, 0); | 158 cmd_buffer.CreateTexture2d(texture_id, 4, 4, 1, texture::kARGB8, 0); |
158 | 159 |
159 static const unsigned int texels[4] = { | 160 static const unsigned int texels[4] = { |
160 0xff0000ff, | 161 0xff0000ff, |
161 0xffff00ff, | 162 0xffff00ff, |
162 0xff00ffff, | 163 0xff00ffff, |
163 0xffffffff, | 164 0xffffffff, |
164 }; | 165 }; |
165 // wait for previous transfer to be executed, so that we can re-use the | 166 // wait for previous transfer to be executed, so that we can re-use the |
166 // transfer shared memory buffer. | 167 // transfer shared memory buffer. |
167 cmd_buffer.WaitForToken(token); | 168 cmd_buffer.WaitForToken(token); |
168 memcpy(shm_address, texels, sizeof(texels)); | 169 memcpy(shm_address, texels, sizeof(texels)); |
169 // Creates a 4x4 texture by uploading 2x2 data in each quadrant. | 170 // Creates a 4x4 texture by uploading 2x2 data in each quadrant. |
170 for (unsigned int x = 0; x < 2; ++x) | 171 for (unsigned int x = 0; x < 2; ++x) |
171 for (unsigned int y = 0; y < 2; ++y) { | 172 for (unsigned int y = 0; y < 2; ++y) { |
172 cmd_buffer.SetTextureData(texture_id, x * 2, y * 2, 0, 2, 2, 1, 0, 0, | 173 cmd_buffer.SetTextureData(texture_id, x * 2, y * 2, 0, 2, 2, 1, 0, |
| 174 texture::kFaceNone, |
173 sizeof(texels[0]) * 2, // row_pitch | 175 sizeof(texels[0]) * 2, // row_pitch |
174 0, // slice_pitch | 176 0, // slice_pitch |
175 sizeof(texels), // size | 177 sizeof(texels), // size |
176 shm_id, | 178 shm_id, |
177 0); | 179 0); |
178 } | 180 } |
179 token = cmd_buffer.InsertToken(); | 181 token = cmd_buffer.InsertToken(); |
180 | 182 |
181 const ResourceID sampler_id = 1; | 183 const ResourceId sampler_id = 1; |
182 cmd_buffer.CreateSampler(sampler_id); | 184 cmd_buffer.CreateSampler(sampler_id); |
183 cmd_buffer.SetSamplerTexture(sampler_id, texture_id); | 185 cmd_buffer.SetSamplerTexture(sampler_id, texture_id); |
184 cmd_buffer.SetSamplerStates(sampler_id, | 186 cmd_buffer.SetSamplerStates(sampler_id, |
185 sampler::CLAMP_TO_EDGE, | 187 sampler::kClampToEdge, |
186 sampler::CLAMP_TO_EDGE, | 188 sampler::kClampToEdge, |
187 sampler::CLAMP_TO_EDGE, | 189 sampler::kClampToEdge, |
188 sampler::POINT, | 190 sampler::kPoint, |
189 sampler::POINT, | 191 sampler::kPoint, |
190 sampler::NONE, | 192 sampler::kNone, |
191 1); | 193 1); |
192 | 194 |
193 // Create a parameter for the sampler. | 195 // Create a parameter for the sampler. |
194 const ResourceID sampler_param_id = 1; | 196 const ResourceId sampler_param_id = 1; |
195 { | 197 { |
196 static const char param_name[] = "s0"; | 198 static const char param_name[] = "s0"; |
197 cmd_buffer.CreateParamByNameImmediate(sampler_param_id, effect_id, | 199 cmd_buffer.CreateParamByNameImmediate(sampler_param_id, effect_id, |
198 sizeof(param_name), param_name); | 200 sizeof(param_name), param_name); |
199 } | 201 } |
200 | 202 |
201 const ResourceID matrix_param_id = 2; | 203 const ResourceId matrix_param_id = 2; |
202 { | 204 { |
203 static const char param_name[] = "worldViewProj"; | 205 static const char param_name[] = "worldViewProj"; |
204 cmd_buffer.CreateParamByNameImmediate(matrix_param_id, effect_id, | 206 cmd_buffer.CreateParamByNameImmediate(matrix_param_id, effect_id, |
205 sizeof(param_name), param_name); | 207 sizeof(param_name), param_name); |
206 } | 208 } |
207 | 209 |
208 float t = 0.f; | 210 float t = 0.f; |
209 while (true) { | 211 while (true) { |
210 t = fmodf(t + .01f, 1.f); | 212 t = fmodf(t + .01f, 1.f); |
211 math::Matrix4 m = | 213 math::Matrix4 m = |
212 math::Matrix4::translation(math::Vector3(0.f, 0.f, .5f)); | 214 math::Matrix4::translation(math::Vector3(0.f, 0.f, .5f)); |
213 m *= math::Matrix4::rotationY(t * 2 * 3.1415926f); | 215 m *= math::Matrix4::rotationY(t * 2 * 3.1415926f); |
214 cmd_buffer.BeginFrame(); | 216 cmd_buffer.BeginFrame(); |
215 // Clear the background with an animated color (black to red). | 217 // Clear the background with an animated color (black to red). |
216 cmd_buffer.Clear(GAPIInterface::COLOR | GAPIInterface::DEPTH, | 218 cmd_buffer.Clear(command_buffer::kColor | command_buffer::kDepth, |
217 color.red, color.green, color.blue, color.alpha, | 219 color.red, color.green, color.blue, color.alpha, |
218 1.f, 0); | 220 1.f, 0); |
219 | 221 |
220 cmd_buffer.SetVertexStruct(vertex_struct_id); | 222 cmd_buffer.SetVertexStruct(vertex_struct_id); |
221 cmd_buffer.SetEffect(effect_id); | 223 cmd_buffer.SetEffect(effect_id); |
222 cmd_buffer.SetParamDataImmediate( | 224 cmd_buffer.SetParamDataImmediate( |
223 sampler_param_id, sizeof(uint32), &sampler_id); // NOLINT | 225 sampler_param_id, sizeof(uint32), &sampler_id); // NOLINT |
224 cmd_buffer.SetParamDataImmediate( | 226 cmd_buffer.SetParamDataImmediate( |
225 matrix_param_id, sizeof(m), &m); | 227 matrix_param_id, sizeof(m), &m); |
226 cmd_buffer.Draw(GAPIInterface::TRIANGLE_STRIPS, 0, 2); | 228 cmd_buffer.Draw(command_buffer::kTriangleStrips, 0, 2); |
227 | 229 |
228 cmd_buffer.EndFrame(); | 230 cmd_buffer.EndFrame(); |
229 cmd_buffer.Flush(); | 231 cmd_buffer.Flush(); |
230 } | 232 } |
231 | 233 |
232 cmd_buffer.Finish(); | 234 cmd_buffer.Finish(); |
233 } | 235 } |
234 | 236 |
235 proxy.CloseConnection(); | 237 proxy.CloseConnection(); |
236 proxy.UnregisterSharedMemory(shm_id); | 238 proxy.UnregisterSharedMemory(shm_id); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 int main(int argc, char **argv) { | 291 int main(int argc, char **argv) { |
290 nacl::HtpHandle htp_handle = InitConnection(argc, argv); | 292 nacl::HtpHandle htp_handle = InitConnection(argc, argv); |
291 if (htp_handle == nacl::kInvalidHtpHandle) { | 293 if (htp_handle == nacl::kInvalidHtpHandle) { |
292 return 1; | 294 return 1; |
293 } | 295 } |
294 | 296 |
295 o3d::command_buffer::BigTestClient(htp_handle); | 297 o3d::command_buffer::BigTestClient(htp_handle); |
296 CloseConnection(htp_handle); | 298 CloseConnection(htp_handle); |
297 return 0; | 299 return 0; |
298 } | 300 } |
OLD | NEW |