vtkOpenGLContextDevice2D.cxx 89.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkOpenGLContextDevice2D.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

#include "vtkOpenGLContextDevice2D.h"

Ken Martin's avatar
Ken Martin committed
18
#include "vtkAbstractContextBufferId.h"
19 20
#include "vtkBrush.h"
#include "vtkFloatArray.h"
Ken Martin's avatar
Ken Martin committed
21
#include "vtkImageData.h"
22
#include "vtkImageResize.h"
23
#include "vtkMath.h"
Ken Martin's avatar
Ken Martin committed
24 25
#include "vtkMathTextUtilities.h"
#include "vtkMatrix3x3.h"
26
#include "vtkNew.h"
27
#include "vtkObjectFactory.h"
Ken Martin's avatar
Ken Martin committed
28
#include "vtkOpenGLError.h"
29
#include "vtkOpenGLGL2PSHelper.h"
Ken Martin's avatar
Ken Martin committed
30
#include "vtkOpenGLIndexBufferObject.h"
Ken Martin's avatar
Ken Martin committed
31 32 33 34 35
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLRenderer.h"
#include "vtkOpenGLShaderCache.h"
#include "vtkOpenGLTexture.h"
#include "vtkOpenGLVertexArrayObject.h"
Ken Martin's avatar
Ken Martin committed
36
#include "vtkOpenGLVertexBufferObject.h"
37
#include "vtkPath.h"
Ken Martin's avatar
Ken Martin committed
38 39
#include "vtkPen.h"
#include "vtkPoints2D.h"
40
#include "vtkPointData.h"
Ken Martin's avatar
Ken Martin committed
41 42 43 44 45 46 47 48
#include "vtkRect.h"
#include "vtkShaderProgram.h"
#include "vtkSmartPointer.h"
#include "vtkTextProperty.h"
#include "vtkTextRendererStringToImage.h"
#include "vtkTexture.h"
#include "vtkTextureUnitManager.h"
#include "vtkTransform.h"
49
#include "vtkTransformFeedback.h"
Ken Martin's avatar
Ken Martin committed
50
#include "vtkVector.h"
51 52
#include "vtkViewport.h"
#include "vtkWindow.h"
Ken Martin's avatar
Ken Martin committed
53
#include "vtkOpenGLHelper.h"
54 55 56 57

#include "vtkObjectFactory.h"

#include "vtkOpenGLContextDevice2DPrivate.h"
58

59
#include <algorithm>
60
#include <sstream>
61

62 63
#define BUFFER_OFFSET(i) ((char *)NULL + (i))

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
namespace
{
  void copyColors(std::vector<unsigned char> &newColors,
    unsigned char *colors, int nc)
    {
    for (int j = 0; j < nc; j++)
      {
      newColors.push_back(colors[j]);
      }
    }

  const char *myVertShader =
    "attribute vec2 vertexMC;\n"
    "uniform mat4 WCDCMatrix;\n"
    "uniform mat4 MCWCMatrix;\n"
    "#ifdef haveColors\n"
    "attribute vec4 vertexScalar;\n"
    "varying vec4 vertexColor;\n"
    "#endif\n"
    "#ifdef haveTCoords\n"
    "attribute vec2 tcoordMC;\n"
    "varying vec2 tcoord;\n"
    "#endif\n"
    "#ifdef haveLines\n"
    "attribute vec2 tcoordMC;\n"
    "varying float ldistance;\n"
    "#endif\n"
    "void main() {\n"
    "#ifdef haveColors\n"
    "vertexColor = vertexScalar;\n"
    "#endif\n"
    "#ifdef haveTCoords\n"
    "tcoord = tcoordMC;\n"
    "#endif\n"
    "#ifdef haveLines\n"
    "ldistance = tcoordMC.x;\n"
    "#endif\n"
    "vec4 vertex = vec4(vertexMC.xy, 0.0, 1.0);\n"
    "gl_Position = vertex*MCWCMatrix*WCDCMatrix; }\n";

  const char *myFragShader =
    "//VTK::Output::Dec\n"
    "#ifdef haveColors\n"
    "varying vec4 vertexColor;\n"
    "#else\n"
    "uniform vec4 vertexColor;\n"
    "#endif\n"
    "#ifdef haveTCoords\n"
    "varying vec2 tcoord;\n"
    "uniform sampler2D texture1;\n"
    "#endif\n"
    "#ifdef haveLines\n"
    "varying float ldistance;\n"
    "uniform int stipple;\n"
    "#endif\n"
    "void main() {\n"
    "#ifdef haveLines\n"
    "if ((0x01 << int(mod(ldistance,16.0)) & stipple) == 0) { discard; }\n"
    "#endif\n"
    "#ifdef haveTCoords\n"
    " gl_FragData[0] = texture2D(texture1, tcoord);\n"
    "#else\n"
    " gl_FragData[0] = vertexColor;\n"
    "#endif\n"
    "}\n";

130 131 132 133 134 135 136 137 138 139 140 141 142
//-----------------------------------------------------------------------------
// Returns true when rendering the GL2PS background raster image. Vectorizable
// primitives should not be drawn during these passes.
bool SkipDraw()
{
  vtkOpenGLGL2PSHelper *gl2ps = vtkOpenGLGL2PSHelper::GetInstance();
  if (gl2ps && gl2ps->GetActiveState() == vtkOpenGLGL2PSHelper::Background)
    {
    return true;
    }
  return false;
}

143 144 145 146 147 148
//-----------------------------------------------------------------------------
// Releases the current shader program if it is inconsistent with the GL2PS
// capture state. Returns the current OpenGLGL2PSHelper instance if one exists.
vtkOpenGLGL2PSHelper* PrepProgramForGL2PS(vtkOpenGLHelper &helper)
{
  vtkOpenGLGL2PSHelper *gl2ps = vtkOpenGLGL2PSHelper::GetInstance();
149
  if (gl2ps && gl2ps->GetActiveState() == vtkOpenGLGL2PSHelper::Capture)
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
    {
    // Always recreate the program when doing GL2PS capture.
    if (helper.Program)
      {
      helper.Program->Delete();
      helper.Program = NULL;
      }
    }
  else
    {
    // If there is a feedback transform capturer set on the current shader
    // program and we're not capturing, recreate the program.
    if (helper.Program && helper.Program->GetTransformFeedback())
      {
      helper.Program->Delete();
      helper.Program = NULL;
      }
    }

  return gl2ps;
}

//-----------------------------------------------------------------------------
// Call before glDraw* commands to ensure that vertices are properly captured
// for GL2PS export.
void PreDraw(vtkOpenGLHelper &helper, int drawMode, size_t numVerts)
{
  vtkOpenGLGL2PSHelper *gl2ps = vtkOpenGLGL2PSHelper::GetInstance();
178 179
  if (gl2ps && gl2ps->GetActiveState() == vtkOpenGLGL2PSHelper::Capture &&
      helper.Program)
180 181 182 183 184 185 186
    {
    if (vtkTransformFeedback *tfc = helper.Program->GetTransformFeedback())
      {
      tfc->SetNumberOfVertices(drawMode, numVerts);
      tfc->BindBuffer();
      }
    }
187 188
}

189 190 191 192 193 194
//-----------------------------------------------------------------------------
// Call after glDraw* commands to ensure that vertices are properly captured
// for GL2PS export.
void PostDraw(vtkOpenGLHelper &helper, vtkRenderer *ren, unsigned char col[4])
{
  vtkOpenGLGL2PSHelper *gl2ps = vtkOpenGLGL2PSHelper::GetInstance();
195 196
  if (gl2ps && gl2ps->GetActiveState() == vtkOpenGLGL2PSHelper::Capture &&
      helper.Program)
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
    {
    if (vtkTransformFeedback *tfc = helper.Program->GetTransformFeedback())
      {
      tfc->ReadBuffer();
      tfc->ReleaseGraphicsResources();
      gl2ps->ProcessTransformFeedback(tfc, ren, col);
      tfc->ReleaseBufferData();
      }
    }
}

//-----------------------------------------------------------------------------
// Returns true if the startAngle and stopAngle (as used in the ellipse drawing
// functions) describe a full circle.
inline bool IsFullCircle(float startAngle, float stopAngle)
{
  // A small number practical for rendering purposes.
  const float TOL = 1e-5f;

  return std::fabs(stopAngle - startAngle) + TOL >= 360.f;
}

} // end anon namespace
220

221 222 223 224 225 226 227 228 229 230 231 232
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkOpenGLContextDevice2D)

//-----------------------------------------------------------------------------
vtkOpenGLContextDevice2D::vtkOpenGLContextDevice2D()
{
  this->Renderer = 0;
  this->InRender = false;
  this->TextRenderer = vtkTextRendererStringToImage::New();
  this->Storage = new vtkOpenGLContextDevice2D::Private;
  this->RenderWindow = NULL;
  this->MaximumMarkerCacheSize = 20;
233 234
  this->ProjectionMatrix = vtkTransform::New();
  this->ModelMatrix = vtkTransform::New();
Ken Martin's avatar
Ken Martin committed
235 236
  this->VBO =  new vtkOpenGLHelper;
  this->VCBO =  new vtkOpenGLHelper;
237 238
  this->LinesBO =  new vtkOpenGLHelper;
  this->LinesCBO =  new vtkOpenGLHelper;
Ken Martin's avatar
Ken Martin committed
239 240 241
  this->VTBO =  new vtkOpenGLHelper;
  this->SBO =  new vtkOpenGLHelper;
  this->SCBO =  new vtkOpenGLHelper;
242
  this->LinePattern = 0xFFFF;
243 244 245 246 247
}

//-----------------------------------------------------------------------------
vtkOpenGLContextDevice2D::~vtkOpenGLContextDevice2D()
{
248 249 250 251
  delete this->VBO;
  this->VBO = 0;
  delete this->VCBO;
  this->VCBO = 0;
252 253 254 255
  delete this->LinesBO;
  this->LinesBO = 0;
  delete this->LinesCBO;
  this->LinesCBO = 0;
256 257 258 259 260 261 262
  delete this->SBO;
  this->SBO = 0;
  delete this->SCBO;
  this->SCBO = 0;
  delete this->VTBO;
  this->VTBO = 0;

263 264 265 266 267 268 269
  while (!this->MarkerCache.empty())
    {
    this->MarkerCache.back().Value->Delete();
    this->MarkerCache.pop_back();
    }

  this->TextRenderer->Delete();
270 271
  this->ProjectionMatrix->Delete();
  this->ModelMatrix->Delete();
272 273 274
  delete this->Storage;
}

275 276 277 278 279 280 281 282 283 284
vtkMatrix4x4 *vtkOpenGLContextDevice2D::GetProjectionMatrix()
{
  return this->ProjectionMatrix->GetMatrix();
}

vtkMatrix4x4 *vtkOpenGLContextDevice2D::GetModelMatrix()
{
  return this->ModelMatrix->GetMatrix();
}

285 286 287 288 289 290 291 292 293 294 295 296 297 298
//-----------------------------------------------------------------------------
void vtkOpenGLContextDevice2D::Begin(vtkViewport* viewport)
{
  vtkOpenGLClearErrorMacro();
  // Need the actual pixel size of the viewport - ask OpenGL.
  GLint vp[4];
  glGetIntegerv(GL_VIEWPORT, vp);
  this->Storage->Offset.Set(static_cast<int>(vp[0]),
                            static_cast<int>(vp[1]));

  this->Storage->Dim.Set(static_cast<int>(vp[2]),
                         static_cast<int>(vp[3]));

  // push a 2D matrix on the stack
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
  this->ProjectionMatrix->Push();
  this->ProjectionMatrix->Identity();
  this->PushMatrix();
  this->ModelMatrix->Identity();

  double offset = 0.5;
  double xmin = offset;
  double xmax = vp[2]+offset-1.0;
  double ymin = offset;
  double ymax = vp[3]+offset-1.0;
  double znear = -2000;
  double zfar = 2000;

  double matrix[4][4];
  vtkMatrix4x4::Identity(*matrix);

  matrix[0][0] = 2/(xmax - xmin);
  matrix[1][1] = 2/(ymax - ymin);
  matrix[2][2] = -2/(zfar - znear);

  matrix[0][3] = -(xmin + xmax)/(xmax - xmin);
  matrix[1][3] = -(ymin + ymax)/(ymax - ymin);
  matrix[2][3] = -(znear + zfar)/(zfar - znear);

  this->ProjectionMatrix->SetMatrix(*matrix);
324 325 326 327 328 329 330 331

  // Store the previous state before changing it
  this->Storage->SaveGLState();
  glDisable(GL_DEPTH_TEST);
  glEnable(GL_BLEND);

  this->Renderer = vtkRenderer::SafeDownCast(viewport);

332 333
  this->RenderWindow = vtkOpenGLRenderWindow::SafeDownCast(this->Renderer->GetRenderWindow());
  this->RenderWindow->GetShaderCache()->ReleaseCurrentShader();
334

335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
  // Enable simple line, point and polygon antialiasing if multisampling is on.
  if (this->Renderer->GetRenderWindow()->GetMultiSamples())
    {
    glEnable(GL_LINE_SMOOTH);
    glEnable(GL_POLYGON_SMOOTH);
    }

  this->InRender = true;
  vtkOpenGLCheckErrorMacro("failed after Begin");
}

//-----------------------------------------------------------------------------
void vtkOpenGLContextDevice2D::End()
{
  if (!this->InRender)
    {
    return;
    }

354 355
  this->ProjectionMatrix->Pop();
  this->PopMatrix();
356

357
  vtkOpenGLClearErrorMacro();
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392

  // Restore the GL state that we changed
  this->Storage->RestoreGLState();

  // Disable simple line, point and polygon antialiasing if multisampling is on.
  if (this->Renderer->GetRenderWindow()->GetMultiSamples())
    {
    glDisable(GL_LINE_SMOOTH);
    glDisable(GL_POLYGON_SMOOTH);
    }

  this->RenderWindow = NULL;
  this->InRender = false;

  vtkOpenGLCheckErrorMacro("failed after End");
}

// ----------------------------------------------------------------------------
void vtkOpenGLContextDevice2D::BufferIdModeBegin(
  vtkAbstractContextBufferId *bufferId)
{
  assert("pre: not_yet" && !this->GetBufferIdMode());
  assert("pre: bufferId_exists" && bufferId!=0);

  vtkOpenGLClearErrorMacro();

  this->BufferId=bufferId;

  // Save OpenGL state.
  this->Storage->SaveGLState(true);

  int lowerLeft[2];
  int usize, vsize;
  this->Renderer->GetTiledSizeAndOrigin(&usize,&vsize,lowerLeft,lowerLeft+1);

393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
  // push a 2D matrix on the stack
  this->ProjectionMatrix->Push();
  this->ProjectionMatrix->Identity();
  this->PushMatrix();
  this->ModelMatrix->Identity();

  double xmin = 0.5;
  double xmax = usize+0.5;
  double ymin = 0.5;
  double ymax = vsize+0.5;
  double znear = -1;
  double zfar = 1;

  double matrix[4][4];
  vtkMatrix4x4::Identity(*matrix);

  matrix[0][0] = 2/(xmax - xmin);
  matrix[1][1] = 2/(ymax - ymin);
  matrix[2][2] = -2/(zfar - znear);

  matrix[0][3] = -(xmin + xmax)/(xmax - xmin);
  matrix[1][3] = -(ymin + ymax)/(ymax - ymin);
  matrix[2][3] = -(znear + zfar)/(zfar - znear);

  this->ProjectionMatrix->SetMatrix(*matrix);
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444

  glDrawBuffer(GL_BACK_LEFT);
  glClearColor(0.0,0.0,0.0,0.0); // id=0 means no hit, just background
  glClear(GL_COLOR_BUFFER_BIT);
  glDisable(GL_ALPHA_TEST);
  glDisable(GL_STENCIL_TEST);
  glDisable(GL_DEPTH_TEST);
  glDisable(GL_BLEND);

  vtkOpenGLCheckErrorMacro("failed after BufferIdModeBegin");

  assert("post: started" && this->GetBufferIdMode());
}

// ----------------------------------------------------------------------------
void vtkOpenGLContextDevice2D::BufferIdModeEnd()
{
  assert("pre: started" && this->GetBufferIdMode());

  vtkOpenGLClearErrorMacro();

  // Assume the renderer has been set previously during rendering (sse Begin())
  int lowerLeft[2];
  int usize, vsize;
  this->Renderer->GetTiledSizeAndOrigin(&usize,&vsize,lowerLeft,lowerLeft+1);
  this->BufferId->SetValues(lowerLeft[0],lowerLeft[1]);

445 446
  this->ProjectionMatrix->Pop();
  this->PopMatrix();
447 448 449 450 451 452 453 454 455 456

  this->Storage->RestoreGLState(true);

  this->BufferId=0;

  vtkOpenGLCheckErrorMacro("failed after BufferIdModeEnd");

  assert("post: done" && !this->GetBufferIdMode());
}

457 458 459 460 461 462 463 464 465 466

void vtkOpenGLContextDevice2D::SetMatrices(vtkShaderProgram *prog)
{
  prog->SetUniformMatrix("WCDCMatrix",
    this->ProjectionMatrix->GetMatrix());
  prog->SetUniformMatrix("MCWCMatrix",
    this->ModelMatrix->GetMatrix());
}

void vtkOpenGLContextDevice2D::BuildVBO(
Ken Martin's avatar
Ken Martin committed
467
  vtkOpenGLHelper *cellBO,
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
  float *f, int nv,
  unsigned char *colors, int nc,
  float *tcoords)
{
  int stride = 2;
  int cOffset = 0;
  int tOffset = 0;
  if (colors)
    {
    cOffset = stride;
    stride++;
    }
  if (tcoords)
    {
    tOffset = stride;
    stride += 2;
    }

  std::vector<float> va;
  va.resize(nv*stride);
Ken Martin's avatar
Ken Martin committed
488
  vtkucfloat c;
489 490 491 492 493 494
  for (int i = 0; i < nv; i++)
    {
    va[i*stride] = f[i*2];
    va[i*stride+1] = f[i*2+1];
    if (colors)
      {
495 496 497
      c.c[0] = colors[nc*i];
      c.c[1] = colors[nc*i+1];
      c.c[2] = colors[nc*i+2];
498 499
      if (nc == 4)
        {
500
        c.c[3] = colors[nc*i+3];
501 502 503
        }
      else
        {
504
        c.c[3] =  255;
505
        }
506
      va[i*stride+cOffset] = c.f;
507 508 509 510 511 512 513 514 515
      }
    if (tcoords)
      {
      va[i*stride+tOffset] = tcoords[i*2];
      va[i*stride+tOffset+1] = tcoords[i*2+1];
      }
    }

  // upload the data
Ken Martin's avatar
Ken Martin committed
516 517 518 519
  cellBO->IBO->Upload(va, vtkOpenGLBufferObject::ArrayBuffer);
  cellBO->VAO->Bind();
  if (!cellBO->VAO->AddAttributeArray(
        cellBO->Program, cellBO->IBO,
520 521 522 523 524 525 526 527
        "vertexMC", 0,
        sizeof(float)*stride,
        VTK_FLOAT, 2, false))
    {
    vtkErrorMacro(<< "Error setting vertexMC in shader VAO.");
    }
  if (colors)
    {
Ken Martin's avatar
Ken Martin committed
528 529
    if (!cellBO->VAO->AddAttributeArray(
          cellBO->Program, cellBO->IBO,
530 531 532 533 534 535 536 537 538
          "vertexScalar", sizeof(float)*cOffset,
          sizeof(float)*stride,
          VTK_UNSIGNED_CHAR, 4, true))
      {
      vtkErrorMacro(<< "Error setting vertexScalar in shader VAO.");
      }
    }
  if (tcoords)
    {
Ken Martin's avatar
Ken Martin committed
539 540
    if (!cellBO->VAO->AddAttributeArray(
          cellBO->Program, cellBO->IBO,
541 542 543 544 545 546 547 548
          "tcoordMC", sizeof(float)*tOffset,
          sizeof(float)*stride,
          VTK_FLOAT, 2, false))
      {
      vtkErrorMacro(<< "Error setting tcoordMC in shader VAO.");
      }
    }

Ken Martin's avatar
Ken Martin committed
549
  cellBO->VAO->Bind();
550 551 552 553
}

void vtkOpenGLContextDevice2D::ReadyVBOProgram()
{
554 555
  vtkOpenGLGL2PSHelper *gl2ps = PrepProgramForGL2PS(*this->VBO);

556 557
  if (!this->VBO->Program)
    {
558
    vtkTransformFeedback *tf = NULL;
559
    if (gl2ps && gl2ps->GetActiveState() == vtkOpenGLGL2PSHelper::Capture)
560 561 562 563 564
      {
      tf = vtkTransformFeedback::New();
      tf->AddVarying(vtkTransformFeedback::Vertex_ClipCoordinate_F,
                     "gl_Position");
      }
565 566 567 568
    std::string vs = "//VTK::System::Dec\n";
    vs += myVertShader;
    std::string fs = "//VTK::System::Dec\n";
    fs +=myFragShader;
569
    this->VBO->Program  =
570
        this->RenderWindow->GetShaderCache()->ReadyShaderProgram(
571 572 573 574 575 576
        vs.c_str(), fs.c_str(),"",tf);
    if (tf)
      {
      tf->Delete();
      tf = NULL;
      }
577 578 579
    }
  else
    {
580
    this->RenderWindow->GetShaderCache()->ReadyShaderProgram(this->VBO->Program);
581 582 583 584 585
    }
}

void vtkOpenGLContextDevice2D::ReadyVCBOProgram()
{
586 587
  vtkOpenGLGL2PSHelper *gl2ps = PrepProgramForGL2PS(*this->VCBO);

588 589
  if (!this->VCBO->Program)
    {
590
    vtkTransformFeedback *tf = NULL;
591
    if (gl2ps && gl2ps->GetActiveState() == vtkOpenGLGL2PSHelper::Capture)
592 593 594 595 596 597 598
      {
      tf = vtkTransformFeedback::New();
      tf->AddVarying(vtkTransformFeedback::Vertex_ClipCoordinate_F,
                     "gl_Position");
      tf->AddVarying(vtkTransformFeedback::Color_RGBA_F,
                     "vertexColor");
      }
599 600 601 602
    std::string vs = "//VTK::System::Dec\n#define haveColors\n";
    vs += myVertShader;
    std::string fs = "//VTK::System::Dec\n#define haveColors\n";
    fs +=myFragShader;
603
    this->VCBO->Program  =
604
        this->RenderWindow->GetShaderCache()->ReadyShaderProgram(
605 606 607 608 609 610
          vs.c_str(), fs.c_str(),"",tf);
    if (tf)
      {
      tf->Delete();
      tf = NULL;
      }
611 612 613
    }
  else
    {
614
    this->RenderWindow->GetShaderCache()->ReadyShaderProgram(this->VCBO->Program);
615 616 617
    }
}

618 619
void vtkOpenGLContextDevice2D::ReadyLinesBOProgram()
{
620 621
  vtkOpenGLGL2PSHelper *gl2ps = PrepProgramForGL2PS(*this->VCBO);

622 623
  if (!this->LinesBO->Program)
    {
624 625 626 627 628 629 630
    vtkTransformFeedback *tf = NULL;
    if (gl2ps && gl2ps->GetActiveState() == vtkOpenGLGL2PSHelper::Capture)
      {
      tf = vtkTransformFeedback::New();
      tf->AddVarying(vtkTransformFeedback::Vertex_ClipCoordinate_F,
                     "gl_Position");
      }
631 632 633 634 635 636
    std::string vs = "//VTK::System::Dec\n#define haveLines\n";
    vs += myVertShader;
    std::string fs = "//VTK::System::Dec\n#define haveLines\n";
    fs +=myFragShader;
    this->LinesBO->Program  =
        this->RenderWindow->GetShaderCache()->ReadyShaderProgram(
637 638 639 640 641 642
        vs.c_str(), fs.c_str(),"",tf);
    if (tf)
      {
      tf->Delete();
      tf = NULL;
      }
643 644 645 646 647 648 649 650 651 652
    }
  else
    {
    this->RenderWindow->GetShaderCache()->ReadyShaderProgram(
      this->LinesBO->Program);
    }
}

void vtkOpenGLContextDevice2D::ReadyLinesCBOProgram()
{
653 654
  vtkOpenGLGL2PSHelper *gl2ps = PrepProgramForGL2PS(*this->VCBO);

655 656
  if (!this->LinesCBO->Program)
    {
657 658 659 660 661 662 663 664 665
    vtkTransformFeedback *tf = NULL;
    if (gl2ps && gl2ps->GetActiveState() == vtkOpenGLGL2PSHelper::Capture)
      {
      tf = vtkTransformFeedback::New();
      tf->AddVarying(vtkTransformFeedback::Vertex_ClipCoordinate_F,
                     "gl_Position");
      tf->AddVarying(vtkTransformFeedback::Color_RGBA_F,
                     "vertexColor");
      }
666 667 668 669 670 671 672 673
    std::string vs =
      "//VTK::System::Dec\n#define haveColors\n#define haveLines\n";
    vs += myVertShader;
    std::string fs =
      "//VTK::System::Dec\n#define haveColors\n#define haveLines\n";
    fs +=myFragShader;
    this->LinesCBO->Program  =
        this->RenderWindow->GetShaderCache()->ReadyShaderProgram(
674 675 676 677 678 679
        vs.c_str(), fs.c_str(),"",tf);
    if (tf)
      {
      tf->Delete();
      tf = NULL;
      }
680 681 682 683 684 685 686
    }
  else
    {
    this->RenderWindow->GetShaderCache()->ReadyShaderProgram(this->LinesCBO->Program);
    }
}

687 688 689 690
void vtkOpenGLContextDevice2D::ReadyVTBOProgram()
{
  if (!this->VTBO->Program)
    {
691 692 693 694
    std::string vs = "//VTK::System::Dec\n#define haveTCoords\n";
    vs += myVertShader;
    std::string fs = "//VTK::System::Dec\n#define haveTCoords\n";
    fs +=myFragShader;
695
    this->VTBO->Program  =
696
        this->RenderWindow->GetShaderCache()->ReadyShaderProgram(
697
        vs.c_str(), fs.c_str(),"");
698 699 700
    }
  else
    {
701
    this->RenderWindow->GetShaderCache()->ReadyShaderProgram(this->VTBO->Program);
702 703 704 705 706 707 708 709
    }
}

void vtkOpenGLContextDevice2D::ReadySBOProgram()
{
  if (!this->SBO->Program)
    {
    this->SBO->Program  =
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
      this->RenderWindow->GetShaderCache()->ReadyShaderProgram(
      // vertex shader
      "//VTK::System::Dec\n"
      "attribute vec2 vertexMC;\n"
      "uniform mat4 WCDCMatrix;\n"
      "uniform mat4 MCWCMatrix;\n"
      "void main() {\n"
      "vec4 vertex = vec4(vertexMC.xy, 0.0, 1.0);\n"
      "gl_Position = vertex*MCWCMatrix*WCDCMatrix; }\n",
      // fragment shader
      "//VTK::System::Dec\n"
      "//VTK::Output::Dec\n"
      "uniform vec4 vertexColor;\n"
      "uniform sampler2D texture1;\n"
      "void main() { gl_FragData[0] = vertexColor*texture2D(texture1, gl_PointCoord); }",
      // geometry shader
      "");
727 728 729
    }
  else
    {
730
    this->RenderWindow->GetShaderCache()->ReadyShaderProgram(this->SBO->Program);
731 732 733 734 735 736 737 738
    }
}

void vtkOpenGLContextDevice2D::ReadySCBOProgram()
{
  if (!this->SCBO->Program)
    {
    this->SCBO->Program  =
739
        this->RenderWindow->GetShaderCache()->ReadyShaderProgram(
740 741 742 743 744 745 746 747 748 749 750 751 752
        // vertex shader
        "//VTK::System::Dec\n"
        "attribute vec2 vertexMC;\n"
        "attribute vec4 vertexScalar;\n"
        "uniform mat4 WCDCMatrix;\n"
        "uniform mat4 MCWCMatrix;\n"
        "varying vec4 vertexColor;\n"
        "void main() {\n"
        "vec4 vertex = vec4(vertexMC.xy, 0.0, 1.0);\n"
        "vertexColor = vertexScalar;\n"
        "gl_Position = vertex*MCWCMatrix*WCDCMatrix; }\n",
        // fragment shader
        "//VTK::System::Dec\n"
753
        "//VTK::Output::Dec\n"
754 755
        "varying vec4 vertexColor;\n"
        "uniform sampler2D texture1;\n"
756
        "void main() { gl_FragData[0] = vertexColor*texture2D(texture1, gl_PointCoord); }",
757 758 759 760 761
        // geometry shader
        "");
    }
  else
    {
762
    this->RenderWindow->GetShaderCache()->ReadyShaderProgram(this->SCBO->Program);
763 764 765
    }
}

766 767 768 769 770 771 772
//-----------------------------------------------------------------------------
void vtkOpenGLContextDevice2D::DrawPoly(float *f, int n, unsigned char *colors,
                                        int nc)
{
  assert("f must be non-null" && f != NULL);
  assert("n must be greater than 0" && n > 0);

773 774 775 776 777
  if (SkipDraw())
    {
    return;
    }

778 779 780 781 782
  if (this->Pen->GetLineType() == vtkPen::NO_PEN)
    {
    return;
    }

783 784 785 786 787 788
  // Skip transparent elements.
  if (!colors && this->Pen->GetColorObject().GetAlpha() == 0)
    {
    return;
    }

789 790 791
  vtkOpenGLClearErrorMacro();
  this->SetLineType(this->Pen->GetLineType());

Ken Martin's avatar
Ken Martin committed
792
  vtkOpenGLHelper *cbo = 0;
793 794
  if (colors)
    {
795 796
    this->ReadyLinesCBOProgram();
    cbo = this->LinesCBO;
797 798 799
    }
  else
    {
800 801
    this->ReadyLinesBOProgram();
    cbo = this->LinesBO;
802 803
    cbo->Program->SetUniform4uc("vertexColor",
      this->Pen->GetColor());
804
    }
805
  cbo->Program->SetUniformi("stipple",this->LinePattern);
806 807 808

  this->SetMatrices(cbo->Program);

809 810 811 812 813 814 815 816 817 818 819 820 821 822 823
  // for line stipple we need to compute the scaled
  // cumulative linear distance
  double *scale = this->ModelMatrix->GetScale();
  std::vector<float> distances;
  distances.resize(n*2);
  float totDist = 0.0;
  distances[0] = 0.0;
  for (int i = 1; i < n; i++)
    {
    float xDel = scale[0]*(f[i*2] - f[i*2-2]);
    float yDel = scale[1]*(f[i*2+1] - f[i*2-1]);
    totDist += sqrt(xDel*xDel + yDel*yDel);
    distances[i*2] = totDist;
    }

824 825 826
  // For GL2PS captures, use the path that draws lines instead of triangles --
  // GL2PS can handle stipples and linewidths just fine.
  vtkOpenGLGL2PSHelper *gl2ps = vtkOpenGLGL2PSHelper::GetInstance();
827

828 829
  if (this->Pen->GetWidth() > 1.0 &&
      !(gl2ps && gl2ps->GetActiveState() == vtkOpenGLGL2PSHelper::Capture))
Ken Martin's avatar
Ken Martin committed
830 831 832 833 834 835
    {
    // convert to triangles and draw, this is because
    // OpenGL no longer supports wide lines directly
    float hwidth = this->Pen->GetWidth()/2.0;
    std::vector<float> newVerts;
    std::vector<unsigned char> newColors;
836 837
    std::vector<float> newDistances;
    newDistances.resize((n-1)*12);
Ken Martin's avatar
Ken Martin committed
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871
    for (int i = 0; i < n-1; i++)
      {
      // for each line segment draw two triangles
      // start by computing the direction
      vtkVector2f dir((f[i*2+2] - f[i*2])*scale[0],
        (f[i*2+3] - f[i*2+1])*scale[1]);
      vtkVector2f norm(-dir.GetY(),dir.GetX());
      norm.Normalize();
      norm.SetX(hwidth*norm.GetX()/scale[0]);
      norm.SetY(hwidth*norm.GetY()/scale[1]);

      newVerts.push_back(f[i*2]+norm.GetX());
      newVerts.push_back(f[i*2+1]+norm.GetY());
      newVerts.push_back(f[i*2]-norm.GetX());
      newVerts.push_back(f[i*2+1]-norm.GetY());
      newVerts.push_back(f[i*2+2]-norm.GetX());
      newVerts.push_back(f[i*2+3]-norm.GetY());

      newVerts.push_back(f[i*2]+norm.GetX());
      newVerts.push_back(f[i*2+1]+norm.GetY());
      newVerts.push_back(f[i*2+2]-norm.GetX());
      newVerts.push_back(f[i*2+3]-norm.GetY());
      newVerts.push_back(f[i*2+2]+norm.GetX());
      newVerts.push_back(f[i*2+3]+norm.GetY());

      if (colors)
        {
        copyColors(newColors, colors+i*nc, nc);
        copyColors(newColors, colors+i*nc, nc);
        copyColors(newColors, colors+(i+1)*nc, nc);
        copyColors(newColors, colors+i*nc, nc);
        copyColors(newColors, colors+(i+1)*nc, nc);
        copyColors(newColors, colors+(i+1)*nc, nc);
        }
872 873 874 875 876 877 878

      newDistances[i*12] = distances[i*2];
      newDistances[i*12+2] = distances[i*2];
      newDistances[i*12+4] = distances[i*2+2];
      newDistances[i*12+6] = distances[i*2];
      newDistances[i*12+8] = distances[i*2+2];
      newDistances[i*12+10] = distances[i*2+2];
Ken Martin's avatar
Ken Martin committed
879 880 881
      }

    this->BuildVBO(cbo, &(newVerts[0]), newVerts.size()/2,
882
      colors ? &(newColors[0]) : NULL, nc, &(newDistances[0]));
883 884

    PreDraw(*cbo, GL_TRIANGLES, newVerts.size() / 2);
Ken Martin's avatar
Ken Martin committed
885
    glDrawArrays(GL_TRIANGLES, 0, newVerts.size()/2);
886
    PostDraw(*cbo, this->Renderer, this->Pen->GetColor());
Ken Martin's avatar
Ken Martin committed
887 888 889 890
    }
  else
    {
    this->SetLineWidth(this->Pen->GetWidth());
891
    this->BuildVBO(cbo, f, n, colors, nc, &(distances[0]));
892
    PreDraw(*cbo, GL_LINE_STRIP, n);
Ken Martin's avatar
Ken Martin committed
893
    glDrawArrays(GL_LINE_STRIP, 0, n);
894
    PostDraw(*cbo, this->Renderer, this->Pen->GetColor());
Ken Martin's avatar
Ken Martin committed
895 896
    this->SetLineWidth(1.0);
    }
897 898 899

  // free everything
  cbo->ReleaseGraphicsResources(this->RenderWindow);
900 901 902 903

  vtkOpenGLCheckErrorMacro("failed after DrawPoly");
}

904 905 906 907 908 909 910
//-----------------------------------------------------------------------------
void vtkOpenGLContextDevice2D::DrawLines(float *f, int n, unsigned char *colors,
                                         int nc)
{
  assert("f must be non-null" && f != NULL);
  assert("n must be greater than 0" && n > 0);

911 912 913 914 915
  if (SkipDraw())
    {
    return;
    }

916 917 918 919 920
  if (this->Pen->GetLineType() == vtkPen::NO_PEN)
    {
    return;
    }

921 922 923 924 925 926
  // Skip transparent elements.
  if (!colors && this->Pen->GetColorObject().GetAlpha() == 0)
    {
    return;
    }

927 928 929 930
  vtkOpenGLClearErrorMacro();

  this->SetLineType(this->Pen->GetLineType());

Ken Martin's avatar
Ken Martin committed
931
  vtkOpenGLHelper *cbo = 0;
932 933
  if (colors)
    {
934 935
    this->ReadyLinesCBOProgram();
    cbo = this->LinesCBO;
936 937 938
    }
  else
    {
939 940
    this->ReadyLinesBOProgram();
    cbo = this->LinesBO;
Ken Martin's avatar
Ken Martin committed
941 942
    cbo->Program->SetUniform4uc("vertexColor",
      this->Pen->GetColor());
943
    }
944
  cbo->Program->SetUniformi("stipple",this->LinePattern);
Ken Martin's avatar
Ken Martin committed
945 946 947

  this->SetMatrices(cbo->Program);

948 949 950 951 952 953 954 955 956 957 958 959 960 961 962
  // for line stipple we need to compute the scaled
  // cumulative linear distance
  double *scale = this->ModelMatrix->GetScale();
  std::vector<float> distances;
  distances.resize(n*2);
  float totDist = 0.0;
  distances[0] = 0.0;
  for (int i = 1; i < n; i++)
    {
    float xDel = scale[0]*(f[i*2] - f[i*2-2]);
    float yDel = scale[1]*(f[i*2+1] - f[i*2-1]);
    totDist += sqrt(xDel*xDel + yDel*yDel);
    distances[i*2] = totDist;
    }

Ken Martin's avatar
Ken Martin committed
963
  if (this->Pen->GetWidth() > 1.0)
964
    {
Ken Martin's avatar
Ken Martin committed
965 966 967 968 969
    // convert to triangles and draw, this is because
    // OpenGL no longer supports wide lines directly
    float hwidth = this->Pen->GetWidth()/2.0;
    std::vector<float> newVerts;
    std::vector<unsigned char> newColors;
970 971
    std::vector<float> newDistances;
    newDistances.resize((n-1)*12);
Ken Martin's avatar
Ken Martin committed
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
    for (int i = 0; i < n-1; i += 2)
      {
      // for each line segment draw two triangles
      // start by computing the direction
      vtkVector2f dir((f[i*2+2] - f[i*2])*scale[0],
        (f[i*2+3] - f[i*2+1])*scale[1]);
      vtkVector2f norm(-dir.GetY(),dir.GetX());
      norm.Normalize();
      norm.SetX(hwidth*norm.GetX()/scale[0]);
      norm.SetY(hwidth*norm.GetY()/scale[1]);

      newVerts.push_back(f[i*2]+norm.GetX());
      newVerts.push_back(f[i*2+1]+norm.GetY());
      newVerts.push_back(f[i*2]-norm.GetX());
      newVerts.push_back(f[i*2+1]-norm.GetY());
      newVerts.push_back(f[i*2+2]-norm.GetX());
      newVerts.push_back(f[i*2+3]-norm.GetY());

      newVerts.push_back(f[i*2]+norm.GetX());
      newVerts.push_back(f[i*2+1]+norm.GetY());
      newVerts.push_back(f[i*2+2]-norm.GetX());
      newVerts.push_back(f[i*2+3]-norm.GetY());
      newVerts.push_back(f[i*2+2]+norm.GetX());
      newVerts.push_back(f[i*2+3]+norm.GetY());

      if (colors)
        {
        copyColors(newColors, colors+i*nc, nc);
        copyColors(newColors, colors+i*nc, nc);
        copyColors(newColors, colors+(i+1)*nc, nc);
        copyColors(newColors, colors+i*nc, nc);
        copyColors(newColors, colors+(i+1)*nc, nc);
        copyColors(newColors, colors+(i+1)*nc, nc);
        }
1006 1007 1008 1009 1010 1011 1012

      newDistances[i*12] = distances[i*2];
      newDistances[i*12+2] = distances[i*2];
      newDistances[i*12+4] = distances[i*2+2];
      newDistances[i*12+6] = distances[i*2];
      newDistances[i*12+8] = distances[i*2+2];
      newDistances[i*12+10] = distances[i*2+2];
Ken Martin's avatar
Ken Martin committed
1013 1014 1015
      }

    this->BuildVBO(cbo, &(newVerts[0]), newVerts.size()/2,
1016
      colors ? &(newColors[0]) : NULL, nc, &(newDistances[0]));
1017
    PreDraw(*cbo, GL_TRIANGLES, newVerts.size() / 2);
Ken Martin's avatar
Ken Martin committed
1018
    glDrawArrays(GL_TRIANGLES, 0, newVerts.size()/2);
1019
    PostDraw(*cbo, this->Renderer, this->Pen->GetColor());
Ken Martin's avatar
Ken Martin committed
1020 1021 1022 1023
    }
  else
    {
    this->SetLineWidth(this->Pen->GetWidth());
1024
    this->BuildVBO(cbo, f, n, colors, nc, &(distances[0]));
1025
    PreDraw(*cbo, GL_LINES, n);
Ken Martin's avatar
Ken Martin committed
1026
    glDrawArrays(GL_LINES, 0, n);
1027
    PostDraw(*cbo, this->Renderer, this->Pen->GetColor());
Ken Martin's avatar
Ken Martin committed
1028
    this->SetLineWidth(1.0);
1029 1030
    }

Ken Martin's avatar
Ken Martin committed
1031 1032
  // free everything
  cbo->ReleaseGraphicsResources(this->RenderWindow);
1033 1034 1035 1036

  vtkOpenGLCheckErrorMacro("failed after DrawLines");
}

1037 1038 1039 1040
//-----------------------------------------------------------------------------
void vtkOpenGLContextDevice2D::DrawPoints(float *f, int n, unsigned char *c,
                                          int nc)
{
1041 1042 1043 1044 1045
  if (SkipDraw())
    {
    return;
    }

1046 1047 1048 1049 1050 1051
  // Skip transparent elements.
  if (!c && this->Pen->GetColorObject().GetAlpha() == 0)
    {
    return;
    }

1052 1053
  vtkOpenGLClearErrorMacro();

Ken Martin's avatar
Ken Martin committed
1054
  vtkOpenGLHelper *cbo = 0;
1055
  if (c)
1056
    {
1057 1058
    this->ReadyVCBOProgram();
    cbo = this->VCBO;
1059 1060 1061
    }
  else
    {
1062 1063 1064 1065
    this->ReadyVBOProgram();
    cbo = this->VBO;
    cbo->Program->SetUniform4uc("vertexColor",
      this->Pen->GetColor());
1066 1067
    }

1068 1069 1070 1071 1072
  this->SetPointSize(this->Pen->GetWidth());

  this->BuildVBO(cbo, f, n, c, nc, NULL);
  this->SetMatrices(cbo->Program);

1073
  PreDraw(*cbo, GL_POINTS, n);
1074
  glDrawArrays(GL_POINTS, 0, n);
1075
  PostDraw(*cbo, this->Renderer, this->Pen->GetColor());
1076 1077 1078 1079

  // free everything
  cbo->ReleaseGraphicsResources(this->RenderWindow);

1080 1081 1082 1083 1084 1085 1086 1087 1088
  vtkOpenGLCheckErrorMacro("failed after DrawPoints");
}

//-----------------------------------------------------------------------------
void vtkOpenGLContextDevice2D::DrawPointSprites(vtkImageData *sprite,
                                                float *points, int n,
                                                unsigned char *colors,
                                                int nc_comps)
{
1089 1090 1091 1092 1093
//  // Draw these to the background -- we don't currently export them to GL2PS.
//  if (SkipDraw())
//    {
//    return;
//    }
1094

1095 1096 1097 1098
  vtkOpenGLClearErrorMacro();
  if (points && n > 0)
    {
    this->SetPointSize(this->Pen->GetWidth());
1099

Ken Martin's avatar
Ken Martin committed
1100
    vtkOpenGLHelper *cbo = 0;
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
    if (colors)
      {
      this->ReadySCBOProgram();
      cbo = this->SCBO;
      }
    else
      {
      this->ReadySBOProgram();
      cbo = this->SBO;
      cbo->Program->SetUniform4uc("vertexColor",
        this->Pen->GetColor());
      }

    this->BuildVBO(cbo, points, n, colors, nc_comps, NULL);
    this->SetMatrices(cbo->Program);

1117 1118 1119 1120 1121 1122 1123 1124 1125
    if (sprite)
      {
      if (!this->Storage->SpriteTexture)
        {
        this->Storage->SpriteTexture = vtkTexture::New();
        }
      int properties = this->Brush->GetTextureProperties();
      this->Storage->SpriteTexture->SetInputData(sprite);
      this->Storage->SpriteTexture->SetInterpolate(properties & vtkContextDevice2D::Linear);
Alexis Girault's avatar
Alexis Girault committed
1126 1127 1128 1129 1130 1131 1132 1133
      if (properties & vtkContextDevice2D::Repeat)
        {
        this->Storage->SpriteTexture->SetWrapMode(vtkTexture::VTKTextureWrapMode::Repeat);
        }
      else
        {
        this->Storage->SpriteTexture->SetWrapMode(vtkTexture::VTKTextureWrapMode::ClampToEdge);
        }
1134
      this->Storage->SpriteTexture->Render(this->Renderer);
1135 1136 1137
      int tunit = vtkOpenGLTexture::SafeDownCast(
        this->Storage->SpriteTexture)->GetTextureUnit();
      cbo->Program->SetUniformi("texture1", tunit);
1138 1139
      }

1140
    // We can actually use point sprites here
1141 1142
    if (!vtkOpenGLRenderWindow::GetContextSupportsOpenGL32() ||
        this->RenderWindow->IsPointSpriteBugPresent())
1143
      {
1144 1145
      glEnable(GL_POINT_SPRITE);
      glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
1146
      }
1147
    glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
1148

1149
    glDrawArrays(GL_POINTS, 0, n);
1150

1151 1152
    // free everything
    cbo->ReleaseGraphicsResources(this->RenderWindow);
1153 1154
    if (!vtkOpenGLRenderWindow::GetContextSupportsOpenGL32() ||
        this->RenderWindow->IsPointSpriteBugPresent())
1155 1156 1157
      {
      glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_FALSE);
      glDisable(GL_POINT_SPRITE);
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
      }

    if (sprite)
      {
      this->Storage->SpriteTexture->PostRender(this->Renderer);
      }
    }
  else
    {
    vtkWarningMacro(<< "Points supplied without a valid image or pointer.");
    }
  vtkOpenGLCheckErrorMacro("failed after DrawPointSprites");
}

//-----------------------------------------------------------------------------
void vtkOpenGLContextDevice2D::DrawMarkers(int shape, bool highlight,
                                           float *points, int n,
                                           unsigned char *colors, int nc_comps)
{
1177
  vtkOpenGLGL2PSHelper *gl2ps = vtkOpenGLGL2PSHelper::GetInstance();
1178
  if (gl2ps)
1179
    {
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189
    switch (gl2ps->GetActiveState())
      {
      case vtkOpenGLGL2PSHelper::Capture:
        this->DrawMarkersGL2PS(shape, highlight, points, n, colors, nc_comps);
        return;
      case vtkOpenGLGL2PSHelper::Background:
        return; // Do nothing.
      case vtkOpenGLGL2PSHelper::Inactive:
        break; // Render as normal.
      }
1190 1191
    }

1192 1193 1194 1195 1196 1197 1198 1199 1200
  // Get a point sprite for the shape
  vtkImageData *sprite = this->GetMarker(shape, this->Pen->GetWidth(),
                                         highlight);
  this->DrawPointSprites(sprite, points, n, colors, nc_comps);
}

//-----------------------------------------------------------------------------
void vtkOpenGLContextDevice2D::DrawQuad(float *f, int n)
{
1201 1202 1203 1204 1205
  if (SkipDraw())
    {
    return;
    }

1206 1207 1208 1209 1210
  if (!f || n <= 0)
    {
    vtkWarningMacro(<< "Points supplied that were not of type float.");
    return;
    }
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220