Opengl Performer™ Programmer's Guide
Total Page:16
File Type:pdf, Size:1020Kb
OpenGL Performer™ Programmer’s Guide Version 3.1 007-1680-090 CONTRIBUTORS Written by George Eckel and Ken Jones Illustrated by Chrystie Danzer and Chris Wengelski Production by Karen Jacobson Engineering contributions by Angus Dorbie, Paolo Farinelli, Tom Flynn, Yair Kurzion, Radomir Mech, Alexandre Naaman, Marcin Romaszewicz, Allan Schaffer, and Jenny Zhao COPYRIGHT © 1994, 2000–2003 Silicon Graphics, Inc. All rights reserved; provided portions may be copyright in third parties, as indicated elsewhere herein. No permission is granted to copy, distribute, or create derivative works from the contents of this electronic documentation in any manner, in whole or in part, without the prior written permission of Silicon Graphics, Inc. LIMITED RIGHTS LEGEND The electronic (software) version of this document was developed at private expense; if acquired under an agreement with the USA government or any contractor thereto, it is acquired as "commercial computer software" subject to the provisions of its applicable license agreement, as specified in (a) 48 CFR 12.212 of the FAR; or, if acquired for Department of Defense units, (b) 48 CFR 227-7202 of the DoD FAR Supplement; or sections succeeding thereto. Contractor/manufacturer is Silicon Graphics, Inc., 1600 Amphitheatre Pkwy 2E, Mountain View, CA 94043-1351. TRADEMARKS AND ATTRIBUTIONS Silicon Graphics, SGI, the SGI logo, IRIS, IRIX, ImageVision Library, Indigo, Indy, InfiniteReality, O2, Octane, Onyx, Onyx2, and OpenGL are registered trademarks and CASEVision, Crimson, Elan Graphics, IRIS Geometry Pipeline, IRIS GL, IRIS Graphics Library, IRIS InSight, IRIS Inventor, Indigo Elan, Indigo2, InfinitePerformance, InfiniteReality2, InfiniteReality4, Onyx4, OpenGL Multipipe, OpenGL Performer, OpenGL Shader, Performance Co-Pilot, REACT, RealityEngine, RealityEngine2, Showcase,UltimateVision, and VPro are trademarks of Silicon Graphics, Inc., in the United States and/or other countries worldwide. AutoCAD is a registered trademark of Autodesk, Inc. CATIA is a registered trademark of DASSAULT SYSTEMES S.A. Designer’s Workbench is a trademark of Centric Software, Inc. Lightscape is a trademark of Autodesk, Inc. Linux is a registered trademark of Linus Torvalds. Maya is a registered trademark and Wavefront is a trademark of Alias Systems, a division of Silicon Graphics Limited in the United States and/or other countries worldwide. Motif is a registered trademark and X Window System and OSF/Motif are trademarks of The Open Group. Purify is a registered trademark of Rational Software Corporation. Red Hat is a registered trademark of Red Hat, Inc. RPC is a trademark of ArchVision. VTune is a trademark of Intel Corporation. WindView is a trademark of Wind River Systems. Microsoft, Windows, and Windows NT are registered trademarks of Microsoft Corporation in the United States and other countries. PATENT DISCLOSURE Many of the techniques and methods disclosed in this Programmer’s Guide are covered by patents held by Silicon Graphics including U.S. Patent Nos. 5,051,737; 5,369,739; 5,438,654; 5,394,170; 5,528,737; 5,528,738; 5,581,680; 5,471,572 and patent applications pending. We encourage you to use these features in your OpenGL Performer application on SGI systems. This functionality and OpenGL Performer are not available for re-implementation and distribution on other platforms without the explicit permission of Silicon Graphics. New Features in This Guide This revision of the guide documents OpenGL Performer 3.1, which has the following features: • GPU programming on systems like Silicon Graphics Onyx4 UltimateVision visualization systems • Curves and surfaces (higher-order primitives) - Parametric surfaces - Subdivision surfaces • pfGeoArrays for efficient use of vertex arrays on systems like Silicon Graphics Onyx4 UltimateVision visualization systems • New data sources - Maya exporter to OpenGL Performer - CATIA import to OpenGL Performer • Miscellaneous - Small object culling - Linux: RedHat 8 support - Linux: RedHat 9 support - IRIX: Remove O32 support - Linux: Remove gcc2 support 007-1680-090 iii Record of Revision Version Description 020 1994 Original publication. 060 November 2000 Updated for the 2.4 version of OpenGL Performer. 070 November 2001 Updated for the 2.5 version of OpenGL Performer. 080 December 2002 Updated for the 3.0 version of OpenGL Performer. 090 December 2003 Updated for the 3.1 version of OpenGL Performer. 007-1680-090 v Contents Figures . xxix Tables . xxxv Examples . xxxix About This Guide. xliii Why Use OpenGL Performer? . xliii What You Should Know Before Reading This Guide . xliv How to Use This Guide . xliv What This Guide Contains . xliv Sample Applications . xlvi Conventions . xlvii Internet and Hardcopy Reading for the OpenGL Performer Series . xlvii Reader Comments . xlviii 1. OpenGL Performer Programming Interface . 1 General Naming Conventions . 1 Prefixes. 1 Header Files . 2 Naming in C and C++ . 2 Abbreviations . 3 Macros, Tokens, and Enums. 3 Class API . 3 Object Creation . 4 Set Routines . 4 Get Routines . 4 Action Routines . 5 Enable and Disable of Modes . 5 Mode, Attribute, or Value . 6 007-1680-090 vii Contents Base Classes . 6 Inheritance Graph . 7 libpr and libpf Objects . 10 User Data . 10 pfDelete() and Reference Counting . 11 Copying Objects with pfCopy() . 15 Printing Objects with pfPrint() . 15 Determining Object Type . 17 2. Setting Up the Display Environment . 19 Using Pipes . 21 The Functional Stages of a Pipeline . 21 Creating and Configuring a pfPipe . 23 Example of pfPipe Use . 25 Using Channels . 26 Creating and Configuring a pfChannel . .26 Setting Up a Scene . 27 Setting Up a Viewport . 27 Setting Up a Viewing Frustum . 28 Setting Up a Viewpoint . 30 Example of Channel Use . 32 Controlling the Video Output. 34 Using Multiple Channels . 35 One Window per Pipe, Multiple Channels per Window . 36 Using Channel Groups. 40 Multiple Channels and Multiple Windows. 43 Importing OpenGL Multipipe SDK (MPK) Configuration Files . 44 3. Nodes and Node Types . 49 Nodes . 49 Attribute Inheritance . 49 pfNode . 51 pfGroup. 53 viii 007-1680-090 Contents Working with Nodes . 56 Instancing . 56 Bounding Volumes . 59 Node Types. 61 pfScene Nodes. 61 pfSCS Nodes . 62 pfDCS Nodes . 62 pfFCS Nodes . 63 pfDoubleSCS Nodes . 64 pfDoubleDCS Nodes . 64 pfDoubleFCS Nodes . 67 pfSwitch Nodes . 67 pfSequence Nodes . 67 pfLOD Nodes . 70 pfASD Nodes . 70 pfLayer Nodes . 70 pfGeode Nodes . 71 pfText Nodes . 73 pfBillboard Nodes . 75 pfPartition Nodes . 78 Sample Program . 80 4. Database Traversal . 85 Scene Graph Hierarchy . 87 Database Traversals . 87 State Inheritance . 87 Database Organization . 88 Application Traversal . 88 Cull Traversal . 90 Traversal Order . 90 Visibility Culling . 91 Organizing a Database for Efficient Culling . 94 Sorting the Scene . 97 Paths through the Scene Graph . .100 007-1680-090 ix Contents Draw Traversal . 100 Optimizing the Drawing of Sub-bins . 101 Bin Draw Callbacks . 101 Controlling and Customizing Traversals . 102 pfChannel Traversal Modes . 102 Cull Programs . 103 pfNode Draw Mask . 112 pfNode Cull and Draw Callbacks . 113 Process Callbacks . 116 Process Callbacks and Passthrough Data . 118 Intersection Traversal . 120 Testing Line Segment Intersections . 120 Intersection Requests: pfSegSets . 121 Intersection Return Data: pfHit Objects . 121 Intersection Masks. 122 Discriminator Callbacks . 124 Line Segment Clipping . 125 Traversing Special Nodes. 125 Picking . 126 Performance . 126 Intersection Methods for Segments . 127 5. Frame and Load Control . 129 Frame Rate Management . 129 Selecting the Frame Rate . 130 Achieving the Frame Rate . 130 Fixing the Frame Rate . 131 Level-of-Detail Management . 136 Level-of-Detail Models . 136 Level-of-Detail States . 140 Level-of-Detail Range Processing . 141 Level-of-Detail Transition Blending . 145 Run-Time User Control Over LOD Evaluation. 146.