Commit 5f99fd3728943e7dd96f34ff91e00bc26a04dd78

Authored by Adam Bialogonski
1 parent a56865a0

line-mesh-demo using setIndexRange(). When changing mode it doesn't recreate the…

… index buffer, but changes the range of indices to draw and the type of primitives.

added interface to modify number of used elements from the elements array.

Change-Id: If0b223e6ace3d64aae8f16af0a284a42a7c9d967
examples/line-mesh/line-mesh-example.cpp
... ... @@ -22,6 +22,8 @@
22 22 // INTERNAL INCLUDES
23 23 #include "shared/view.h"
24 24  
  25 +#include <sstream>
  26 +
25 27 using namespace Dali;
26 28  
27 29 namespace
... ... @@ -62,11 +64,11 @@ void main()
62 64 }
63 65 );
64 66  
65   -const unsigned short indexLines[] = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 0 };
66   -const unsigned short indexLoop[] = { 0, 1, 2, 3, 4 };
67   -const unsigned short indexStrip[] = { 0, 1, 2, 3, 4, 0 };
68   -const unsigned short* indices[3] = { &indexLines[0], &indexLoop[0], &indexStrip[0] };
69   -const unsigned int indicesSize[3] = { sizeof(indexLines)/sizeof(indexLines[0]), sizeof(indexLoop)/sizeof(indexLoop[0]), sizeof(indexStrip)/sizeof(indexStrip[0])};
  67 +const unsigned short INDEX_LINES[] = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 0 };
  68 +const unsigned short INDEX_LOOP[] = { 0, 1, 2, 3, 4 };
  69 +const unsigned short INDEX_STRIP[] = { 0, 1, 2, 3, 4, 0 };
  70 +const unsigned short* INDICES[3] = { &INDEX_LINES[0], &INDEX_LOOP[0], &INDEX_STRIP[0] };
  71 +const unsigned int INDICES_SIZE[3] = { sizeof(INDEX_LINES)/sizeof(INDEX_LINES[0]), sizeof(INDEX_LOOP)/sizeof(INDEX_LOOP[0]), sizeof(INDEX_STRIP)/sizeof(INDEX_STRIP[0])};
70 72  
71 73 Geometry CreateGeometry()
72 74 {
... ... @@ -99,7 +101,7 @@ Geometry CreateGeometry()
99 101 // Create the geometry object
100 102 Geometry pentagonGeometry = Geometry::New();
101 103 pentagonGeometry.AddVertexBuffer( pentagonVertices );
102   - pentagonGeometry.SetIndexBuffer( indices[0], indicesSize[0] );
  104 + pentagonGeometry.SetIndexBuffer( INDICES[0], INDICES_SIZE[0] );
103 105 pentagonGeometry.SetGeometryType( Geometry::LINES );
104 106 return pentagonGeometry;
105 107 }
... ... @@ -139,14 +141,18 @@ public:
139 141 {
140 142 Stage stage = Stage::GetCurrent();
141 143  
  144 + // initial settings
  145 + mPrimitiveType = Geometry::LINES;
  146 + mCurrentIndexCount = 10;
  147 + mMaxIndexCount = 10;
  148 +
142 149 CreateRadioButtons();
143 150  
144 151 stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent);
145 152  
146 153 mStageSize = stage.GetSize();
147 154  
148   - // The Init signal is received once (only) during the Application lifetime
149   - ReInitialise( Geometry::LINES );
  155 + Initialise();
150 156  
151 157 // Hide the indicator bar
152 158 application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
... ... @@ -156,9 +162,8 @@ public:
156 162  
157 163 /**
158 164 * Invoked whenever application changes the type of geometry drawn
159   - * @param[in] type of geometry
160 165 */
161   - void ReInitialise( Geometry::GeometryType geometryType )
  166 + void Initialise()
162 167 {
163 168 Stage stage = Stage::GetCurrent();
164 169  
... ... @@ -173,6 +178,9 @@ public:
173 178 mGeometry = CreateGeometry();
174 179 mRenderer = Renderer::New( mGeometry, mShader );
175 180  
  181 + mRenderer.SetIndexRange( 0, 10 ); // lines
  182 + mPrimitiveType = Geometry::LINES;
  183 +
176 184 mMeshActor = Actor::New();
177 185 mMeshActor.AddRenderer( mRenderer );
178 186 mMeshActor.SetSize(200, 200);
... ... @@ -202,14 +210,14 @@ public:
202 210 {
203 211 Stage stage = Stage::GetCurrent();
204 212  
205   - Toolkit::TableView modeSelectTableView = Toolkit::TableView::New( 3, 1 );
  213 + Toolkit::TableView modeSelectTableView = Toolkit::TableView::New( 4, 1 );
206 214 modeSelectTableView.SetParentOrigin( ParentOrigin::TOP_LEFT );
207 215 modeSelectTableView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
208 216 modeSelectTableView.SetFitHeight( 0 );
209 217 modeSelectTableView.SetFitHeight( 1 );
210 218 modeSelectTableView.SetFitHeight( 2 );
211 219 modeSelectTableView.SetCellPadding( Vector2( 6.0f, 0.0f ) );
212   - modeSelectTableView.SetScale( Vector3( 0.5f, 0.5f, 0.5f ));
  220 + modeSelectTableView.SetScale( Vector3( 0.8f, 0.8f, 0.8f ));
213 221  
214 222 const char* labels[] =
215 223 {
... ... @@ -234,7 +242,46 @@ public:
234 242 mButtons[i] = radio;
235 243 modeSelectTableView.AddChild( radio, Toolkit::TableView::CellPosition( i, 0 ) );
236 244 }
  245 +
  246 + Toolkit::TableView elementCountTableView = Toolkit::TableView::New( 1, 3 );
  247 + elementCountTableView.SetCellPadding( Vector2( 6.0f, 0.0f ) );
  248 + elementCountTableView.SetParentOrigin( ParentOrigin::BOTTOM_LEFT );
  249 + elementCountTableView.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT );
  250 + elementCountTableView.SetFitHeight( 0 );
  251 + elementCountTableView.SetFitWidth( 0 );
  252 + elementCountTableView.SetFitWidth( 1 );
  253 + elementCountTableView.SetFitWidth( 2 );
  254 + mMinusButton = Toolkit::PushButton::New();
  255 + mMinusButton.SetLabelText( "<<" );
  256 + mMinusButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
  257 + mMinusButton.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
  258 +
  259 + Toolkit::PushButton mPlusButton = Toolkit::PushButton::New();
  260 + mPlusButton.SetLabelText( ">>" );
  261 + mPlusButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
  262 + mPlusButton.SetAnchorPoint( AnchorPoint::CENTER_RIGHT );
  263 +
  264 + mMinusButton.ClickedSignal().Connect( this, &ExampleController::OnButtonClicked );
  265 + mPlusButton.ClickedSignal().Connect( this, &ExampleController::OnButtonClicked );
  266 +
  267 + mIndicesCountLabel = Toolkit::TextLabel::New();
  268 + mIndicesCountLabel.SetParentOrigin( ParentOrigin::CENTER );
  269 + mIndicesCountLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT );
  270 +
  271 + std::stringstream str;
  272 + str << mCurrentIndexCount;
  273 + mIndicesCountLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, str.str() );
  274 + mIndicesCountLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Vector4( 1.0, 1.0, 1.0, 1.0 ) );
  275 + mIndicesCountLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "BOTTOM");
  276 + mIndicesCountLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH );
  277 + mIndicesCountLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
  278 +
  279 + elementCountTableView.AddChild( mMinusButton, Toolkit::TableView::CellPosition( 0, 0 ) );
  280 + elementCountTableView.AddChild( mIndicesCountLabel, Toolkit::TableView::CellPosition( 0, 1 ) );
  281 + elementCountTableView.AddChild( mPlusButton, Toolkit::TableView::CellPosition( 0, 2 ) );
  282 +
237 283 stage.Add(modeSelectTableView);
  284 + stage.Add(elementCountTableView);
238 285 }
239 286  
240 287 /**
... ... @@ -261,34 +308,57 @@ public:
261 308  
262 309 bool OnButtonPressed( Toolkit::Button button )
263 310 {
264   - const Geometry::GeometryType geomTypes[] =
265   - {
266   - Geometry::LINES,
267   - Geometry::LINE_LOOP,
268   - Geometry::LINE_STRIP
269   - };
270   -
271   - size_t index;
  311 + int indicesArray;
272 312 if( button == mButtons[0] )
273 313 {
274   - index = 0;
  314 + mCurrentIndexCount = 10;
  315 + mMaxIndexCount = 10;
  316 + mPrimitiveType = Geometry::LINES;
  317 + indicesArray = 0;
275 318 }
276 319 else if( button == mButtons[1] )
277 320 {
278   - index = 1;
  321 + mCurrentIndexCount = 5;
  322 + mMaxIndexCount = 5;
  323 + mPrimitiveType = Geometry::LINE_LOOP;
  324 + indicesArray = 1;
279 325 }
280 326 else
281 327 {
282   - index = 2;
  328 + mCurrentIndexCount = 6;
  329 + mMaxIndexCount = 6;
  330 + mPrimitiveType = Geometry::LINE_STRIP;
  331 + indicesArray = 2;
283 332 }
284 333  
285   - mGeometry.SetIndexBuffer( indices[index], indicesSize[index] );
286   - mGeometry.SetGeometryType( geomTypes[ index ] );
287   -
  334 + std::stringstream str;
  335 + str << mCurrentIndexCount;
  336 + mIndicesCountLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, str.str() );
  337 + mGeometry.SetGeometryType( mPrimitiveType );
  338 + mGeometry.SetIndexBuffer( INDICES[ indicesArray ], INDICES_SIZE[ indicesArray ] );
  339 + mRenderer.SetIndexRange( 0, mCurrentIndexCount );
288 340 return true;
289 341 }
290 342  
  343 + bool OnButtonClicked( Toolkit::Button button )
  344 + {
  345 + if( button == mMinusButton )
  346 + {
  347 + if (--mCurrentIndexCount < 2 )
  348 + mCurrentIndexCount = 2;
  349 + }
  350 + else
  351 + {
  352 + if (++mCurrentIndexCount > mMaxIndexCount )
  353 + mCurrentIndexCount = mMaxIndexCount;
  354 + }
291 355  
  356 + std::stringstream str;
  357 + str << mCurrentIndexCount;
  358 + mIndicesCountLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, str.str() );
  359 + mRenderer.SetIndexRange( 0, mCurrentIndexCount );
  360 + return true;
  361 + }
292 362  
293 363 private:
294 364  
... ... @@ -299,7 +369,13 @@ private:
299 369 Geometry mGeometry;
300 370 Renderer mRenderer;
301 371 Actor mMeshActor;
302   - Toolkit::RadioButton mButtons[3];
  372 + Toolkit::RadioButton mButtons[3];
  373 + Toolkit::PushButton mMinusButton;
  374 + Toolkit::PushButton mPlusButton;
  375 + Toolkit::TextLabel mIndicesCountLabel;
  376 + Geometry::GeometryType mPrimitiveType;
  377 + int mCurrentIndexCount;
  378 + int mMaxIndexCount;
303 379 };
304 380  
305 381 void RunTest( Application& application )
... ...