Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1.  
  2. ///////////////////////////////////////////////////////////////////////////////
  3. void Widget::Draw(int nesting) {
  4.     if(!mAlreadyRendered) {
  5.         if(IsVisible()) {
  6.             auto parent = mParent.lock();
  7.             if(parent) {
  8.                 GLCall(glStencilFunc(GL_EQUAL, nesting, 0xFF));
  9.                 GLCall(glStencilOp(GL_KEEP, GL_KEEP, GL_INCR));
  10.             } else {
  11.                 GLCall(glStencilFunc(GL_ALWAYS, 1, 0xFF));
  12.                 GLCall(glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE));
  13.             }
  14.  
  15.             CalculateGlobalPosition();
  16.  
  17.             PrepareVertices();
  18.  
  19.             auto label = dynamic_pointer_cast<Label>(shared_from_this());
  20.             if(label) {
  21.                 if(label->GetFont()) {
  22.                     GLCall(glBindTexture(GL_TEXTURE_2D, label->GetFont()->getTexture(label->GetCharacterSize()).getNativeHandle()));
  23.                 }
  24.             } else {
  25.                 if(mTexture) {
  26.                     GLCall(glBindTexture(GL_TEXTURE_2D, mTexture->mGLTexture));
  27.                 }
  28.             }
  29.  
  30.             if(mVertices.size()) {
  31.                 const char* data = reinterpret_cast<const char*>(&mVertices[0]);
  32.                 GLCall(glVertexPointer(2, GL_FLOAT, sizeof(sf::Vertex), data + offsetof(sf::Vertex, position)));
  33.                 GLCall(glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(sf::Vertex), data + offsetof(sf::Vertex, color)));
  34.                 GLCall(glTexCoordPointer(2, GL_FLOAT, sizeof(sf::Vertex), data + offsetof(sf::Vertex, texCoords)));
  35.                 GLCall(glDrawArrays(GL_QUADS, 0, mVertices.size()));
  36.             }
  37.  
  38.             for(auto & child : mChildren) {
  39.                 child->Draw(nesting + 1);
  40.             }
  41.  
  42.             mAlreadyRendered = true;
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement