gpt4 book ai didi

iphone - OpenGL ES 运行多个着色器

转载 作者:行者123 更新时间:2023-12-03 20:55:26 24 4
gpt4 key购买 nike

基于上一个问题,我一直在研究如何在一次传递中运行多个着色器(即有一个 FBO 并渲染到纹理)。这是 Iphone 上的 OpenGLES 2。

我创建了一些运行但仅运行一帧的代码。很明显我做错了什么,但我就是无法发现它。

输入输出数据是来自摄像头的 corevideo 缓冲区。

非常欢迎任何指示或修复:)。

谢谢

西蒙

PS:我现在已将所有内容放入一种方法中 - 这样我就可以专注于让它发挥作用!

- (void) PingPong:(CVImageBufferRef)cameraframe;
{
int bufferHeight = CVPixelBufferGetHeight(cameraframe);

int bufferWidth = CVPixelBufferGetWidth(cameraframe);

// Build the first FBO - this is wasteful - don't do this everytime
GLuint firstFBO;
glGenFramebuffers(1, &firstFBO);
glBindFramebuffer(GL_FRAMEBUFFER, firstFBO);

// Build the first texture and copy the video stuff into it
GLuint sourcetexture;
glGenTextures(1, &sourcetexture);
glBindTexture(GL_TEXTURE_2D, sourcetexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);


// Build the second texture
GLuint nextTexture;
glGenTextures(1, &nextTexture);
glBindTexture(GL_TEXTURE_2D, nextTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

// Attach the texture to our first FBO
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sourcetexture, 0);


// Using BGRA extension to pull in video frame data directly
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bufferWidth, bufferHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, CVPixelBufferGetBaseAddress(cameraframe));

//glDrawBuffer(sourcetexture);
glEnable(GL_TEXTURE_2D);
glViewport(0, 0, backingWidth, backingHeight);
glBindTexture(GL_TEXTURE_2D, sourcetexture);
glUseProgram(greyscaleProgram);

// Now do the 2nd pass using the sourcetexture as input
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, nextTexture, 0);
glBindTexture(GL_TEXTURE_2D, nextTexture);
glUseProgram(program);

// Present the framebuffer to the render buffer
[EAGLContext setCurrentContext:context];

glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);

[context presentRenderbuffer:GL_RENDERBUFFER];

// Clean up stuff
glDeleteTextures(1, &sourcetexture);
glDeleteTextures(1, &nextTexture);

}

最佳答案

你的抽奖代码在哪里?绘图是触发着色器执行的原因,而我现在看到的代码具有零绘图调用(glDrawArrays、glDrawElements 等),因此它不起作用,因为您没有绘图。

绘制一个全屏四边形来触发每个 channel 的着色器执行,它将起作用。

此外,建议使用 glCheckFramebufferStatus 来检查您的 FBO 配置是否受支持以及是否适用于您的 GL 实现。

关于iphone - OpenGL ES 运行多个着色器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5466267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com