コード例 #1
0
bool OffscreenRenderer::initFrameBuffer(int width, int height, Buffer& buffer)
{
  mainGlWidget->makeCurrent();

#ifndef OSX
  if(!GLEW_EXT_framebuffer_object)
    return false;
#endif

  glGenFramebuffersEXT(1, &buffer.frameBufferId);
  glGenRenderbuffersEXT(2, buffer.renderBufferIds);

  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, buffer.frameBufferId);

  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, buffer.renderBufferIds[0]);
  glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height);
  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, buffer.renderBufferIds[1]);
  glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, width, height);
  glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, buffer.renderBufferIds[0]);
  glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, buffer.renderBufferIds[1]);

  GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
  if(status != GL_FRAMEBUFFER_COMPLETE_EXT)
  {
    glDeleteFramebuffersEXT(1, &buffer.frameBufferId);
    glDeleteRenderbuffersEXT(2, buffer.renderBufferIds);
    buffer.frameBufferId = 0;
    return false;
  }

  return true;
}
コード例 #2
0
void PCSSShadowMap::reInit(DrawEnv *pEnv)
{
#ifdef USE_FBO_FOR_COLOR_AND_FACTOR_MAP
    Int32   width = _shadowVP->getPixelWidth();
    Int32   height = _shadowVP->getPixelHeight();

    Window *win = pEnv->getWindow();

    win->validateGLObject(_colorMap->getGLId(), pEnv);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fb);
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
                              GL_TEXTURE_2D,
                              win->getGLObjectId(_colorMap->getGLId()), 0);
    win->validateGLObject(_shadowFactorMap->getGLId(), pEnv);
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT,
                              GL_TEXTURE_2D,
                              win->getGLObjectId(_shadowFactorMap->getGLId()),
                              0);

    //Initialize Depth Renderbuffer
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, _rb_depth);
    if(_useNPOTTextures)
        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24_ARB,
                                 _shadowVP->getPixelWidth(),
                                 _shadowVP->getPixelHeight());
    else
        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24_ARB,
                                 _widthHeightPOT, _widthHeightPOT);
    //Attach Renderbuffer to Framebuffer depth Buffer
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT
                                 , _rb_depth);
#endif
}
		//note corner1, 2, 3 must be specified counterclockwise (when looking at the face with the texture)
		//further, corner1 will be the bottom left of the image, corner 2 bottom right, corner 3 top right
MARS_Graphic_ImageOnQuad::MARS_Graphic_ImageOnQuad(const char* name, GLubyte transparentr, GLubyte transparentg, GLubyte transparentb, GLubyte alpha, int windowWidth, int windowHeight, vector3<GLfloat> corner1, vector3<GLfloat> corner2, vector3<GLfloat> corner3, char* imageData, int imageWidth, int imageHeight) : MARS_Graphic(name,0,0,0,alpha) {
	this->corner1 = corner1;
	this->corner2 = corner2;
	this->corner3 = corner3;
	this->imageData = imageData;
	this->imageWidth = imageWidth;
	this->imageHeight = imageHeight;
	this->windowWidth = windowWidth;
	this->windowHeight = windowHeight;
	this->transparent[0] = (GLfloat)transparentr/255.0;
	this->transparent[1] = (GLfloat)transparentg/255.0;
	this->transparent[2] = (GLfloat)transparentb/255.0;	
			
	this->stencilData = new GLubyte[windowHeight*windowWidth];
	this->frameData = new GLubyte[windowHeight*windowWidth*3];
			
			
	//prepare the texture
	glGenTextures(1, &this->texID);
	glBindTexture(GL_TEXTURE_2D, texID);
	// the texture wraps over at the edges (repeat)
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	
	if (MIPMAPPING){
		//mipmapping enabled
		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
	}
	else {
		//mipmapping disabled
		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
				glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
	}	
			
	if (glewIsSupported("GL_EXT_framebuffer_object") == GL_FALSE){
		  std::cout << "ERROR: NO FBO support" << std::endl;
		  std::cout << "Did you try to call the ImageOnQuad constructor before calling MARS_Engine.init??" << std::endl;
		  std::cout << "This constructor relies on glew/glut being initialized, which occurs in MARS_Engine.init" << std::endl;
		  std::cout << "If your code is fine, and the problem persists, try rebooting, and/or updating your videocard driver." << std::endl;
	} 
			
	//prepare the framebuffer
	glGenFramebuffersEXT(1, &this->fboID);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, this->fboID); //bind the framebuffer
	//first, depth buffer
	glGenRenderbuffersEXT(1, &this->fbo_depthID); // depth buffer ID
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo_depthID); // bind the render buffer
	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, windowWidth, windowHeight); //allocates depth buffer-type storage for this renderbuffer
	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, fbo_depthID); //attaches the buffer to the FBO as a depthbuf
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); // Unbind the depth buffer 
	//next, renderbuffer
	glGenRenderbuffersEXT(1, &this->fbo_renderID); // depth buffer ID
			glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo_renderID); // bind the render buffer
	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB8, windowWidth, windowHeight); //allocates depth buffer-type storage for this renderbuffer
	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, fbo_renderID); //attaches the render buffer to FBO
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); // Unbind the depth buffer 
	//finally, unbind the framebuffer
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);//unbind (switch back to rendering on backbuffer)	
}
コード例 #4
0
ファイル: fbotest2.c プロジェクト: eviom/mesademos
static void
Init( void )
{
    if (!glutExtensionSupported("GL_EXT_framebuffer_object")) {
        printf("fbotest2: GL_EXT_framebuffer_object not found!\n");
        exit(0);
    }
    printf("fbotest2: GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));

    glGenFramebuffersEXT(1, &MyFB);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB);
    assert(glIsFramebufferEXT(MyFB));

    /* set color buffer */
    glGenRenderbuffersEXT(1, &ColorRb);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, ColorRb);
    assert(glIsRenderbufferEXT(ColorRb));
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
                                 GL_RENDERBUFFER_EXT, ColorRb);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);

    /* setup depth buffer */
    glGenRenderbuffersEXT(1, &DepthRb);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, DepthRb);
    assert(glIsRenderbufferEXT(DepthRb));
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
                                 GL_RENDERBUFFER_EXT, DepthRb);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, Width, Height);

    CheckError(__LINE__);

    /* restore to default */
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    CheckError(__LINE__);
}
コード例 #5
0
ファイル: drawbuffers2.c プロジェクト: Distrotech/mesa-demos
static void
SetupRenderbuffers(void)
{
   glGenFramebuffersEXT(1, &FBobject);
   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBobject);

   glGenRenderbuffersEXT(3, RBobjects);

   glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, RBobjects[0]);
   glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);

   glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, RBobjects[1]);
   glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);

   glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, RBobjects[2]);
   glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT,
                            Width, Height);

   glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
                                GL_RENDERBUFFER_EXT, RBobjects[0]);
   glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT,
                                GL_RENDERBUFFER_EXT, RBobjects[1]);
   glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
                                GL_RENDERBUFFER_EXT, RBobjects[2]);

   CheckError(__LINE__);
}
コード例 #6
0
ファイル: gloffscreen.cpp プロジェクト: Kenzu/solvespace
bool GLOffscreen::begin(int width, int height) {
    if(_width != width || _height != height) {
        delete[] _pixels;
        delete[] _pixels_inv;

        _pixels = new uint32_t[width * height * 4];
        _pixels_inv = new uint32_t[width * height * 4];

        _width = width;
        _height = height;
    }

    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _framebuffer);

    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, _color_renderbuffer);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, _width, _height);
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
                              GL_RENDERBUFFER_EXT, _color_renderbuffer);

    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, _depth_renderbuffer);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, _width, _height);
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
                              GL_RENDERBUFFER_EXT, _depth_renderbuffer);

    if(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) == GL_FRAMEBUFFER_COMPLETE_EXT)
        return true;

    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    return false;
}
コード例 #7
0
ファイル: fbo-storage-formats.c プロジェクト: nobled/piglit
static enum piglit_result
test(void)
{
   GLuint fbo, rb;
   int i;
   GLboolean pass = GL_TRUE;
   GLenum err;

   glGenFramebuffersEXT(1, &fbo);
   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
   check_error(__LINE__);

   glGenRenderbuffersEXT(1, &rb);
   check_error(__LINE__);
   glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb);

   glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
                                GL_COLOR_ATTACHMENT0,
                                GL_RENDERBUFFER_EXT,
                                rb);
   check_error(__LINE__);

   /* clear out any errors */
   while (glGetError())
      ;

   /* test formats that should be accepted */
   for (i = 0; i < ARRAY_SIZE(Formats); i++) {
      if (!HaveExtension[Formats[i].extension])
          continue;

      glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, Formats[i].format,
                               piglit_width, piglit_height);
      err = glGetError();
      if (err) {
         printf("%s: glRenderbufferStorage failed for format 0x%x\n",
                TestName, Formats[i].format);
         pass = GL_FALSE;
      }
      printf("0x%04X: %s\n", Formats[i].format,
             glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) == GL_FRAMEBUFFER_COMPLETE_EXT ?
             "complete" : "incomplete");
   }

   /* test formats that should fail */
   for (i = 0; i < ARRAY_SIZE(InvalidFormats); i++) {
      glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, InvalidFormats[i],
                               piglit_width, piglit_height);
      err = glGetError();
      if (err != GL_INVALID_ENUM) {
         printf("%s: glRenderbufferStorage erroneously accepted format 0x%x\n",
                TestName, InvalidFormats[i]);
         pass = GL_FALSE;
      }
   }

   return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
コード例 #8
0
bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer)
{
    // Create the context
    m_context = new Context;

    // Create the framebuffer object
    GLuint frameBuffer = 0;
    glCheck(glGenFramebuffersEXT(1, &frameBuffer));
    m_frameBuffer = static_cast<unsigned int>(frameBuffer);
    if (!m_frameBuffer)
    {
        err() << "Impossible to create render texture (failed to create the frame buffer object)" << std::endl;
        return false;
    }
    glCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_frameBuffer));

    // Create the depth buffer if requested
    if (depthBuffer || sfExt::StencilBufferEnabled)
    {
        GLuint depth = 0;
        glCheck(glGenRenderbuffersEXT(1, &depth));
        m_depthBuffer = static_cast<unsigned int>(depth);
        if (!m_depthBuffer)
        {
            err() << "Impossible to create render texture (failed to create the attached depth buffer)" << std::endl;
            return false;
        }
        glCheck(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer));
        if(sfExt::StencilBufferEnabled)
        {
            err() << "Creating FBO with stencil" << std::endl;
            glCheck(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, width, height));
            glCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer));
            glCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer));
        }
        else
        {
            glCheck(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height));
            glCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer));
        }
    }

    // Link the texture to the frame buffer
    glCheck(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textureId, 0));

    // A final check, just to be sure...
    if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT)
    {
        glCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
        err() << "Impossible to create render texture (failed to link the target texture to the frame buffer)" << std::endl;
        return false;
    }

    return true;
}
コード例 #9
0
ファイル: fge_fbuffer.c プロジェクト: ILeonor/FGE
byte
fge_fbuffer_create(struct fge_fbuffer *buffer)
{
	int32	depth_format;
	int32	stencil_format;

	if ((buffer->width <=0) || (buffer->height <= 0)){
		return 0;
	}

	glGenFramebuffersEXT(1, &buffer->frame_buffer);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, buffer->frame_buffer);

	depth_format	= 0;
	stencil_format	= 0;

	if (buffer->flags & DEPTH16)
		depth_format	= GL_DEPTH_COMPONENT16_ARB;
	else
	if (buffer->flags & DEPTH24)
		depth_format	= GL_DEPTH_COMPONENT24_ARB;
	else
	if (buffer->flags & DEPTH32)
		depth_format	= GL_DEPTH_COMPONENT32_ARB;

	if (buffer->flags & STENCIL1)
		stencil_format	= GL_STENCIL_INDEX1_EXT;
	else
	if (buffer->flags & STENCIL4)
		stencil_format	= GL_STENCIL_INDEX4_EXT;
	else
	if (buffer->flags & STENCIL8)
		stencil_format	= GL_STENCIL_INDEX8_EXT;
	else
	if (buffer->flags & STENCIL16)
		stencil_format	= GL_STENCIL_INDEX16_EXT;

	if (depth_format != 0){
		glGenRenderbuffersEXT(1, &buffer->depth_buffer);
		glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, buffer->depth_buffer);
		glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, buffer->depth_buffer, buffer->width, buffer->height);
		glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, buffer->depth_buffer);
	}

	if (stencil_format != 0){
		glGenRenderbuffersEXT(1, &buffer->stencil_buffer);
		glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, buffer->stencil_buffer);
		glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, buffer->stencil_buffer, buffer->width, buffer->height);
		glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, buffer->stencil_buffer);
	}

	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

	return GL_FRAMEBUFFER_COMPLETE_EXT;
}
コード例 #10
0
bool SkEGLContext::init(int width, int height) {
    GLint major, minor;
    AGLContext ctx;

    aglGetVersion(&major, &minor);
    //SkDebugf("---- agl version %d %d\n", major, minor);

    const GLint pixelAttrs[] = {
        AGL_RGBA,
        AGL_STENCIL_SIZE, 8,
/*
        AGL_SAMPLE_BUFFERS_ARB, 1,
        AGL_MULTISAMPLE,
        AGL_SAMPLES_ARB, 2,
*/
        AGL_ACCELERATED,
        AGL_NONE
    };
    AGLPixelFormat format = aglChoosePixelFormat(NULL, 0, pixelAttrs);
    //AGLPixelFormat format = aglCreatePixelFormat(pixelAttrs);
    //SkDebugf("----- agl format %p\n", format);
    ctx = aglCreateContext(format, NULL);
    //SkDebugf("----- agl context %p\n", ctx);
    aglDestroyPixelFormat(format);

/*
    static const GLint interval = 1;
    aglSetInteger(ctx, AGL_SWAP_INTERVAL, &interval);
*/

    aglSetCurrentContext(ctx);
    this->context = ctx;

    // Now create our FBO render target

    GLuint cbID;
    GLuint dsID;
    glGenFramebuffersEXT(1, &fFBO);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fFBO);
    glGenRenderbuffersEXT(1, &cbID);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, cbID);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA, width, height);
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER_EXT, cbID);
    glGenRenderbuffersEXT(1, &dsID);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, dsID);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL, width, height);
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER_EXT, dsID);
    glViewport(0, 0, width, height);
    glClearStencil(0);
    glClear(GL_STENCIL_BUFFER_BIT);

    GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
    return GL_FRAMEBUFFER_COMPLETE_EXT == status;
}
コード例 #11
0
    /** Try a certain FBO format, and return the status. Also sets mDepthRB and mStencilRB.
        @returns true    if this combo is supported
                 false   if this combo is not supported
    */
    GLuint GLFBOManager::_tryFormat(GLenum depthFormat, GLenum stencilFormat)
    {
        GLuint status, depthRB = 0, stencilRB = 0;
        bool failed = false; // flag on GL errors

        if(depthFormat != GL_NONE)
        {
            /// Generate depth renderbuffer
            glGenRenderbuffersEXT(1, &depthRB);
            /// Bind it to FBO
            glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthRB);
            
            /// Allocate storage for depth buffer
            glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, depthFormat,
                                PROBE_SIZE, PROBE_SIZE);
            
            /// Attach depth
            glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
                                    GL_RENDERBUFFER_EXT, depthRB);
        }

        if(stencilFormat != GL_NONE)
        {
            /// Generate stencil renderbuffer
            glGenRenderbuffersEXT(1, &stencilRB);
            /// Bind it to FBO
            glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, stencilRB);
            glGetError(); // NV hack
            /// Allocate storage for stencil buffer
            glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, stencilFormat,
                                PROBE_SIZE, PROBE_SIZE); 
            if(glGetError() != GL_NO_ERROR) // NV hack
                failed = true;
            /// Attach stencil
            glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
                            GL_RENDERBUFFER_EXT, stencilRB);
            if(glGetError() != GL_NO_ERROR) // NV hack
                failed = true;
        }
        
        status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
        /// If status is negative, clean up
        // Detach and destroy
        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
        if (depthRB)
            glDeleteRenderbuffersEXT(1, &depthRB);
        if (stencilRB)
            glDeleteRenderbuffersEXT(1, &stencilRB);
        
        return status == GL_FRAMEBUFFER_COMPLETE_EXT && !failed;
    }
コード例 #12
0
	virtual void onCreate() {
		CubeMapTexture::onCreate();
		
		// one FBO to rule them all...
		glGenFramebuffersEXT(1, &mFboId);
		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFboId);
		//Attach one of the faces of the Cubemap texture to this FBO
		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_X, id(), 0);

		
		glGenRenderbuffersEXT(1, &mRboId);
		glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mRboId);
		glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, mResolution, mResolution);
		// Attach depth buffer to FBO
		glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mRboId);
		
		// ...and in the darkness bind them:
		for (unsigned face=0; face<6; face++) {
			glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+face, GL_TEXTURE_CUBE_MAP_POSITIVE_X+face, id(), 0);
		}
		
		//Does the GPU support current FBO configuration?
		GLenum status;
		status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
		if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
			printf("GPU does not support required FBO configuration\n");
			exit(0);
		}
		
		// cleanup:
		glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
	}
コード例 #13
0
ファイル: DrawBuffer.cpp プロジェクト: scottrick/dgame
DrawBuffer::DrawBuffer(int x, int y)
{
	if (gShaderManager()->IsShadersSupported())
	{
		glGenFramebuffersEXT(1, &m_dwFrameBuffer);
		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_dwFrameBuffer);

		glGenRenderbuffersEXT(1, &m_dwDepthBuffer);
		glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_dwDepthBuffer);
		glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, x, y);
		
		glGenTextures(1, &m_dwTexture);
		glBindTexture(GL_TEXTURE_2D, m_dwTexture);

		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_dwTexture, 0);
		glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_dwDepthBuffer);

		GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);	

		DrawBuffer::BindDefault();
	}
}
コード例 #14
0
ファイル: renderer.cpp プロジェクト: gbuzogany/Trabalho-CG
void Renderer::createFBO()
{
    glGenFramebuffersEXT(1, &fbo);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
    
    // create a renderbuffer object to store depth info
    // NOTE: A depth renderable image should be attached the FBO for depth test.
    // If we don't attach a depth renderable image to the FBO, then
    // the rendering output will be corrupted because of missing depth test.
    // If you also need stencil test for your rendering, then you must
    // attach additional image to the stencil attachement point, too.
    glGenRenderbuffersEXT(1, &rbo);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rbo);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, WIDTH*msaa, HEIGHT*msaa);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
    
    // attach a texture to FBO color attachement point
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, img, 0);
    
    // attach a renderbuffer to depth attachment point
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rbo);

    GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
    if(status == GL_FRAMEBUFFER_COMPLETE_EXT)
    {
        printf("FBO Setup complete!\n");
    }
    else
    {
        printf("FBO Error!\n");
    }
    
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
コード例 #15
0
/*
================
R_CreateFBOPackedDepthStencilBuffer
================
*/
void R_CreateFBOPackedDepthStencilBuffer( FBO_t *fbo, int format )
{
	qboolean absent;

	if ( format != GL_DEPTH_STENCIL_EXT && format != GL_DEPTH24_STENCIL8_EXT )
	{
		ri.Printf( PRINT_WARNING, "R_CreateFBOPackedDepthStencilBuffer: format %i is not depth-stencil-renderable\n", format );
		return;
	}

	fbo->packedDepthStencilFormat = format;

	absent = fbo->packedDepthStencilBuffer == 0;

	if ( absent )
	{
		glGenRenderbuffersEXT( 1, &fbo->packedDepthStencilBuffer );
	}

	glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, fbo->packedDepthStencilBuffer );
	glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, fbo->packedDepthStencilFormat, fbo->width, fbo->height );
	GL_CheckErrors();

	if ( absent )
	{
		glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT,
		                              fbo->packedDepthStencilBuffer );
		glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT,
		                              fbo->packedDepthStencilBuffer );
	}

	GL_CheckErrors();
}
コード例 #16
0
/*
================
R_CreateFBODepthBuffer
================
*/
void R_CreateFBODepthBuffer( FBO_t *fbo, int format )
{
	qboolean absent;

	if ( format != GL_DEPTH_COMPONENT &&
	     format != GL_DEPTH_COMPONENT16 && format != GL_DEPTH_COMPONENT24 && format != GL_DEPTH_COMPONENT32_ARB )
	{
		ri.Printf( PRINT_WARNING, "R_CreateFBODepthBuffer: format %i is not depth-renderable\n", format );
		return;
	}

	fbo->depthFormat = format;

	absent = fbo->depthBuffer == 0;

	if ( absent )
	{
		glGenRenderbuffersEXT( 1, &fbo->depthBuffer );
	}

	glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, fbo->depthBuffer );
	glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, fbo->depthFormat, fbo->width, fbo->height );

	if ( absent )
	{
		glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, fbo->depthBuffer );
	}

	GL_CheckErrors();
}
コード例 #17
0
/*
================
R_CreateFBOColorBuffer

Framebuffer must be bound
================
*/
void R_CreateFBOColorBuffer( FBO_t *fbo, int format, int index )
{
	qboolean absent;

	if ( index < 0 || index >= glConfig2.maxColorAttachments )
	{
		ri.Printf( PRINT_WARNING, "R_CreateFBOColorBuffer: invalid attachment index %i\n", index );
		return;
	}

	fbo->colorFormat = format;

	absent = fbo->colorBuffers[ index ] == 0;

	if ( absent )
	{
		glGenRenderbuffersEXT( 1, &fbo->colorBuffers[ index ] );
	}

	glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, fbo->colorBuffers[ index ] );
	glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, format, fbo->width, fbo->height );

	if ( absent )
	{
		glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + index, GL_RENDERBUFFER_EXT,
		                              fbo->colorBuffers[ index ] );
	}

	GL_CheckErrors();
}
コード例 #18
0
void
piglit_init(int argc, char **argv)
{
	GLint rb_samples;
	GLuint rb;
	bool pass = true;

	piglit_require_extension("GL_EXT_framebuffer_multisample");

	glGenRenderbuffersEXT(1, &rb);
	glBindRenderbufferEXT(GL_RENDERBUFFER, rb);
	glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_RGBA, 1, 1);
	glGetRenderbufferParameterivEXT(GL_RENDERBUFFER,
					GL_RENDERBUFFER_SAMPLES,
					&rb_samples);

	if (rb_samples != 0) {
		fprintf(stderr, "glRenderbufferStorageEXT() produced %d samples\n",
			rb_samples);
		pass = false;
	}

	glDeleteRenderbuffersEXT(1, &rb);

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
コード例 #19
0
void createFrameBuffer(FrameBuffer &fb, bool depth) {
   // Create the color render buffer
   glGenTextures(1, &fb.texture);
   glBindTexture(GL_TEXTURE_2D, fb.texture);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fb.bufferSize.x , fb.bufferSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glBindTexture(GL_TEXTURE_2D, 0);
   checkError("Creation of the color texture for the FBO");
   
   // Create the depth render buffer
   if (depth) {
      glGenRenderbuffersEXT(1, &fb.depth);
      glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fb.depth);
      glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24,  fb.bufferSize.x,  fb.bufferSize.y);
      checkError("Creation of the depth renderbuffer for the FBO");
   }
   else {
      fb.depth = 0;
   }
   
   // Create the FBO
   glGenFramebuffersEXT(1, &fb.fbo);
   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb.fbo);
   glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fb.texture, 0);
   if (depth) {
      glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, fb.depth);
   }
   checkFBO();
   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
   checkError("Creation of the FBO");
}
コード例 #20
0
ファイル: framebuffer.cpp プロジェクト: mmozeiko/Squares3D
void FrameBuffer::attachRBufDepth()
{
    glGenRenderbuffersEXT(1, (GLuint*)&m_shadowRBuf);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_shadowRBuf);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, m_sizeX, m_sizeY);
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_shadowRBuf);
}
コード例 #21
0
ファイル: FBO.cpp プロジェクト: alexpaulzor/projectm
GLuint RenderTarget::initRenderToTexture()
{
#ifdef USE_FBO

  if (this->useFBO==1)
    {
      this->renderToTexture=1;
      
      GLuint   fb2, depth_rb2;
      glGenFramebuffersEXT(1, &fb2);
      glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fb2 );
      glGenRenderbuffersEXT(1, &depth_rb2);
      glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, depth_rb2 );
      
      glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, this->texsize,this->texsize  );
      glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb2 );         
      this->fbuffer[1] = fb2;
      this->depthb[1]=  depth_rb2;
      glGenTextures(1, &this->textureID[2]);
      glBindTexture(GL_TEXTURE_2D, this->textureID[2]); 
      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, texsize, texsize, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
      glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, this->textureID[2], 0 );
      return this->textureID[2];
    }
#endif 
return -1;
      
}
コード例 #22
0
void testApp::generateFrameBuffers(){
	
	// create a framebuffer object, you need to delete them when program exits.
	glGenFramebuffersEXT(1, &fboId);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);

	// create a renderbuffer object to store depth info
	// NOTE: A depth renderable image should be attached the FBO for depth test.
	// If we don't attach a depth renderable image to the FBO, then
	// the rendering output will be corrupted because of missing depth test.
	// If you also need stencil test for your rendering, then you must
	// attach additional image to the stencil attachement point, too.
	glGenRenderbuffersEXT(1, &rboId);
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rboId);
	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, ofGetWidth(), ofGetHeight());
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);

	// attach a texture to FBO color attachement point
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colourTextureId, 0);

	// attach a renderbuffer to depth attachment point
	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rboId);

	//@ disable color buffer if you don't attach any color buffer image,
	//@ for example, rendering depth buffer only to a texture.
	//@ Otherwise, glCheckFramebufferStatusEXT will not be complete.
	//glDrawBuffer(GL_NONE);
	//glReadBuffer(GL_NONE);

	// check FBO status
	printFramebufferInfo();
	bool status = checkFramebufferStatus();
	if(!status)
		fboUsed = false;
}
コード例 #23
0
ファイル: fbo-extended-blend.c プロジェクト: blaztinn/piglit
static void
create_fbo(void)
{
	GLuint rb[32];
	int i;

	glGenFramebuffersEXT(1, &fbo);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);

	glGenRenderbuffersEXT(max_ds_buffers, rb);
	check_error(__LINE__);

	for (i = 0; i < max_ds_buffers; i++) {
		glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb[i]);
		check_error(__LINE__);

		glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
					     GL_COLOR_ATTACHMENT0 + i,
					     GL_RENDERBUFFER_EXT,
					     rb[i]);
		check_error(__LINE__);

		glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA,
					 piglit_width, piglit_height);
		check_error(__LINE__);
	}
}
コード例 #24
0
ファイル: source.cpp プロジェクト: terryfeverpitch/GLSL
void initFBO(GLuint& fbo, GLuint& depthBuffer, GLuint& img) {																											
	// Setup our FBO
	width = gw; height = gh;
    glGenFramebuffersEXT(1, &fbo);

	// bind for set up
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);

	// Now setup a texture to render to
	glGenTextures(1, &img);
	glBindTexture(GL_TEXTURE_2D, img);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,  width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);		

	// And attach it to the FBO so we can render to it
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, img, 0);
	// Create the render buffer for depth	
	glGenRenderbuffersEXT(1, &depthBuffer);
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthBuffer);
	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,GL_DEPTH_COMPONENT, width, height);

	// Attach the depth render buffer to FBO as it's depth attachment
	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuffer);
		
	// Checking 
	GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
	if(status != GL_FRAMEBUFFER_COMPLETE_EXT)
		exit(1);	
	// Unbind the FBO for now
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);	
}
コード例 #25
0
ファイル: GlFramebufferObject.cpp プロジェクト: gprice1/chomp
void GlRenderbufferObject::createObject(GLint internalFormat,
                                        GLsizei width, GLsizei height) {
  deleteObject();
  glGenRenderbuffersEXT(1, &_handle);
  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, _handle);
  glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, internalFormat, width, height);
}
コード例 #26
0
ファイル: clear-fbo.c プロジェクト: astrofimov/vgallium
static void Init(void)
{
   fprintf(stderr, "GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
   fprintf(stderr, "GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
   fprintf(stderr, "GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));


   if (!glutExtensionSupported("GL_EXT_framebuffer_object")) {
      printf("GL_EXT_framebuffer_object not found!\n");
      exit(0);
   }


   glGenFramebuffersEXT(1, &MyFB);
   glGenRenderbuffersEXT(1, &MyRB);

   {
      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB);

      glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, MyRB);

      glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT,
				   GL_RENDERBUFFER_EXT, MyRB);

      glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);

      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
   }

}
コード例 #27
0
void DepthRenderTexture::update()
{
    // Bind the FBO so that the next operations will be bound to it
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);

    // Bind the depth buffer
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBufferRT);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, m_width, m_height);
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBufferRT);

    // Generate and bind the OGL texture for diffuse

    glBindTexture(GL_TEXTURE_2D, m_depthTexture);
    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);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0);
    // Attach the texture to the FBO
    glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthTexture, 0);

    // Check if all worked fine and unbind the FBO
    GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
    if( status != GL_FRAMEBUFFER_COMPLETE_EXT)
        qDebug() << "Can't initialize an FBO render texture. FBO initialization failed.";

    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
コード例 #28
0
DECLARE_ENGINE_NAMESPACE


bool FrameBufferObject::CreateFBO(int width, int height)
{
   glGenFramebuffersEXT(1, &m_frameBuffer);
   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_frameBuffer);

   if(width > 0 && height > 0)
      {
         glGenRenderbuffersEXT(1, &m_renderBuffer);
         glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_renderBuffer);

         glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24,
                                    width, height);

         glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
                                       GL_RENDERBUFFER_EXT, m_renderBuffer);
      }

   glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttachments);

   GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);

   if(status != GL_FRAMEBUFFER_COMPLETE_EXT ||
      status != GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT)
      {
         return false;
      }

   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

   return true;
}
コード例 #29
0
ファイル: tr_ext_framebuffer.c プロジェクト: Geptun/japp
unsigned int R_EXT_CreateRenderbuffer( unsigned int width, unsigned int height, internalFormat_t internalFormat )
{
	unsigned int renderbufferId = 0;

	if ( numRenderbuffers >= MAX_RENDERBUFFERS )
	{
		Com_Error( ERR_DROP, "Exceeded maximum number of renderbuffers\n" );
		return 0;
	}

	glGenRenderbuffersEXT (1, &renderbufferId);
	if ( renderbufferId == 0 )
	{
		Com_Error( ERR_DROP, "Failed to create renderbuffer with internal ID %d.\n", numRenderbuffers );
		return 0;
	}

	glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, renderbufferId );
	glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, R_EXT_GetGLInternalFormat( internalFormat ), width, height );

	renderbuffers[numRenderbuffers] = renderbufferId;
	numRenderbuffers++;

	CheckGLErrors( __FILE__, __LINE__ );

	return renderbufferId;
}
コード例 #30
0
ファイル: RayCaster.cpp プロジェクト: maismail/cuYURI
GLuint* OpenGL::RayCaster::CreateRenderBuffer(const int WINDOW_SIZE_X,
                                             const int WINDOW_SIZE_Y)
{

    INFO("Creating the rendering buffer");

    GLuint* renderBuffer_ID = MEM_ALLOC_1D_GENERIC(GLuint, 1);

    // Generate the render buffer ID
    glGenRenderbuffersEXT(1, renderBuffer_ID);

    // Bnd the render buffer
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, *renderBuffer_ID);

    // Setup the parameters of the render buffer
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT,
                             WINDOW_SIZE_X, WINDOW_SIZE_Y);

    // Attche the render buffer to the frame buffer
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
                                 GL_RENDERBUFFER_EXT, *renderBuffer_ID);

    // Unbind the render buffer
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

    INFO("1")
    return renderBuffer_ID;
}