简体   繁体   English

OpenGL - GLM和GLSL,它们有何不同?

[英]OpenGL - GLM and GLSL, how are they different?

I am starting to learn about OpenGL and GLM and GLSL and I am getting a little confused. 我开始学习OpenGL,GLM和GLSL,我有点困惑。 I will say in here what I have understood so far and my questions, so please feel free to correct me anytime. 我会在这里说到目前为止我所理解的和我的问题,所以请随时随地纠正我。

So far I see that GLM extends the GLSL documentation providing more math functions, but since GLM is C++ based it will run on the CPU, on the other hand, GLSL runs directly in the GPU so I guess matrix math is a lot faster in GLSL since it can use the GPU's power to do all the math in parallel. 到目前为止,我看到GLM扩展了GLSL文档,提供了更多的数学函数,但由于GLM是基于C ++的,它将在CPU上运行,另一方面,GLSL直接在GPU中运行,所以我猜GLSL中的矩阵数学运算要快很多因为它可以使用GPU的功能并行完成所有数学运算。 So why to use GLM? 那么为什么要使用GLM呢?

They're completely different things: 他们是完全不同的东西:

  • GLSL is the language used to write shader programs that run on the GPU. GLSL是用于编写在GPU上运行的着色器程序的语言。 It's a variant of C with some special OpenGL-specific extensions. 它是C的变种,带有一些特殊的OpenGL特定扩展。 But as far as your application is concerned, a GLSL shader is just an opaque data file to be passed to the OpenGL library; 但就您的应用程序而言,GLSL着色器只是一个传递给OpenGL库的不透明数据文件; it's completely independent of the host program. 它完全独立于主机程序。
  • GLM is a C++ library for working with vector data on the CPU. GLM是一个C ++库,用于处理CPU上的矢量数据。 For convenience, it follows similar naming conventions to GLSL, but it's completely independent of OpenGL. 为方便起见,它遵循与GLSL类似的命名约定,但它完全独立于OpenGL。

GLM isn't meant as a substitute or alternative to GLSL. GLM不是GLSL的替代品或替代品。 It's meant to help with calculations that wouldn't make sense to do on the GPU — things like building a projection matrix to be used by your vertex shaders, or computing distances between points in 3D space. 它旨在帮助进行在GPU上没有意义的计算 - 例如构建顶点着色器使用的投影矩阵,或计算3D空间中点之间的距离。

They're two completely different things: 他们是两个完全不同的东西:

  • GLSL (OpenGL Shading Language) is a language used by OpenGL (syntax based on C) to run programs on the GPU, called shaders , which you know the purpose of. GLSL(OpenGL着色语言)是OpenGL使用的语言(基于C的语法)在GPU上运行程序,称为着色器 ,你知道它的目的。 They're not even part of your program - instead, they are two files stored in your computer which at runtime are passed to OpenGL and only then they're compiled. 它们甚至不是你程序的一部分 - 相反,它们是存储在你的计算机中的两个文件,它们在运行时传递给OpenGL,然后才编译。 It provides advanced math for two reasons: there's no way to load libraries, and because this is graphics programming , which is very related to math. 它提供高级数学有两个原因:没有办法加载库,因为这是图形编程 ,这与数学非常相关。
  • GLM (OpenGL Mathematics) is a C++ library used to extend C++'s math capabilities with functions and types that are commonly used in graphics programming - all this will be executed on the CPU, and it's independent from OpenGL. GLM(OpenGL数学)是一个C ++库,用于通过图形编程中常用的函数和类型扩展C ++的数学功能 - 所有这些都将在CPU上执行,并且它独立于OpenGL。

The reason GLM has OpenGL in its name is because it was built with graphics programming in their minds (in other words, made for OpenGL). GLM在其名称中使用OpenGL的原因是因为它是在他们的脑海中使用图形编程构建的(换句话说,是为OpenGL制作的)。

Short version: GLM is for your program, GLSL's math capabilities are for your shader. 简短版本:GLM适用于您的程序,GLSL的数学功能适用于您的着色器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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