webgl - Emscripten:如何在运行时检测 webgl 上下文版本?
问题描述
我在 Emscripten 中使用 GLFW3 和 GLEW 包装器,所以我不emscripten_webgl_create_context
手动调用也不设置上下文的属性。上下文版本仅由 JS 代码确定,这超出了我的范围。在我的 C++ 代码中,我需要知道我们是在 WebGL1 还是 WebGL2 上下文中运行。有没有一种独立于文件的方式来做到这一点?就像是:
const auto ctx = emscripten_webgl_get_current_context();
emscripten_webgl_get_context_version(ctx);// Should return 1 or 2.
解决方案
在 C++ 中
const char ES_VERSION_2_0[] = "OpenGL ES 2.0";
const char ES_VERSION_3_0[] = "OpenGL ES 3.0";
const char* version = glGetString(GL_VERSION);
if (strncmp(version, ES_VERSION_2_0, sizeof(ES_VERSION_2_0)) == 0) {
// it's WebGL1
} else if (strncmp(version, ES_VERSION_3_0, sizeof(ES_VERSION_3_0)) == 0) {
// it's WebGL2
} else {
// it's something else
}
WebGL 中的版本字符串具有必需的非硬件相关的起始格式。请参阅WebGL2 的规范
VERSION:返回 WebGL<space>2.0<optional><space><vendor-specific information></optional> 形式的版本或发行版号。
对于WebGL1
VERSION:返回 WebGL<space>1.0<space><vendor-specific information> 形式的版本或发行版号。
Emscripten 还返回固定字符串。查看源代码
推荐阅读
- r - 当特定列相等时所有行的总和-R中的-data.frame
- c++ - 把课堂传进课堂
- reactjs - 在 React 测试站点上阻止 Chrome 自动填充电子邮件/密码?
- websocket - 与 websockets 握手时连接关闭
- flutter - Flutter 无法在父 ListView 中实现类似 Swipeable Tabs 的 PageView
- python - 将代码和打印结果合并到 excel .csv 文件中
- excel - 来自另一个工作簿的 excel 加载项 .xla 参考
- javascript - 您在 Redux Observable 中预期流的位置提供了 `undefined`
- postgresql - 应该使用什么样的键来对同一个数据库表中的多行进行分组?
- python - 渲染动态烧瓶 WTForm FieldList 的最佳实践(带嵌套)