1

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++?
Samuel Harmer
  • 4,264
  • 5
  • 33
  • 67
gemfield
  • 3,228
  • 7
  • 27
  • 28

2 Answers2

13

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • `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.` This is not, strictly speaking, quite true. If you are running OpenGL in [emulation mode](http://stackoverflow.com/questions/7364871/how-to-start-opengl-in-software-emulation-mode), everything will be done on the CPU. – Nicu Stiurca Aug 02 '12 at 23:05
  • 1
    @SchighSchagh: There is no "emulation mode" in OpenGL. The best you'll get is running MesaGL. – Nicol Bolas Aug 03 '12 at 03:48
  • 4
    As far as the OpenGL spec is concerned, there is no mention of any `emulation mode`, but that's because it's an API spec; similarly, the spec doesn't mention GPUs and certainly doesn't mandate that `rendering takes place on the GPU` as you claim. That said, various drivers (MesaGL included as you point out) provide a software-only implementation which runs solely on the CPU. Indeed, the **Introduction** on MesaGL's home page explicitly mentions that Mesa can `be used in many different environments ranging from SOFTWARE EMULATION to complete hardware acceleration for modern GPUs.` – Nicu Stiurca Aug 05 '12 at 02:00
4

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.

Pubby
  • 51,882
  • 13
  • 139
  • 180