渲染WebGL ...属性设置为零时特定于Windows的问题? [英] Windows-specific issue when rendering WebGL... attribute set to zero?

查看:120
本文介绍了渲染WebGL ...属性设置为零时特定于Windows的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WebGL遇到难以调试的问题.我正在为CraftyJS游戏框架实现WebGL后端.一切在OSX,Linux和Android上都可以正常运行,但是当协作者在Windows上进行测试时,会出现一个重要错误-旋转后的精灵无法旋转!我能够跨IE,Chrome和Firefox复制此文件. 顶点程序的类型的示例正在使用,它只会呈现一个彩色矩形:

I'm running into a hard-to-debug issue using WebGL. I was implementing a WebGL backend for the CraftyJS game framework. Everything works absolutely fine on OSX, Linux, and Android, but when a collaborator tested on windows there was an important error -- rotated sprites rendered unrotated! I was able to replicate this across IE, Chrome, and Firefox. An example of the type of vertex program I'm using, which simply renders a colored rectangle:

attribute vec2 aPosition;
attribute vec3 aOrientation;
attribute vec4 aExtra;
attribute vec4 aColor;

varying lowp vec4 vColor;

uniform  vec4 uViewport;

mat4 viewportScale = mat4(2.0 / uViewport.z, 0, 0, 0,    0, -2.0 / uViewport.w, 0,0,    0, 0,1,0,    -1,+1,0,1);
vec4 viewportTranslation = vec4(uViewport.xy, 0, 0);

vec2 entityOrigin = aOrientation.xy;
mat2 entityRotationMatrix = mat2(cos(aOrientation.z), sin(aOrientation.z), -sin(aOrientation.z), cos(aOrientation.z));

void main() {
  vec2 pos = aPosition;
  pos = entityRotationMatrix * (pos - entityOrigin) + entityOrigin ;
  gl_Position = viewportScale * (viewportTranslation + vec4(pos, 1.0/(1.0+exp(aExtra.x) ), 1) );
  vColor = vec4(aColor.rgb*aColor.a*aExtra.y, aColor.a*aExtra.y);
}

问题似乎与aOrientation属性有关-它用于计算旋转矩阵.使用Firefox的着色器编辑器,如果我手动指定entityOriginentityRotationMatrix,则该程序将正确呈现.但是默认情况下,它渲染时好像aOrientation属性的所有组件都只是0.着色器的其他所有方面(位置+尺寸,颜色,alpha透明度,视口缩放/平移)似乎都可以正常工作.唯一依赖于aOrientation的行为已被破坏,并且似乎仅在Windows上存在.

The problem seems to be related to the aOrientation attribute -- it is used to calculate the rotation matrix. Using Firefox's shader editor, if I manually specify entityOrigin and entityRotationMatrix then the program will render correctly. But by default, it renders as if all components of the aOrientation attribute were just 0. Every other aspect of the shader (positioning+dimensions, color, alpha transparency, viewport scale/translation) seems to work fine; it's only behavior which depend on aOrientation that is broken, and seemingly only on Windows.

由于我仅很少访问Windows机器,因此很难调试.是否存在任何特定于Windows的(或特定于硬件/驱动程序的?)问题,可能会导致设置该特定属性的问题?

Since I only have infrequent access to a windows machine this is annoyingly hard to debug. Are there any windows-specific (or hardware/driver specific?) issues that could somehow cause problems setting that one particular attribute?

推荐答案

弄清楚了,一旦我真正有时间坐在一台Windows计算机上并进行实验,编译器就优化"了我在Windows上的属性.我认为这可能与驱动程序/平台/硬件有关.

Figured it out, once I actually had time to sit down with a windows machine and experiment -- the compiler was "optimizing" away my attribute on windows. I guess it makes sense that this might be driver/platform/hardware dependent.

解决方案是将以下行放置在main()内部而不是外部.

The solution was to place the following lines inside of main() instead of outside of it.

vec2 entityOrigin = aOrientation.xy;
mat2 entityRotationMatrix = mat2(cos(aOrientation.z), sin(aOrientation.z), -sin(aOrientation.z), cos(aOrientation.z));

我想我不太了解main内部的代码与main内部的代码之间的区别.值得研究的东西! :)

I guess I don't really understand the difference between code that goes inside of main, and code outside of it. Something to look into! :)

这篇关于渲染WebGL ...属性设置为零时特定于Windows的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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