0

This question is specifically about OpenGL 2.0 ES on Android, but if there are more general answers based on the OpenGL specs, I'd be interested in those too.

Is there a way to pass a message (string) out of a GL 2.0 ES shader to the application code (either Java or native)? E.g.

void main()
{
   ...
   if (somecondition)
   {
       logMessage("Things are messed up man");
   }
}

If not, why would a programming environment be defined (OpenGL ES 2.0 shader language in this case) without this type of facility? I don't know anything about hardware but surely this would not be that hard to implement in the GPU. If there are performance issues, it could always be optionally #ifdef'd out of the shader code...

4

2 回答 2

3

不,在任何 OpenGL 着色语言(包括 OpenGL ES)中都没有您要求的日志记录工具。桌面 OpenGL 上的调试上下文(以及当它们到达那里时在 ES 中)可能会提供一些信息,但没有什么比你所要求的要好。

最常见的技术(这通常在片段着色器的上下文中完成)是将着色器的输出设置为错误颜色,或其他指示着色器失败的信号。

给定特定着色器的许多实例同时执行(想想填充全屏四边形时执行了多少片段着色器线程),跟踪每个线程的状态将需要大量状态才能正确完成工作。

你说:

我对硬件一无所知,但在 GPU 中实现这肯定不会那么难。

不; 现代 GPU 是具有复杂设计的复杂机器。虽然这样做是可能的,但不值得额外的复杂性和硬件验证。这就是 API 的魔力,虽然类似的东西在概念上看起来很简单,但事实并非如此。

于 2013-08-02T16:01:30.140 回答
0

激进7的答案是正确的。

如果您想对着色器代码进行调试,GPU 供应商会提供编译器和模拟器。或者您可以尝试使用glm 库并使用 C++ 编写着色器,并使用所有工具来打印您需要的消息。

于 2013-08-04T23:17:28.323 回答