| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 // Release the back-buffer references. | 175 // Release the back-buffer references. |
| 176 back_buffer_surface_ = NULL; | 176 back_buffer_surface_ = NULL; |
| 177 back_buffer_depth_surface_ = NULL; | 177 back_buffer_depth_surface_ = NULL; |
| 178 } | 178 } |
| 179 | 179 |
| 180 // Clears the selected buffers. | 180 // Clears the selected buffers. |
| 181 void GAPID3D9::Clear(unsigned int buffers, | 181 void GAPID3D9::Clear(unsigned int buffers, |
| 182 const RGBA &color, | 182 const RGBA &color, |
| 183 float depth, | 183 float depth, |
| 184 unsigned int stencil) { | 184 unsigned int stencil) { |
| 185 DWORD flags = (buffers & COLOR ? D3DCLEAR_TARGET : 0) | | 185 DWORD flags = (buffers & kColor ? D3DCLEAR_TARGET : 0) | |
| 186 (buffers & DEPTH ? D3DCLEAR_ZBUFFER : 0) | | 186 (buffers & kDepth ? D3DCLEAR_ZBUFFER : 0) | |
| 187 (buffers & STENCIL ? D3DCLEAR_STENCIL : 0); | 187 (buffers & kStencil ? D3DCLEAR_STENCIL : 0); |
| 188 HR(d3d_device_->Clear(0, | 188 HR(d3d_device_->Clear(0, |
| 189 NULL, | 189 NULL, |
| 190 flags, | 190 flags, |
| 191 D3DCOLOR_COLORVALUE(color.red, | 191 D3DCOLOR_COLORVALUE(color.red, |
| 192 color.green, | 192 color.green, |
| 193 color.blue, | 193 color.blue, |
| 194 color.alpha), | 194 color.alpha), |
| 195 depth, | 195 depth, |
| 196 stencil)); | 196 stencil)); |
| 197 } | 197 } |
| 198 | 198 |
| 199 // Sets the viewport. | 199 // Sets the viewport. |
| 200 void GAPID3D9::SetViewport(unsigned int x, | 200 void GAPID3D9::SetViewport(unsigned int x, |
| 201 unsigned int y, | 201 unsigned int y, |
| 202 unsigned int width, | 202 unsigned int width, |
| 203 unsigned int height, | 203 unsigned int height, |
| 204 float z_min, | 204 float z_min, |
| 205 float z_max) { | 205 float z_max) { |
| 206 D3DVIEWPORT9 viewport = {x, y, width, height, z_min, z_max}; | 206 D3DVIEWPORT9 viewport = {x, y, width, height, z_min, z_max}; |
| 207 HR(d3d_device_->SetViewport(&viewport)); | 207 HR(d3d_device_->SetViewport(&viewport)); |
| 208 } | 208 } |
| 209 | 209 |
| 210 // Converts an unsigned int RGBA color into an unsigned int ARGB (DirectX) | 210 // Converts an unsigned int RGBA color into an unsigned int ARGB (DirectX) |
| 211 // color. | 211 // color. |
| 212 static unsigned int RGBAToARGB(unsigned int rgba) { | 212 static unsigned int RGBAToARGB(unsigned int rgba) { |
| 213 return (rgba >> 8) | (rgba << 24); | 213 return (rgba >> 8) | (rgba << 24); |
| 214 } | 214 } |
| 215 | 215 |
| 216 // Sets the current VertexStruct. Just keep track of the ID. | 216 // Sets the current VertexStruct. Just keep track of the ID. |
| 217 BufferSyncInterface::ParseError GAPID3D9::SetVertexStruct(ResourceID id) { | 217 BufferSyncInterface::ParseError GAPID3D9::SetVertexStruct(ResourceId id) { |
| 218 current_vertex_struct_ = id; | 218 current_vertex_struct_ = id; |
| 219 validate_streams_ = true; | 219 validate_streams_ = true; |
| 220 return BufferSyncInterface::kParseNoError; | 220 return BufferSyncInterface::kParseNoError; |
| 221 } | 221 } |
| 222 | 222 |
| 223 // Sets in D3D the input streams of the current vertex struct. | 223 // Sets in D3D the input streams of the current vertex struct. |
| 224 bool GAPID3D9::ValidateStreams() { | 224 bool GAPID3D9::ValidateStreams() { |
| 225 DCHECK(validate_streams_); | 225 DCHECK(validate_streams_); |
| 226 VertexStructD3D9 *vertex_struct = vertex_structs_.Get(current_vertex_struct_); | 226 VertexStructD3D9 *vertex_struct = vertex_structs_.Get(current_vertex_struct_); |
| 227 if (!vertex_struct) { | 227 if (!vertex_struct) { |
| 228 LOG(ERROR) << "Drawing with invalid streams."; | 228 LOG(ERROR) << "Drawing with invalid streams."; |
| 229 return false; | 229 return false; |
| 230 } | 230 } |
| 231 max_vertices_ = vertex_struct->SetStreams(this); | 231 max_vertices_ = vertex_struct->SetStreams(this); |
| 232 validate_streams_ = false; | 232 validate_streams_ = false; |
| 233 return max_vertices_ > 0; | 233 return max_vertices_ > 0; |
| 234 } | 234 } |
| 235 | 235 |
| 236 // Converts a GAPID3D9::PrimitiveType to a D3DPRIMITIVETYPE. | 236 // Converts a GAPID3D9::PrimitiveType to a D3DPRIMITIVETYPE. |
| 237 static D3DPRIMITIVETYPE D3DPrimitive(GAPID3D9::PrimitiveType primitive_type) { | 237 static D3DPRIMITIVETYPE D3DPrimitive( |
| 238 command_buffer::PrimitiveType primitive_type) { |
| 238 switch (primitive_type) { | 239 switch (primitive_type) { |
| 239 case GAPID3D9::POINTS: | 240 case command_buffer::kPoints: |
| 240 return D3DPT_POINTLIST; | 241 return D3DPT_POINTLIST; |
| 241 case GAPID3D9::LINES: | 242 case command_buffer::kLines: |
| 242 return D3DPT_LINELIST; | 243 return D3DPT_LINELIST; |
| 243 case GAPID3D9::LINE_STRIPS: | 244 case command_buffer::kLineStrips: |
| 244 return D3DPT_LINESTRIP; | 245 return D3DPT_LINESTRIP; |
| 245 case GAPID3D9::TRIANGLES: | 246 case command_buffer::kTriangles: |
| 246 return D3DPT_TRIANGLELIST; | 247 return D3DPT_TRIANGLELIST; |
| 247 case GAPID3D9::TRIANGLE_STRIPS: | 248 case command_buffer::kTriangleStrips: |
| 248 return D3DPT_TRIANGLESTRIP; | 249 return D3DPT_TRIANGLESTRIP; |
| 249 case GAPID3D9::TRIANGLE_FANS: | 250 case command_buffer::kTriangleFans: |
| 250 return D3DPT_TRIANGLEFAN; | 251 return D3DPT_TRIANGLEFAN; |
| 251 default: | 252 default: |
| 252 LOG(FATAL) << "Invalid primitive type"; | 253 LOG(FATAL) << "Invalid primitive type"; |
| 253 return D3DPT_POINTLIST; | 254 return D3DPT_POINTLIST; |
| 254 } | 255 } |
| 255 } | 256 } |
| 256 | 257 |
| 257 // Draws with the current vertex struct. | 258 // Draws with the current vertex struct. |
| 258 BufferSyncInterface::ParseError GAPID3D9::Draw( | 259 BufferSyncInterface::ParseError GAPID3D9::Draw( |
| 259 PrimitiveType primitive_type, | 260 PrimitiveType primitive_type, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 275 // TODO: add proper error management | 276 // TODO: add proper error management |
| 276 return BufferSyncInterface::kParseInvalidArguments; | 277 return BufferSyncInterface::kParseInvalidArguments; |
| 277 } | 278 } |
| 278 HR(d3d_device_->DrawPrimitive(D3DPrimitive(primitive_type), first, count)); | 279 HR(d3d_device_->DrawPrimitive(D3DPrimitive(primitive_type), first, count)); |
| 279 return BufferSyncInterface::kParseNoError; | 280 return BufferSyncInterface::kParseNoError; |
| 280 } | 281 } |
| 281 | 282 |
| 282 // Draws with the current vertex struct. | 283 // Draws with the current vertex struct. |
| 283 BufferSyncInterface::ParseError GAPID3D9::DrawIndexed( | 284 BufferSyncInterface::ParseError GAPID3D9::DrawIndexed( |
| 284 PrimitiveType primitive_type, | 285 PrimitiveType primitive_type, |
| 285 ResourceID index_buffer_id, | 286 ResourceId index_buffer_id, |
| 286 unsigned int first, | 287 unsigned int first, |
| 287 unsigned int count, | 288 unsigned int count, |
| 288 unsigned int min_index, | 289 unsigned int min_index, |
| 289 unsigned int max_index) { | 290 unsigned int max_index) { |
| 290 IndexBufferD3D9 *index_buffer = index_buffers_.Get(index_buffer_id); | 291 IndexBufferD3D9 *index_buffer = index_buffers_.Get(index_buffer_id); |
| 291 if (!index_buffer) return BufferSyncInterface::kParseInvalidArguments; | 292 if (!index_buffer) return BufferSyncInterface::kParseInvalidArguments; |
| 292 if (validate_streams_ && !ValidateStreams()) { | 293 if (validate_streams_ && !ValidateStreams()) { |
| 293 // TODO: add proper error management | 294 // TODO: add proper error management |
| 294 return BufferSyncInterface::kParseInvalidArguments; | 295 return BufferSyncInterface::kParseInvalidArguments; |
| 295 } | 296 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 308 | 309 |
| 309 HR(d3d_device_->SetIndices(index_buffer->d3d_index_buffer())); | 310 HR(d3d_device_->SetIndices(index_buffer->d3d_index_buffer())); |
| 310 HR(d3d_device_->DrawIndexedPrimitive(D3DPrimitive(primitive_type), 0, | 311 HR(d3d_device_->DrawIndexedPrimitive(D3DPrimitive(primitive_type), 0, |
| 311 min_index, max_index - min_index + 1, | 312 min_index, max_index - min_index + 1, |
| 312 first, count)); | 313 first, count)); |
| 313 return BufferSyncInterface::kParseNoError; | 314 return BufferSyncInterface::kParseNoError; |
| 314 } | 315 } |
| 315 | 316 |
| 316 } // namespace command_buffer | 317 } // namespace command_buffer |
| 317 } // namespace o3d | 318 } // namespace o3d |
| OLD | NEW |