Пример #1
0
 void compileTo(VertexArrays& vas)
 {
     if (!glBlocks.empty())
         throw std::logic_error("Custom code cannot be recorded into a macro");
     
     std::stable_sort(ops.begin(), ops.end());
     for (DrawOps::const_iterator op = ops.begin(), end = ops.end(); op != end; ++op)
         op->compileTo(vas);
 }
Пример #2
0
 void performDrawOpsAndCode()
 {
     // Allows us to make some assumptions.
     if (ops.empty())
     {
         for (CodeMap::iterator it = code.begin(), end = code.end(); it != end; ++it)
             it->second();
         return;
     }
     
     // Apply Z-Ordering.
     std::stable_sort(ops.begin(), ops.end());
     
     // We will loop: Drawing DrawOps, execute custom code.
     // This means if there is no code, we just draw one batch
     // of DrawOps, so no performance is sacrified.
     DrawOps::const_iterator current = ops.begin(), last = ops.begin();
     CodeMap::const_iterator it = code.begin();
     
     while (true)
     {
         if (it == code.end())
             // Last or only batch of DrawOps:
             // Just draw everything.
             last = ops.end() - 1;
         else
         {
             // There is code waiting:
             // Only draw up to this Z level.
             while (last != ops.end() - 1 && (last + 1)->z < it->first)
                 ++last;
         }
         
         if (current <= last)
         {
             // Draw DrawOps until next code is due
             RenderState renderState;
             while (current < last)
             {
                 DrawOps::const_iterator next = current + 1;
                 current->perform(renderState, &*next);
                 current = next;
             }
             last->perform(renderState, 0);
             ++current;
         }
         
         // Draw next code, or break if there is none
         if (it == code.end())
             break;
         else
         {
             it->second();
             ++it;
         }
     }
 }
Пример #3
0
 void performDrawOpsAndCode()
 {
     // Apply Z-Ordering.
     std::stable_sort(ops.begin(), ops.end());
     
     RenderStateManager manager;
     #ifdef GOSU_IS_IPHONE
     if (ops.empty())
         return;
     
     DrawOps::const_iterator current = ops.begin(), last = ops.end() - 1;
     for (; current != last; ++current)
     {
         manager.setRenderState(current->renderState);
         current->perform(&*(current + 1));
     }
     manager.setRenderState(last->renderState);
     last->perform(0);
     #else
     for (DrawOps::const_iterator current = ops.begin(), last = ops.end();
         current != last; ++current)
     {
         manager.setRenderState(current->renderState);
         if (current->verticesOrBlockIndex >= 0)
             current->perform(0);
         else
         {
             // GL code
             int blockIndex = ~current->verticesOrBlockIndex;
             assert (blockIndex >= 0);
             assert (blockIndex < glBlocks.size());
             glBlocks[blockIndex]();
             manager.enforceAfterUntrustedGL();
         }
     }
     #endif
 }