Audio and video development sixteen: SDL basic concepts

SDL

texture rendering

texture

​In SDL, a texture is the description information of an image. Represents SDL_Texturea texture object (texture), which is a structure type used to store pixel data .

rendering

​ **Internet explanation: **Rendering is in computer graphics and refers to the process of using software to generate images from models. A model is a description of a three-dimensional object in a strictly defined language or data structure, including geometry, viewpoint, texture, and lighting information.

​ Commonly referred to as video rendering: Editing, adding effects, subtitles, music, etc. are performed on the collected digital video. When generating a video, it is necessary to integrate the added materials into the video and compress it into the final format of the video. This process That's rendering.

​ **Rendering in SDL:** is the process of generating images from data. This data is the data stored in the texture buffer.

texture rendering

Texture rendering is the process of generating an image (rendering) from the information (texture) described by the image stored in the buffer (memory).

Case understanding: Student A draws a picture

Below, we use an example in our daily life 'Student A draws a picture' to explain the concept of SDL rendering and texture.

Using SDL to render and display a picture on a computer is equivalent to drawing a picture on the wall by student A. We first divide the roles in the whole process into texture, renderer, gpu (painter), and cpu (classmate A)

According to the SDL programming method, there are two situations here:

  1. no textures

    That is, the CPU directly draws a picture (the CPU needs to brush the most original rgb/YUV data to the screen), which is equivalent to student A drawing directly on the wall

  2. use texture

    It is equivalent to the little A classmate (cpu) instructing the painter (gpu) to draw on the paper, and then stick the paper on the wall. In this process, the painting is drawn by the painter (gpu), and Xiao A is responsible for giving orders (that is, telling the painter what to draw), the paper represents the texture, and the painter represents the GPU. All drawing operations are performed on the texture. In fact, the concept of texture is not just a piece of paper, but also includes the idea of ​​the painting in the little A classmate, which can be understood as the algorithm of drawing, and the paper is equivalent to a carrier (memory space, used to save these ideas ). The gpu can calculate the color of each pixel of the picture according to the texture (equivalent to the painter drawing a picture according to the description of the little A classmate)

It can be seen that the use of textures can reduce the burden on the cpu. The cpu is in a role of giving orders, and the calculation process of the picture is handed over to the more efficient gpu, which can improve the rendering efficiency.

Why texture data is processed by GPU: Because GPU is an image processing unit, GPU usually has a dedicated texture processing unit, so it can process texture data.

problem analysis

Why use textures?

​ There is a picture, and the pixels of the picture are represented by RGB24 true color. Pass it to the graphics card, and the graphics card can also help us display it. In this case, why use textures?

​ If you draw a straight line with a gradient color. For RGB data, you have to describe each pixel, the ratio of each component of red, yellow and blue. For the texture, it will not be described in this way. It will only describe that there is a line, where the starting point and focus of the line are, and how the intermediate color changes gradually. It will only introduce this description information to you. So like RGB or YUV data, it is a relatively large space in the main memory. The CPU needs to transmit these relevant data to the graphics card, and the graphics card receives these digital data, and then converts these digital signals into visible images to display the video. For texture, it only needs a small space in the main memory, and only stores these description information. After these descriptions are handed over to the graphics card, the calculation result is actually the same as that described by RGB through the calculation of the GPU of the graphics card, and finally displayed to on the screen.

Summarize:

  • Textures take up less space in main memory.

  • The calculation of texture data is performed on the GPU of the graphics card and rendered through hardware acceleration. The RGB data needs to be calculated by the CPU and then handed over to the graphics card. The graphics card can be displayed directly. The GPU is specially used to process images and render, and it is faster than the CPU in processing images.

Why do you say that RGB data is handed over to the CPU for processing?

​ This statement is incorrect at first. RGB data is handed over to the CPU for processing by default. Because in most cases, the CPU is the main computer controller, which is responsible for scheduling and managing all computing and processing tasks, including image processing and rendering.

When processing image and video data, the CPU launches image processing programs or other related applications to perform processing tasks. The CPU can perform some basic image processing tasks such as cropping, scaling, rotating, adjusting chroma, etc. However, when the CPU is processing a large amount of data, performance bottlenecks may occur, resulting in slower processing speed.

If you need to perform large-scale image or video processing, you can consider using GPU to accelerate the processing process and improve processing efficiency. However, it should be noted that using the GPU to process RGB data requires the use of relevant GPU acceleration libraries and image processing software, otherwise the processing effect and speed will be affected.

Whether to use CPU or GPU to process RGB data depends on specific needs and processing tasks. If large-scale data processing and calculations are required, it is recommended to use GPU to process RGB data for better performance and efficiency.

The basic process of rendering

The basic principle is, first create a window window, which is the target we want to render. Then, there must be a rendering context (that is, the renderer). On the one hand, the context stores the target to be rendered, that is, the windows window; on the other hand, it stores a buffer (that is, the texture object), which is used for Store the rendered content (the rendered content is the description information of the image).

The rendered content can be various combinations of points, lines, various graphics, pictures, and videos. The combined content is first stored in the buffer, and finally SDL renders the content in the buffer to the window.

To put it simply: the memory image is converted into a texture by the renderer, and then the texture is handed over to the graphics card for calculation and displayed on the window.

Guess you like

Origin blog.csdn.net/qq_38056514/article/details/130190835