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 29 matching lines...) Loading... |
40 #include "core/cross/command_buffer/effect_cb.h" | 40 #include "core/cross/command_buffer/effect_cb.h" |
41 #include "core/cross/command_buffer/stream_bank_cb.h" | 41 #include "core/cross/command_buffer/stream_bank_cb.h" |
42 #include "core/cross/error.h" | 42 #include "core/cross/error.h" |
43 #include "command_buffer/common/cross/gapi_interface.h" | 43 #include "command_buffer/common/cross/gapi_interface.h" |
44 #include "command_buffer/client/cross/cmd_buffer_helper.h" | 44 #include "command_buffer/client/cross/cmd_buffer_helper.h" |
45 | 45 |
46 // TODO: add unit tests. | 46 // TODO: add unit tests. |
47 | 47 |
48 namespace o3d { | 48 namespace o3d { |
49 | 49 |
50 using command_buffer::ResourceID; | 50 using command_buffer::ResourceId; |
51 using command_buffer::CommandBufferHelper; | 51 using command_buffer::CommandBufferHelper; |
52 using command_buffer::CommandBufferEntry; | 52 using command_buffer::CommandBufferEntry; |
53 using command_buffer::GAPIInterface; | 53 using command_buffer::GAPIInterface; |
54 using command_buffer::kInvalidResource; | 54 using command_buffer::kInvalidResource; |
55 namespace vertex_struct = command_buffer::vertex_struct; | 55 namespace vertex_struct = command_buffer::vertex_struct; |
56 | 56 |
57 PrimitiveCB::PrimitiveCB(ServiceLocator* service_locator, RendererCB *renderer) | 57 PrimitiveCB::PrimitiveCB(ServiceLocator* service_locator, RendererCB *renderer) |
58 : Primitive(service_locator), | 58 : Primitive(service_locator), |
59 renderer_(renderer) { | 59 renderer_(renderer) { |
60 } | 60 } |
61 | 61 |
62 PrimitiveCB::~PrimitiveCB() { | 62 PrimitiveCB::~PrimitiveCB() { |
63 } | 63 } |
64 | 64 |
65 // Converts an O3D primitive type to a command-buffer one. | 65 // Converts an O3D primitive type to a command-buffer one. |
66 static GAPIInterface::PrimitiveType GetCBPrimitiveType( | 66 static command_buffer::PrimitiveType GetCBPrimitiveType( |
67 Primitive::PrimitiveType primitive_type) { | 67 Primitive::PrimitiveType primitive_type) { |
68 switch (primitive_type) { | 68 switch (primitive_type) { |
69 case Primitive::LINELIST: | 69 case Primitive::LINELIST: |
70 return GAPIInterface::LINES; | 70 return command_buffer::kLines; |
71 case Primitive::LINESTRIP: | 71 case Primitive::LINESTRIP: |
72 return GAPIInterface::LINE_STRIPS; | 72 return command_buffer::kLineStrips; |
73 case Primitive::TRIANGLELIST: | 73 case Primitive::TRIANGLELIST: |
74 return GAPIInterface::TRIANGLES; | 74 return command_buffer::kTriangles; |
75 case Primitive::TRIANGLESTRIP: | 75 case Primitive::TRIANGLESTRIP: |
76 return GAPIInterface::TRIANGLE_STRIPS; | 76 return command_buffer::kTriangleStrips; |
77 case Primitive::TRIANGLEFAN: | 77 case Primitive::TRIANGLEFAN: |
78 return GAPIInterface::TRIANGLE_FANS; | 78 return command_buffer::kTriangleFans; |
79 default: | 79 default: |
80 // Note that POINTLIST falls into this case, for compatibility with D3D. | 80 // Note that POINTLIST falls into this case, for compatibility with D3D. |
81 return GAPIInterface::MAX_PRIMITIVE_TYPE; | 81 return command_buffer::kMaxPrimitiveType; |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 // Sends the draw commands to the command buffers. | 85 // Sends the draw commands to the command buffers. |
86 void PrimitiveCB::PlatformSpecificRender(Renderer* renderer, | 86 void PrimitiveCB::PlatformSpecificRender(Renderer* renderer, |
87 DrawElement* draw_element, | 87 DrawElement* draw_element, |
88 Material* material, | 88 Material* material, |
89 ParamObject* override, | 89 ParamObject* override, |
90 ParamCache* param_cache) { | 90 ParamCache* param_cache) { |
91 DLOG_ASSERT(draw_element); | 91 DLOG_ASSERT(draw_element); |
(...skipping 17 matching lines...) Loading... |
109 // InsertMissingVertexStreams(); | 109 // InsertMissingVertexStreams(); |
110 } | 110 } |
111 | 111 |
112 IndexBufferCB *index_buffer_cb = | 112 IndexBufferCB *index_buffer_cb = |
113 down_cast<IndexBufferCB *>(index_buffer()); | 113 down_cast<IndexBufferCB *>(index_buffer()); |
114 if (!index_buffer_cb) { | 114 if (!index_buffer_cb) { |
115 // TODO(gman): draw non-indexed primitives. | 115 // TODO(gman): draw non-indexed primitives. |
116 DLOG(INFO) << "Trying to draw with an empty index buffer."; | 116 DLOG(INFO) << "Trying to draw with an empty index buffer."; |
117 return; | 117 return; |
118 } | 118 } |
119 GAPIInterface::PrimitiveType cb_primitive_type = | 119 command_buffer::PrimitiveType cb_primitive_type = |
120 GetCBPrimitiveType(primitive_type_); | 120 GetCBPrimitiveType(primitive_type_); |
121 if (cb_primitive_type == GAPIInterface::MAX_PRIMITIVE_TYPE) { | 121 if (cb_primitive_type == command_buffer::kMaxPrimitiveType) { |
122 DLOG(INFO) << "Invalid primitive type (" << primitive_type_ << ")."; | 122 DLOG(INFO) << "Invalid primitive type (" << primitive_type_ << ")."; |
123 return; | 123 return; |
124 } | 124 } |
125 | 125 |
126 // Make sure our streams are up to date (skinned, etc..) | 126 // Make sure our streams are up to date (skinned, etc..) |
127 stream_bank_cb->UpdateStreams(); | 127 stream_bank_cb->UpdateStreams(); |
128 | 128 |
129 stream_bank_cb->BindStreamsForRendering(); | 129 stream_bank_cb->BindStreamsForRendering(); |
130 | 130 |
131 CommandBufferHelper *helper = renderer_->helper(); | 131 CommandBufferHelper *helper = renderer_->helper(); |
132 | 132 |
133 // Sets current effect. | 133 // Sets current effect. |
134 // TODO: cache current effect ? | 134 // TODO: cache current effect ? |
135 helper->SetEffect(effect_cb->resource_id()); | 135 helper->SetEffect(effect_cb->resource_id()); |
136 param_cache_cb->RunHandlers(helper); | 136 param_cache_cb->RunHandlers(helper); |
137 | 137 |
138 // Draws. | 138 // Draws. |
139 helper->DrawIndexed(cb_primitive_type, index_buffer_cb->resource_id(), | 139 helper->DrawIndexed(cb_primitive_type, index_buffer_cb->resource_id(), |
140 0, number_primitives_, 0, number_vertices_ - 1); | 140 0, number_primitives_, 0, number_vertices_ - 1); |
141 } | 141 } |
142 | 142 |
143 } // namespace o3d | 143 } // namespace o3d |
OLD | NEW |