Opengl Shading Language
Total Page:16
File Type:pdf, Size:1020Kb
The OpenGL® Shading Language Language Version: 3.30 Document Revision: 6 12-Feb-2010 Editor: John Kessenich, Intel Version 1.1 Authors: John Kessenich, Dave Baldwin, Randi Rost Copyright (c) 2008-20092010 The Khronos Group Inc. All Rights Reserved. This specification is protected by copyright laws and contains material proprietary to the Khronos Group, Inc. It or any components may not be reproduced, republished, distributed, transmitted, displayed, broadcast or otherwise exploited in any manner without the express prior written permission of Khronos Group. You may use this specification for implementing the functionality therein, without altering or removing any trademark, copyright or other notice from the specification, but the receipt or possession of this specification does not convey any rights to reproduce, disclose, or distribute its contents, or to manufacture, use, or sell anything that it may describe, in whole or in part. Khronos Group grants express permission to any current Promoter, Contributor or Adopter member of Khronos to copy and redistribute UNMODIFIED versions of this specification in any fashion, provided that NO CHARGE is made for the specification and the latest available update of the specification for any version of the API is used whenever possible. Such distributed specification may be re-formatted AS LONG AS the contents of the specification are not changed in any way. The specification may be incorporated into a product that is sold as long as such product includes significant independent work developed by the seller. A link to the current version of this specification on the Khronos Group web-site should be included whenever possible with specification distributions. Khronos Group makes no, and expressly disclaims any, representations or warranties, express or implied, regarding this specification, including, without limitation, any implied warranties of merchantability or fitness for a particular purpose or non-infringement of any intellectual property. Khronos Group makes no, and expressly disclaims any, warranties, express or implied, regarding the correctness, accuracy, completeness, timeliness, and reliability of the specification. Under no circumstances will the Khronos Group, or any of its Promoters, Contributors or Members or their respective partners, officers, directors, employees, agents or representatives be liable for any damages, whether direct, indirect, special or consequential damages for lost revenues, lost profits, or otherwise, arising from or in connection with these materials. Khronos, OpenKODE, OpenKOGS, OpenVG, OpenMAX, OpenSL ES and OpenWF are trademarks of the Khronos Group Inc. COLLADA is a trademark of Sony Computer Entertainment Inc. used by permission by Khronos. OpenGL and OpenML are registered trademarks and the OpenGL ES logo is a trademark of Silicon Graphics Inc. used by permission by Khronos. All other product names, trademarks, and/or company names are used solely for identification and belong to their respective owners. 2 Table of Contents 1 Introduction.................................................................................................................................1 1.1 Acknowledgments................................................................................................................1 1.2 Changes ............................................................................................................................... 1 1.2.1 Changes from revision 5...............................................................................................1 1.2.2 Changes from revision 4...............................................................................................2 1.2.3 Changes from revision 3...............................................................................................2 1.2.4 Changes from revision 2 of version 3.30......................................................................2 1.2.5 Changes from revision 1 of version 3.30......................................................................2 1.2.6 Summary of Changes from Version 1.50 (all revisions).............................................. 2 1.3 Overview.............................................................................................................................. 3 1.4 Error Handling......................................................................................................................3 1.5 Typographical Conventions................................................................................................. 3 1.6 Deprecation.......................................................................................................................... 3 2 Overview of OpenGL Shading....................................................................................................4 2.1 Vertex Processor.................................................................................................................. 4 2.2 Geometry Processor............................................................................................................. 4 2.3 Fragment Processor..............................................................................................................4 3 Basics.......................................................................................................................................... 6 3.1 Character Set........................................................................................................................ 6 3.2 Source Strings...................................................................................................................... 6 3.3 Preprocessor......................................................................................................................... 7 3.4 Comments.......................................................................................................................... 12 3.5 Tokens................................................................................................................................13 3.6 Keywords............................................................................................................................13 3.7 Identifiers........................................................................................................................... 15 3.8 Static Use........................................................................................................................... 15 4 Variables and Types..................................................................................................................16 4.1 Basic Types........................................................................................................................ 16 4.1.1 Void............................................................................................................................ 19 4.1.2 Booleans..................................................................................................................... 19 4.1.3 Integers....................................................................................................................... 19 4.1.4 Floats.......................................................................................................................... 21 4.1.5 Vectors........................................................................................................................22 4.1.6 Matrices...................................................................................................................... 22 4.1.7 Samplers..................................................................................................................... 22 4.1.8 Structures....................................................................................................................23 4.1.9 Arrays......................................................................................................................... 24 4.1.10 Implicit Conversions................................................................................................ 26 4.2 Scoping...............................................................................................................................26 4.3 Storage Qualifiers...............................................................................................................28 3 4.3.1 Default Storage Qualifier............................................................................................29 4.3.2 Constant Qualifier...................................................................................................... 29 4.3.3 Constant Expressions................................................................................................. 29 4.3.4 Inputs.......................................................................................................................... 30 4.3.5 Uniform...................................................................................................................... 31 4.3.6 Outputs....................................................................................................................... 32 4.3.7 Interface Blocks..........................................................................................................33 4.3.8 Layout Qualifiers........................................................................................................36 4.3.8.1 Input Layout Qualifiers.......................................................................................36