OpenGL的布尔制服? [英] OpenGL bool uniform?

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

问题描述

我想一个布尔值发送到一个OpenGL GLSL着色器。

目前我有这个着色器:

 均匀布尔富;

和我使用它来设置它:

  glUniform1i(glGetUniformLocation(着色器,富),TRUE);

似乎没有成为一个 glUniform1b ,所以我将其设置为一个整数。这似乎很好地工作。

有没有使用这种方法的任何问题吗?它是便携式的,或者可以在其他突破的显卡/驱动程序?我使用OpenGL 4.3的时刻。


解决方案

  

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


  
  

      
  • 布尔有条件的类型,承担true或false

  •   
  • bvec2 双组分布尔矢量

  •   
  • bvec3 三分量布尔矢量

  •   
  • bvec4 四种成分布尔矢量

  •   

...


  

第4.1.2节布尔以使code更容易EX preSS的条件执行,BOOL类型的支持。没有期望硬件直接支持此类型的变量。 (...)


至于设置:


  

第2.2.1节(...)当使用不同的参数类型比实际类型国家规定的状态值,数据转换是
  如下进行:


  
  

      
  • 在当前内部状态的类型是布尔值,零整数或浮点数值转换为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的布尔制服?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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