1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
|
/*=========================================================================
Program: Visualization Toolkit
Module: LoadOpenGLExtension.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.
=========================================================================*/
/*
* Copyright 2004 Sandia Corporation.
* Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
* license for use of this work by or on behalf of the
* U.S. Government. Redistribution and use in source and binary forms, with
* or without modification, are permitted provided that this Notice and any
* statement of authorship are reproduced on all copies.
*/
// This code test to make sure vtkOpenGLExtensionManager can properly get
// extension functions that can be used. To do this, we convolve an image
// with a kernel for a Laplacian filter. This requires the use of functions
// defined in OpenGL 1.2, which should be available pretty much everywhere
// but still has functions that can be loaded as extensions.
#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkCamera.h"
#include "vtkCallbackCommand.h"
#include "vtkUnsignedCharArray.h"
#include "vtkRegressionTestImage.h"
#include "vtkOpenGLExtensionManager.h"
#include "vtkgl.h"
#include "vtkOpenGLError.h"
#include "vtkTextActor.h"
#include "vtkTextProperty.h"
static vtkUnsignedCharArray *image;
static GLfloat laplacian[3][3] = {
{ -0.125f, -0.125f, -0.125f },
{ -0.125f, 1.0f, -0.125f },
{ -0.125f, -0.125f, -0.125f }
};
static void ImageCallback(vtkObject *__renwin, unsigned long, void *, void *)
{
static int inImageCallback = 0;
if (inImageCallback)
{
cout << "*********ImageCallback called recursively?" << endl;
return;
}
inImageCallback = 1;
vtkOpenGLClearErrorMacro();
cout << "In ImageCallback" << endl;
vtkRenderWindow *renwin = static_cast<vtkRenderWindow *>(__renwin);
int *size = renwin->GetSize();
cout << "Turn on convolution." << endl;
glEnable(vtkgl::CONVOLUTION_2D);
cout << "Read back image." << endl;
renwin->GetRGBACharPixelData(0, 0, size[0]-1, size[1]-1, 0, image);
cout << "Turn off convolution." << endl;
glDisable(vtkgl::CONVOLUTION_2D);
cout << "Write image." << endl;
renwin->SetRGBACharPixelData(0, 0, size[0]-1, size[1]-1, image, 0);
cout << "Swap buffers." << endl;
renwin->SwapBuffersOn();
renwin->Frame();
renwin->SwapBuffersOff();
inImageCallback = 0;
vtkOpenGLStaticCheckErrorMacro("failed after ImageCallback");
}
int LoadOpenGLExtension(int argc, char *argv[])
{
cout << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << endl;
vtkRenderWindow *renwin = vtkRenderWindow::New();
renwin->SetSize(250, 250);
vtkRenderer *renderer = vtkRenderer::New();
renwin->AddRenderer(renderer);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
renwin->SetInteractor(iren);
vtkOpenGLExtensionManager *extensions = vtkOpenGLExtensionManager::New();
extensions->SetRenderWindow(renwin);
// Force a Render here so that we can call glGetString reliably:
//
renwin->Render();
const char *gl_vendor =
reinterpret_cast<const char *>(glGetString(GL_VENDOR));
const char *gl_version =
reinterpret_cast<const char *>(glGetString(GL_VERSION));
const char *gl_renderer =
reinterpret_cast<const char *>(glGetString(GL_RENDERER));
cout << endl;
cout << "GL_VENDOR: " << (gl_vendor ? gl_vendor : "(null)") << endl;
cout << "GL_VERSION: " << (gl_version ? gl_version : "(null)") << endl;
cout << "GL_RENDERER: " << (gl_renderer ? gl_renderer : "(null)") << endl;
extensions->Update();
cout
<< endl
<< "DriverGLVersion = " << extensions->GetDriverGLVersion() << endl
<< "DriverGLVendor = " << extensions->GetDriverGLVendor() << endl
<< "DriverGLRenderer = " << extensions->GetDriverGLRenderer() << endl
<< "DriverGLVersionMajor = " << extensions->GetDriverGLVersionMajor() << endl
<< "DriverGLVersionMinor = " << extensions->GetDriverGLVersionMinor() << endl
<< "DriverGLVersionPatch = " << extensions->GetDriverGLVersionPatch() << endl
<< "DriverVersionMajor = " << extensions->GetDriverVersionMajor() << endl
<< "DriverVersionMinor = " << extensions->GetDriverVersionMinor() << endl
<< "DriverVersionPatch = " << extensions->GetDriverVersionPatch() << endl
<< "DriverIsATI = " << extensions->DriverIsATI() << endl
<< "DriverIsNvidia = " << extensions->DriverIsNvidia() << endl
<< "DriverIsIntel = " << extensions->DriverIsIntel() << endl
<< "DriverIsMesa = " << extensions->DriverIsMesa() << endl
<< "DriverGLRendererIsOSMesa = " << extensions->DriverGLRendererIsOSMesa() << endl
<< "DriverIsMicrosoft = " << extensions->DriverIsMicrosoft() << endl;
cout << endl;
renwin->Print(cout);
cout << "LoadSupportedExtension..." << endl;
int supported=extensions->ExtensionSupported("GL_VERSION_1_2");
int loaded=0;
if(supported)
{
cout << "Driver claims to support OpenGL 1.2" <<endl;
loaded=extensions->LoadSupportedExtension("GL_VERSION_1_2");
if(loaded)
{
cout << "OpenGL 1.2 features loaded." <<endl;
}
else
{
cout << "Failed to load OpenGL 1.2 features!" <<endl;
}
}
supported=extensions->ExtensionSupported("GL_VERSION_1_3");
if(supported)
{
cout << "Driver claims to support OpenGL 1.3" <<endl;
loaded=extensions->LoadSupportedExtension("GL_VERSION_1_3");
if(loaded)
{
cout << "OpenGL 1.3 features loaded." <<endl;
}
else
{
cout << "Failed to load OpenGL 1.3 features!" <<endl;
}
}
supported=extensions->ExtensionSupported("GL_VERSION_1_4");
if(supported)
{
cout << "Driver claims to support OpenGL 1.4" <<endl;
loaded=extensions->LoadSupportedExtension("GL_VERSION_1_4");
if(loaded)
{
cout << "OpenGL 1.4 features loaded." <<endl;
}
else
{
cout << "Failed to load OpenGL 1.4 features!" <<endl;
}
}
supported=extensions->ExtensionSupported("GL_VERSION_1_5");
if(supported)
{
cout << "Driver claims to support OpenGL 1.5" <<endl;
loaded=extensions->LoadSupportedExtension("GL_VERSION_1_5");
if(loaded)
{
cout << "OpenGL 1.5 features loaded." <<endl;
}
else
{
cout << "Failed to load OpenGL 1.5 features!" <<endl;
}
}
supported=extensions->ExtensionSupported("GL_VERSION_2_0");
if(supported)
{
cout << "Driver claims to support OpenGL 2.0" <<endl;
loaded=extensions->LoadSupportedExtension("GL_VERSION_2_0");
if(loaded)
{
cout << "OpenGL 2.0 features loaded." <<endl;
}
else
{
cout << "Failed to load OpenGL 2.0 features!" <<endl;
}
}
supported=extensions->ExtensionSupported("GL_VERSION_2_1");
if(supported)
{
cout << "Driver claims to support OpenGL 2.1" <<endl;
loaded=extensions->LoadSupportedExtension("GL_VERSION_2_1");
if(loaded)
{
cout << "OpenGL 2.1 features loaded." <<endl;
}
else
{
cout << "Failed to load OpenGL 2.1 features!" <<endl;
}
}
cout << "GetExtensionsString..." << endl;
cout << extensions->GetExtensionsString() << endl;
cout << "Set up pipeline." << endl;
vtkConeSource *cone = vtkConeSource::New();
vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
mapper->SetInputConnection(cone->GetOutputPort());
vtkActor *actor = vtkActor::New();
actor->SetMapper(mapper);
renderer->AddActor(actor);
renderer->ResetCamera();
vtkCamera *camera = renderer->GetActiveCamera();
camera->Elevation(-45);
cout << "Do a render without convolution." << endl;
renwin->Render();
image=0;
if (extensions->LoadSupportedExtension("GL_ARB_imaging"))
{
// Set up a convolution filter. We are using the Laplacian filter, which
// is basically an edge detector. Once vtkgl::CONVOLUTION_2D is enabled,
// the filter will be applied any time an image is transferred in the
// pipeline.
cout << "Set up convolution filter." << endl;
vtkgl::ConvolutionFilter2D(vtkgl::CONVOLUTION_2D, GL_LUMINANCE, 3, 3,
GL_LUMINANCE, GL_FLOAT, laplacian);
vtkgl::ConvolutionParameteri(vtkgl::CONVOLUTION_2D,
vtkgl::CONVOLUTION_BORDER_MODE,
vtkgl::REPLICATE_BORDER);
vtkOpenGLStaticCheckErrorMacro("failed after setting up convolution");
image = vtkUnsignedCharArray::New();
vtkCallbackCommand *cbc = vtkCallbackCommand::New();
cbc->SetCallback(ImageCallback);
renwin->AddObserver(vtkCommand::EndEvent, cbc);
cbc->Delete();
// This is a bit of a hack. The EndEvent on the render window will swap
// the buffers.
renwin->SwapBuffersOff();
cout << "Do test render with convolution on." << endl;
renwin->Render();
}
else
{
renderer->RemoveAllViewProps();
vtkTextActor *t=vtkTextActor::New();
t->SetInput("GL_ARB_imaging not supported.");
t->SetDisplayPosition(125,125);
t->GetTextProperty()->SetJustificationToCentered();
renderer->AddViewProp(t);
t->Delete();
renwin->Render();
}
extensions->Delete();
int retVal = vtkRegressionTestImage(renwin);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
cone->Delete();
mapper->Delete();
actor->Delete();
renderer->Delete();
renwin->Delete();
iren->Delete();
if(image!=0)
{
image->Delete();
}
return !retVal;
}
|