简体   繁体   中英

What's the difference between GLSL and c?

I have three questions here:

  1. Is the Qt/3D API implemented by GLSL code?
  2. Is GLSL code compiled and linked as normal c/c++ code, and can it run on CPU (not GPU)?
  3. Why GLSL is better at rendering than normal c/c++?

You seem to have a fundamental misunderstanding of what GLSL is. It's not a programming language for graphics. It is a shader language.

In the OpenGL rendering pipeline , there are certain stages in the rendering of an object that are designed to be implemented by a program. These stages are called "shader stages". A shader is a program, written in GLSL (for OpenGL at least) which is executed at one of these shader stages.

GLSL is used as part of the process of rendering. GLSL defines how things get rendered, not what gets rendered.

Therefore:

Is the Qt/3D API implemented by GLSL code?

Not in the way you mean. Some of the rendering pipeline for the drawing functions may be. But it may not. It's not really relevant to you, since you're using it from the outside.

Is GLSL code compiled and linked as normal c/c++ code, and can it run on CPU (not GPU)?

No, per above. Shaders affect rendering, and rendering takes place on the GPU. GLSL is the shading language for OpenGL, therefore GLSL code is executed on the GPU.

Why GLSL is better at rendering than normal c/c++?

It's not better or worse; you cannot use one for the other. You cannot just throw random C-code at a GPU as part of the rendering pipeline. And you cannot compile GLSL for CPUs.

GLSL is what we call a domain specific language . It is a language designed to facilitate a particular purpose. It has language constructs that most languages simply don't have. It knows what a "texture" is. It has the concept of values which are invariant across multiple executions of a shader within a single rendering call (uniforms). It has many other concepts that are unique to the problem of hardware-based shaders and rendering.

Not only can you not throw C or C++ at a GPU, you wouldn't want to. Not for shaders.

Does the Qt/3D API is implemented by GLSL code?

Not really. It may use some internally, but that's all hidden from the user. The API itself is C++. OpenGL's API is in C, although it (drivers) uses assembly internally.

Does the GLSL code compiled and linked as normal c/c++ code

No, of course not. It's compiled by the video card driver and ran on the GPU. It's a fairly limited language, not much use other than shaders.

Why GLSL is more gift at painting than normal c/c++ ?

It contains features that the GPU is good at, while lacking features it is bad at.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM