If you are using fixed-function OpenGL: Disabling GLTEXTURE2D is a better way of approaching this problem. Changing bound objects should be done as little as possible. If you are using programmable OpenGL: Neither of these things make much sense. Work your desired behavior into your shaders. If you are using fixed-function OpenGL: Disabling GLTEXTURE2D is a better way of approaching this problem. Changing bound objects should be done as little as possible. If you are using programmable OpenGL: Neither of these things make much sense.
Chapter ObjectivesAfter reading this chapter, you’ll be able to do the following:.Identify the various types of shaders that OpenGL uses to create images.Construct and compile shaders using the OpenGL Shading Language.Pass data into shaders using a variety of mechanisms available in OpenGL.Employ advanced GLSL shading capabilities to make shaders more reusable.This chapter introduces shaders and explains how to use them with OpenGL.
Contents.The OpenGL ES 2.0 pipeline is important for GLSL shaders in OpenGL ES 2.0 and WebGL. It is also very similar to the OpenGL 2.0 pipeline without many of the features that were deprecated in newer versions of OpenGL. Therefore, the OpenGL ES 2.0 pipeline is not only highly relevant for programmers of mobile graphics using OpenGL ES 2.0 and web-based 3D graphics using WebGL, but also a very good starting point to learn about desktop-based 3D graphics using OpenGL, including 3D graphics in game engines such as Blender, Unity and Torque 3D.Parallelism in the OpenGL Pipeline GPUs are highly parallel processors.
This is the main reason for their performance. In fact, they implement two kinds of parallelism: vertical and horizontal parallelism. Assembly plant of the Bell Aircraft Corporation with multiple parallel assembly lines, ca. 1944. Horizontal parallelism describes the possibility to process work in multiple pipelines. This allows for even more parallelism than the vertical parallelism in a single pipeline.
Again, the concept was also employed at Ford Motor Company and in many other industries. In the context of GPUs, horizontal parallelism of the graphics pipeline was an important feature to achieve the performance of modern GPUs.The following diagram shows an illustration of vertical parallelism (processing in stages represented by boxes) and horizontal parallelism (multiple processing units for each stage represented by multiple arrows between boxes).Vertex Datae.g. Triangle meshes provided by 3D modeling tools↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓many vertices are processed in parallelVertex Shadera small program in GLSL is applied to each vertex↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓Primitive Assemblysetup of primitives, e.g. Triangles, lines, and points↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓many primitives are processed in parallelRasterizationinterpolation of data for all pixels covered by the primitive (e.g. Triangle)↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓many fragments (corresponding to pixels) are processed in parallelFragment Shadera small program in GLSL is applied to each fragment (i.e.
Covered pixel)↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓Per-Fragment Operationsconfigurable operations on each fragment (i.e. Covered pixel)↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓results of many fragments are written in parallel to the framebufferFramebufferarray of pixels in which the computed fragment colors are storedIn the following diagrams, there is only one arrow between any two stages. However, it should be understood that GPUs usually implement the graphics pipeline with massive horizontal parallelism. Only software implementations of OpenGL, e.g. Mesa 3D, usually implement a single pipeline.Programmable and Fixed-Function Stages The pipelines of OpenGL ES 1.x and core OpenGL 1.x are configurable fixed-function pipelines, i.e. There is no possibility to include programs in these pipelines.
![Disable Disable](http://www.yaldex.com/open-gl/images/02fig01_alt.jpg)
In OpenGL (ES) 2.0 two stages (the vertex shader and the fragment shader stage) of the pipeline are programmable, i.e. Small programs (shaders) written in GLSL are applied in these stages. In the following diagram, programmable stages are represented by green boxes, fixed-function stages are represented by gray boxes, and data is represented by blue boxes.Vertex Datae.g. Triangle meshes provided by 3D modeling tools↓Vertex Shadera small program in GLSL is applied to each vertex↓Primitive Assemblysetup of primitives, e.g.
Triangles, lines, and points↓Rasterizationinterpolation of data (e.g. Color) for all pixels covered by the primitive↓Fragment Shadera small program in GLSL is applied to each fragment (i.e. Covered pixel)↓Per-Fragment Operationsconfigurable operations on each fragment (i.e. Covered pixel)↓Framebufferarray of pixels in which the computed fragment colors are storedThe vertex shader and fragment shader stages are discussed in more detail in the platform-specific tutorials. The rasterization stage is discussed in and the per-fragment operations in.The primitive assembly stage mainly consists of clipping primitives to the view frustum (the part of space that is visible on the screen) and optional culling of front-facing and/or back-facing primitives.
These possibilities are discussed in more detail in the platform-specific tutorials.Data Flow In order to program GLSL vertex and fragment shaders, it is important to understand the input and ouput of each shader. To this end, it is also useful to understand how data is communicated between all stages of the OpenGL pipeline.