OpenGL bool制服? [英] OpenGL bool uniform?

查看:350
本文介绍了OpenGL bool制服?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试向OpenGL glsl着色器发送布尔值。



目前我在着色器中有这个:

  uniform bool foo; 

我用它来设置:

  glUniform1i(glGetUniformLocation(shader,foo),true); 

似乎没有 glUniform1b ,所以我把它设置为一个整数。这似乎很好。



这个方法有什么问题吗?它是可移植的,还是可以在其他显卡/驱动程序上破坏?我目前正在使用OpenGL 4.3。

解决方案

OpenGL着色语言支持以下基本数据类型,分组如下:







b $ b

  • bool 条件类型,取值为true或false

  • code> bvec2 一个双组件布尔向量

  • bvec3

  • bvec4 一个四分量布尔向量




...

使条件执行代码更容易表达,支持类型bool。没有预期硬件直接支持这种类型的变量。 (...)


至于设置:


§2.2.1 (...)当使用与该状态的实际类型不同的参数类型指定状态值时,数据转换
执行如下: / p>


  • 当内部状态的类型为boolean时,零整数或浮点值将转换为 FALSE 和非零值转换为 TRUE



I'm trying to send a boolean to an OpenGL glsl shader.

Currently I have this in the shader:

uniform bool foo;

And I use this to set it:

glUniform1i(glGetUniformLocation(shader, "foo"), true);

There doesn't seem to be a glUniform1b, so I'm setting it as an integer. This seems to work fine.

Is there any problem with this approach? Is it portable, or could it break on other graphics cards / drivers? I'm using OpenGL 4.3 at the moment.

解决方案

§ 4.1 Basic Types The OpenGL Shading Language supports the following basic data types, grouped as follows:

  • bool a conditional type, taking on values of true or false
  • bvec2 a two-component Boolean vector
  • bvec3 a three-component Boolean vector
  • bvec4 a four-component Boolean vector

...

§ 4.1.2 Booleans To make conditional execution of code easier to express, the type bool is supported. There is no expectation that hardware directly supports variables of this type. (...)

As for setting:

§ 2.2.1 (...) When state values are specified using a different parameter type than the actual type of that state, data conversions are performed as follows:

  • When the type of internal state is boolean, zero integer or floating-point values are converted to FALSE and non-zero values are converted to TRUE.

这篇关于OpenGL bool制服?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆