简体   繁体   English

使用 OpenGL ES 在 iPhone 上渲染到立方体贴图

[英]Render to cube map on iPhone using OpenGL ES

I'm trying to generate dynamic cube map on the iPhone using this code:我正在尝试使用以下代码在iPhone上生成动态立方体贴图:

GLuint textureCubeMap;
glGenTextures(1, &textureCubeMap);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureCubeMap);

for (int i = 0; i < 6; i++) {
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0);
}

GLuint framebuffer;
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, textureCubeMap, 0);

GLenum framebufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (framebufferStatus == GL_FRAMEBUFFER_UNSUPPORTED) {
    Log("Unsupported");
} else if (framebufferStatus == GL_FRAMEBUFFER_COMPLETE) {
    Log("All is OK");
}

When I'm running this code on iOS simulator, I see All is OK message in console.当我在iOS模拟器上运行此代码时,我在控制台中看到All is OK消息。
But running on iPhone 5 with iOS 7 prints Unsupported message.但是在装有iOS 7 iPhone 5上运行会打印Unsupported消息。 As I understand iPhone does not support rendering to cube map.据我了解,iPhone 不支持渲染到立方体贴图。 But I know this is possible because I saw the game with such effect.但是我知道这是可能的,因为我看到了具有这种效果的游戏。 So my question is: What is the correct way to generate dynamic cube map on the iPhone using OpenGL ES ?所以我的问题是:使用OpenGL ESiPhone上生成动态立方体贴图的正确方法是什么?

Try changing the call to the following:尝试将呼叫更改为以下内容:

glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM