preface

In the previous article, WE have learned how to draw a square with a fixed storage shader in OpenGL. So this article is mainly to get familiar with and understand the entire rendering process and work content of OpenGL again. Theory and practice are equally important.

Rendering pipeline flow chart

This is a diagram that OpenGL developers need to understand, and any graphics rendering they do in the future will be based on it, and frameworks based on OpenGL encapsulation will follow the rules of this diagram. After learning OpenGL ES, its rendering process is similar or even the same, so the understanding of this picture is quite important!!

Rendering pipeline

In the first article, I actually talked about the rendering pipeline, which was explained and explained, but it may not be that easy to understand.

In OpenGL, everything is in 3D space, whereas screens and Windows are 2D arrays of pixels, so much of OpenGL’s work is about converting 3D coordinates into 2D pixels that fit the screen. The process of converting 3D coordinates to 2D coordinates is managed by OpenGL’s Graphics Pipeline.

The graphics rendering pipeline can be divided into two main parts:

  1. Convert your 3D coordinates to 2D coordinates,
  2. The 2D coordinates are converted to actual colored pixels.

Below is an abstract representation of each stage of a graphics rendering pipeline. The blue ones represent programmable shaders, but we generally use only vertex shaders and fragment shaders:

Rasterization (after pixel assembly)

Rasterization is the operation of converting vector graphics into pixels. Our screens are made up of pixels, while three-dimensional objects are made up of points, lines and planes. To turn points, lines and planes into pixels that can be displayed on a screen, you need a process called Rasterize. It’s going from a vector description of points, lines and planes to a description of pixels.

The following picture is an understanding of the rasterization process. The first step tells the computer that I want to display a circle, and the second step the computer converts the circle into pixels that can be displayed

shader

  • Shaders are written in a C-like language called GLSL. GLSL is tailored for graphical computing and contains some useful features for vector and matrix operations.

  • Shaders always start with a version declaration, followed by input and output variables, uniform, and main functions. The entry point for each shader is the main function, where we process all the input variables and output the results to the output variables.

  • In OpenGL, we must define at least one vertex shader and one fragment shader (since there is no default vertex/fragment shader in the GPU). The rendering process that uses these two shader applets for data transfer processing computation is generally called a programmable pipeline.

Input and output

  • Although shaders are separate small programs, they are all part of a whole, and for this reason we want each shader to have inputs and outputs so that data can be communicated and passed.

  • GLSL defines the in and out keywords specifically for this purpose. Each shader uses these two keywords to set input and output, and as long as an output variable matches the input of the next shader stage, it is passed on. The difference between vertex and fragment shaders is that Attributs can only be passed indirectly to the fragment shader, but can be passed directly to the vertex shader, as illustrated above.

Attributs

Attributes are data elements that are changed for each vertex. In fact, the vertex position itself is a property. Property values can be floating-point, integer, or Boolean.

  • Attributes are always stored internally as four-dimensional vectors, even if we don’t use all four components. A vertex location may store (x,y,z) and will occupy three of the four components.

  • In fact, if you’re in the plane case, as long as you’re drawing in the XY plane, then the Z component is automatically set to zero.

  • Properties can also be: texture coordinates, color values, and light computed surface normals.

  • Properties are copied from local client memory and stored in a buffer on the graphics hardware. These properties are only available to vertex shaders and do not make much sense to slice shaders, but can also be passed to slice shaders.

  • Declaration: These attributes change for each vertex, but it does not mean that their values cannot be repeated. Usually, they’re not the same, but it’s possible that the entire array is the same value.

Uniform

Uniform is a way to send data from an application in the CPU to a shader in the GPU, but Uniform and vertex properties are somewhat different.

  • Uniform is Global. Global means that the UNIFORM variable must be unique within each shader program object, and it can be accessed by any shader of the shader program at any stage.

  • Regardless of what you set uniform values to, UNIFORM holds their data until they are reset or updated, sort of like global static variables.

Textures

A texture is a 2D image (there are even 1D and 3D textures, usually 2D) that can be used to add detail to an object.

  • Texture data can be sampled and filtered in vertex shaders and fragment shaders.

  • A typical application scenario: a fragment shader samples a texture value and applies rendered texture data to a triangular surface, as described below.

  • Texture data, not only in graphics, is stored in many graphics file formats as color components in unsigned bytes (8 bits per color channel), which are later reflected in texture Settings.

  • Think of a texture as a piece of paper painted with bricks that fold seamlessly and fit onto your house so that it looks like your house has a brick facade.

OpenGL introduction (a) — OpenGL professional noun analysis

Introduction to OpenGL (2) — Build an OpenGL Mac environment

OpenGL Start (3) — Quickly draw a square

OpenGL introduction (4) – rendering process analysis

OpenGL introduction (five) – metagraph drawing actual combat

OpenGL Introduction (six) – Matrix basic change actual combat

OpenGL introduction (seven) – hidden surface elimination details

OpenGL Start (eight) – Texture coordinate parsing