最近在學習opengl幀快取,在MFC框架視口onCreate函式下呼叫如下init函式創建幀快取,結果檢驗函式一直回傳GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,請教各位大神是哪里出了問題啊
#include "stdafx.h"
#include "PickingEntity.h"
#include "IO.h"
PickingEntity::PickingEntity()
{
}
PickingEntity::~PickingEntity()
{
}
bool PickingEntity::Init(unsigned int WindowWidth, unsigned int WindowHeight)
{
// Create the FBO
glGenFramebuffers(1, &m_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
// Create the texture object for the primitive information buffer
glGenTextures(1, &m_pickingTexture);
glBindTexture(GL_TEXTURE_2D, m_pickingTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, WindowWidth, WindowHeight,
0, GL_RGB_INTEGER, GL_UNSIGNED_INT, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
m_pickingTexture, 0);
// Create the texture object for the depth buffer
glGenTextures(1, &m_depthTexture);
glBindTexture(GL_TEXTURE_2D, m_depthTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, WindowWidth, WindowHeight,
0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,
m_depthTexture, 0);
// Disable reading to avoid problems with older GPUs
glReadBuffer(GL_NONE);
// Verify that the FBO is correct
GLenum Status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (Status == GL_FRAMEBUFFER_COMPLETE) {
//printf("FB error, status: 0x%x\n", Status);
ioMessage("GL_FRAMEBUFFER_COMPLETE");
//ioMessage(Status);
return false;
}
else if (Status == GL_FRAMEBUFFER_UNDEFINED)
{
ioMessage("GL_FRAMEBUFFER_UNDEFINED");
}
else if (Status == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT)
{
ioMessage("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
}
else if (Status == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT)
{
ioMessage("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");
}
else if (Status == GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER)
{
ioMessage("GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER");
}
else if (Status == GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER)
{
ioMessage("GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER");
}
else if (Status == GL_FRAMEBUFFER_UNSUPPORTED)
{
ioMessage("GL_FRAMEBUFFER_UNSUPPORTED");
}
else if (Status == GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE)
{
ioMessage("GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE");
}
else
{
ioMessage("UNKNOW_MISTAKE");
}
// Restore the default framebuffer
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, GL_NONE);
//return GLCheckError();
return true;
}
void PickingEntity::EnableWriting()
{
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo);
}
void PickingEntity::DisableWriting()
{
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, GL_NONE);
}
PickingEntity::PixelInfo PickingEntity::ReadPixel(unsigned int x, unsigned int y)
{
glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo);
glReadBuffer(GL_COLOR_ATTACHMENT0);
PixelInfo Pixel;
glReadPixels(x, y, 1, 1, GL_RGB_INTEGER, GL_UNSIGNED_INT, &Pixel);
glReadBuffer(GL_NONE);
glBindFramebuffer(GL_READ_FRAMEBUFFER, GL_NONE);
return Pixel;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/37080.html
標籤:圖形處理/算法
