void GraphicsContext3D::deleteFramebuffer(Platform3DObject framebuffer)
{
    makeContextCurrent();
    glDeleteFramebuffersEXT(1, &framebuffer);
}
enum piglit_result
piglit_display(void)
{
	GLboolean pass = GL_TRUE;
	GLuint fbo, tex, pbo;
	uint32_t *addr;

	make_fbo(&fbo, &tex);

	glClear(GL_COLOR_BUFFER_BIT);

	glGenBuffersARB(1, &pbo);
	glBindBufferARB(GL_PIXEL_PACK_BUFFER, pbo);
	glBufferDataARB(GL_PIXEL_PACK_BUFFER, 4 * 4, NULL, GL_STREAM_DRAW_ARB);
	glPixelStorei(GL_PACK_ALIGNMENT, 1);

	glViewport(0, 0, 2, 2);
	piglit_ortho_projection(2, 2, GL_FALSE);

	/* bottom: green.  top: blue. */
	glColor4f(0.0, 1.0, 0.0, 0.0);
	piglit_draw_rect(0, 0, 2, 1);
	glColor4f(0.0, 0.0, 1.0, 0.0);
	piglit_draw_rect(0, 1, 2, 1);

	/* Read the whole buffer. */
	glReadPixels(0, 0, 2, 2,
		     GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)0);
	addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB);
	pass &= probe(0, 0, 0x0000ff00, addr[0]);
	pass &= probe(1, 0, 0x0000ff00, addr[1]);
	pass &= probe(0, 1, 0x000000ff, addr[2]);
	pass &= probe(1, 1, 0x000000ff, addr[3]);
	glUnmapBufferARB(GL_PIXEL_PACK_BUFFER);

	/* Read with an offset. */
	glReadPixels(1, 0, 1, 1,
		     GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)4);
	addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB);
	pass &= probe(1, 0, 0x0000ff00, addr[1]);
	glUnmapBufferARB(GL_PIXEL_PACK_BUFFER);

	/* Read with an offset. */
	glReadPixels(1, 1, 1, 1,
		     GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)4);
	addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB);
	pass &= probe(1, 1, 0x000000ff, addr[1]);
	glUnmapBufferARB(GL_PIXEL_PACK_BUFFER);

	glDeleteBuffersARB(1, &pbo);

	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

	glViewport(0, 0, piglit_width, piglit_height);
	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	glBindTexture(GL_TEXTURE_2D, tex);
	glEnable(GL_TEXTURE_2D);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	piglit_draw_rect_tex(0, 0, piglit_width, piglit_height,
			     0, 0, 1, 1);
	glDisable(GL_TEXTURE_2D);

	glDeleteFramebuffersEXT(1, &fbo);
	glDeleteTextures(1, &tex);

	glutSwapBuffers();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Example #3
0
static void create_1d_fbo(GLuint *out_tex, GLuint *out_ds)
{
	GLuint tex, ds, fb;
	GLenum status;

	/* Create the color buffer. */
	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_1D, tex);
	glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA,
		     BUF_WIDTH,
		     0,
		     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	assert(glGetError() == 0);

	/* Create the depth-stencil buffer. */
	glGenTextures(1, &ds);
	glBindTexture(GL_TEXTURE_1D, ds);
	glTexImage1D(GL_TEXTURE_1D, 0, f.iformat, BUF_WIDTH, 0, f.format, f.type, NULL);
	assert(glGetError() == 0);

	/* Create the FBO. */
	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);

	glFramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT,
				  GL_COLOR_ATTACHMENT0_EXT,
				  GL_TEXTURE_1D,
				  tex,
				  0);

	glFramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT,
				  GL_DEPTH_ATTACHMENT_EXT,
				  GL_TEXTURE_1D,
				  ds,
				  0);

	if (f.format == GL_DEPTH_STENCIL) {
		glFramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT,
					  GL_STENCIL_ATTACHMENT_EXT,
					  GL_TEXTURE_1D,
					  ds,
					  0);
	}

	assert(glGetError() == 0);

	status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
	if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
		piglit_report_result(PIGLIT_SKIP);
	}

	glViewport(0, 0, BUF_WIDTH, 1);
	glClearDepth(1);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_ALWAYS);
	glDepthRange(0, 0);

	glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	piglit_ortho_projection(BUF_WIDTH, 1, GL_FALSE);

	/* green */
	glColor4f(0.0, 1.0, 0.0, 0.0);
	piglit_draw_rect(0, 0, BUF_WIDTH, 1);

	glDeleteFramebuffersEXT(1, &fb);

	*out_tex = tex;
	*out_ds = ds;
}
Example #4
0
/**
 * Render the six faces of a cube map.
 */
static void
RenderCubeMap(void)
{
   GLuint fbo, face, depthStencilRb;
   GLint cubeSize;

   CheckError(__LINE__);

   cubeSize = ChooseCubeSize();
   printf("Rendering %d x %d cube texture\n", cubeSize, cubeSize);

   CubeTexture = CreateCubeTexture(cubeSize);

   /*
    * Make FBO.
    */
   glGenFramebuffersEXT(1, &fbo);
   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);

   /*
    * Make depth/stencil renderbuffer.
    */
   glGenRenderbuffersEXT(1, &depthStencilRb);
   glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthStencilRb);
   glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL,
                            cubeSize, cubeSize);
   glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
                                GL_DEPTH_ATTACHMENT_EXT,
                                GL_RENDERBUFFER_EXT, depthStencilRb);
   glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
                                GL_STENCIL_ATTACHMENT_EXT,
                                GL_RENDERBUFFER_EXT, depthStencilRb);

   glClearColor(0.25, 0.25, 0.25, 1.0);
   glViewport(0, 0, cubeSize, cubeSize);

   /*
    * Render into cube faces.
    */
   for (face = 0; face < 6; face++) {
      GLenum status;

      /* Render color into face of cubemap */
      glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
                                GL_TEXTURE_CUBE_MAP_POSITIVE_X + face,
				CubeTexture, 0);

      status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
      CheckError(__LINE__);
      if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
	 fprintf(stderr, "FBO not complete!  status = 0x%04x\n", status);
	 assert(status == GL_FRAMEBUFFER_COMPLETE_EXT);
      }

      CheckError(__LINE__);

      /* Render the depth image into cube face */
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

      SetupCubeFaceView(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, SpherePos);

      DrawScene();
   }

   glDeleteRenderbuffersEXT(1, &depthStencilRb);
   glDeleteFramebuffersEXT(1, &fbo);
   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

   CheckError(__LINE__);
}
Example #5
0
PIGLIT_GL_TEST_CONFIG_END

enum piglit_result
piglit_display(void)
{
	GLboolean pass = GL_TRUE;
	GLuint tex, fb;
	GLenum status;
	float fbo_white[] = {0.0, 0.0, 0.0, 1.0};
	float fbo_black[] = {0.0, 0.0, 0.0, 0.0};
	float fbo_gray[] =  {0.0, 0.0, 0.0, 0.5};
	float white[] = {1.0, 1.0, 1.0, 1.0};
	float black[] = {0.0, 0.0, 0.0, 0.0};
	float gray[] =  {0.5, 0.5, 0.5, 0.5};
	int fbo_width = 64;
	int fbo_height = 64;

	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
	glViewport(0, 0, fbo_width, fbo_height);

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_2D, tex);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA,
		     fbo_width, fbo_height, 0,
		     GL_ALPHA, GL_UNSIGNED_BYTE, NULL);

	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
				  GL_COLOR_ATTACHMENT0_EXT,
				  GL_TEXTURE_2D,
				  tex,
				  0);
	assert(glGetError() == 0);

	status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
	if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
		fprintf(stderr, "fbo incomplete (status = 0x%04x)\n", status);
		piglit_report_result(PIGLIT_SKIP);
	}

	/* Clear to no alpha. */
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	glColor4f(0.0, 0.0, 0.0, 0.0);
	piglit_draw_rect(-1.0, -1.0, 0.5, 2.0);

	glColor4f(0.0, 0.0, 0.0, 1.0);
	piglit_draw_rect(-0.5, -1.0, 0.5, 2.0);

	glColor4f(0.0, 0.0, 0.0, 0.5);
	piglit_draw_rect(0.0, -1.0, 0.5, 2.0);
	glEnable(GL_BLEND);
	glBlendFunc(GL_DST_ALPHA, GL_ZERO);
	glColor4f(0.0, 0.0, 0.0, 1.0);
	piglit_draw_rect(0.0, -1.0, 0.5, 2.0);
	glDisable(GL_BLEND);

	glColor4f(0.0, 0.0, 0.0, 0.5);
	piglit_draw_rect(0.5, -1.0, 0.5, 2.0);
	glEnable(GL_BLEND);
	glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
	glColor4f(0.0, 0.0, 0.0, 1.0);
	piglit_draw_rect(0.5, -1.0, 0.5, 2.0);
	glDisable(GL_BLEND);

	printf("Testing FBO result.\n");
	pass = piglit_probe_pixel_rgba(fbo_width * 1 / 8, 0, fbo_black) && pass;
	pass = piglit_probe_pixel_rgba(fbo_width * 3 / 8, 0, fbo_white) && pass;
	pass = piglit_probe_pixel_rgba(fbo_width * 5 / 8, 0, fbo_gray) && pass;
	pass = piglit_probe_pixel_rgba(fbo_width * 7 / 8, 0, fbo_gray) && pass;

	/* Draw the two textures to halves of the window. */
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
	glViewport(0, 0, piglit_width, piglit_height);

	glEnable(GL_TEXTURE_2D);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
	glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_ALPHA);
	glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
	glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
	glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);

	glBindTexture(GL_TEXTURE_2D, tex);
	piglit_draw_rect_tex(-1, -1, 2, 2,
			     0, 0, 1, 1);

	glDisable(GL_TEXTURE_2D);
	glDeleteTextures(1, &tex);
	glDeleteFramebuffersEXT(1, &fb);

	printf("Testing window result.\n");
	pass = piglit_probe_pixel_rgba(piglit_width * 1 / 8, 0, black) && pass;
	pass = piglit_probe_pixel_rgba(piglit_width * 3 / 8, 0, white) && pass;
	pass = piglit_probe_pixel_rgba(piglit_width * 5 / 8, 0, gray) && pass;
	pass = piglit_probe_pixel_rgba(piglit_width * 7 / 8, 0, gray) && pass;

	piglit_present_results();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Example #6
0
bool _al_ogl_create_persistent_fbo(ALLEGRO_BITMAP *bitmap)
{
   ALLEGRO_BITMAP_EXTRA_OPENGL *ogl_bitmap;
   ALLEGRO_FBO_INFO *info;
   GLint old_fbo, e;

   if (bitmap->parent)
      bitmap = bitmap->parent;
   ogl_bitmap = bitmap->extra;

   /* Don't continue if the bitmap does not belong to the current display. */
   if (_al_get_bitmap_display(bitmap)->ogl_extras->is_shared == false &&
         _al_get_bitmap_display(bitmap) != al_get_current_display()) {
      return false;
   }

   if (ogl_bitmap->is_backbuffer) {
      return false;
   }

   ASSERT(!ogl_bitmap->fbo_info);

   info = al_malloc(sizeof(ALLEGRO_FBO_INFO));
   if (ANDROID_PROGRAMMABLE_PIPELINE(al_get_current_display())) {
      glGenFramebuffers(1, &info->fbo);
   }
   else {
      glGenFramebuffersEXT(1, &info->fbo);
   }
   if (info->fbo == 0) {
      al_free(info);
      return false;
   }

   old_fbo = _al_ogl_bind_framebuffer(info->fbo);

   if (ANDROID_PROGRAMMABLE_PIPELINE(al_get_current_display())) {
      glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
         GL_TEXTURE_2D, ogl_bitmap->texture, 0);
   }
   else {
      glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
         GL_TEXTURE_2D, ogl_bitmap->texture, 0);
   }

   e = glGetError();
   if (e) {
      ALLEGRO_DEBUG("glFrameBufferTexture2DEXT failed! fbo=%d texture=%d (%s)",
         info->fbo, ogl_bitmap->texture, _al_gl_error_string(e));
   }

   /* You'll see this a couple times in this file: some ES 1.1 functions aren't
    * implemented on Android. This is an ugly workaround.
    */
   if (UNLESS_ANDROID_OR_RPI(
         glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT))
   {
      ALLEGRO_ERROR("FBO incomplete.\n");
      _al_ogl_bind_framebuffer(old_fbo);
      glDeleteFramebuffersEXT(1, &info->fbo);
      al_free(info);
      return false;
   }

   _al_ogl_bind_framebuffer(old_fbo);

   info->fbo_state = FBO_INFO_PERSISTENT;
   info->owner = bitmap;
   info->last_use_time = al_get_time();
   ogl_bitmap->fbo_info = info;
   ALLEGRO_DEBUG("Persistent FBO: %u\n", info->fbo);
   return true;
}
Example #7
0
void MGLContext::deleteFrameBuffer(unsigned int * frameBufferId){
	glDeleteFramebuffersEXT(1, frameBufferId);
}
Example #8
0
DiGLFrameBuffer::~DiGLFrameBuffer()
{
    glDeleteFramebuffersEXT(1, &mFBOId);
}
Example #9
0
static int
create_cube_fbo(void)
{
	GLuint tex, fb;
	GLenum status;
	int face, dim;

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_CUBE_MAP, tex);

	for (face = 0; face < 6; face++) {
		int level = 0;

		for (dim = BUF_WIDTH; dim > 0; dim /= 2) {
			glTexImage2D(cube_face_targets[face], level, GL_RGBA,
				     dim, dim,
				     0,
				     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
			level++;
		}
	}
	assert(glGetError() == 0);

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

	for (face = 0; face < 6; face++) {
		int level = 0;

		for (dim = BUF_WIDTH; dim > 0; dim /= 2) {
			glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
						  GL_COLOR_ATTACHMENT0_EXT,
						  cube_face_targets[face],
						  tex,
						  level);

			assert(glGetError() == 0);

			status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
			if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
				fprintf(stderr, "FBO incomplete\n");
				goto done;
			}

			glViewport(0, 0, dim, dim);
			piglit_ortho_projection(dim, dim, GL_FALSE);

			glColor4fv(get_face_color(face, level));
			/* Draw a little outside the bounds to make
			 * sure clipping's working.
			 */
			piglit_draw_rect(-2, -2, dim + 2, dim + 2);

			level++;
		}
	}


done:
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
	glDeleteFramebuffersEXT(1, &fb);

	return tex;
}
Example #10
0
DiGLFBOManager::~DiGLFBOManager()
{
    glDeleteFramebuffersEXT(1, &mTempFBO);
}
Example #11
0
void DiGLFBOManager::DetectFBOFormats()
{
    // Try all formats, and report which ones work as target
    GLuint fb = 0, tid = 0;
    GLint old_drawbuffer = 0, old_readbuffer = 0;
    GLenum target = GL_TEXTURE_2D;

    glGetIntegerv(GL_DRAW_BUFFER, &old_drawbuffer);
    glGetIntegerv(GL_READ_BUFFER, &old_readbuffer);

    for (uint32 x = 0; x < PIXEL_FORMAT_MAX; ++x)
    {
        mProps[x].valid = false;

        GLenum fmt = DiGLTypeMappings::GLInternalFormatMapping[(DiPixelFormat)x];
        if (fmt == GL_NONE && x != 0)
            continue;

        if (DiPixelBox::IsCompressedFormat((DiPixelFormat)x))
            continue;

        // Buggy ATI cards *crash* on non-RGB(A) formats
        int depths[4];
        DiPixelBox::GetBitDepths((DiPixelFormat)x, depths);
        if (fmt != GL_NONE && mATIMode && (!depths[0] || !depths[1] || !depths[2]))
            continue;

        // Create and attach framebuffer
        glGenFramebuffersEXT(1, &fb);
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
        if (fmt != GL_NONE)
        {
            // Create and attach texture
            glGenTextures(1, &tid);
            glBindTexture(target, tid);

            // Set some default parameters so it won't fail on NVidia cards
            if (GLEW_VERSION_1_2)
                glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, 0);
            glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

            glTexImage2D(target, 0, fmt, PROBE_SIZE, PROBE_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
            glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
                                      target, tid, 0);
        }
        else
        {
            // Draw to nowhere -- stencil/depth only
            glDrawBuffer(GL_NONE);
            glReadBuffer(GL_NONE);
        }

        // Check status
        GLuint status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);

        // Ignore status in case of fmt==GL_NONE, because no implementation will accept
        // a buffer without *any* attachment. Buffers with only stencil and depth attachment
        // might still be supported, so we must continue probing.
        if (fmt == GL_NONE || status == GL_FRAMEBUFFER_COMPLETE_EXT)
        {
            mProps[x].valid = true;

            // For each depth/stencil formats
            for (size_t depth = 0; depth < DEPTHFORMAT_COUNT; ++depth)
            {
                if (depthFormats[depth] != GL_DEPTH24_STENCIL8_EXT)
                {
                    // General depth/stencil combination

                    for (size_t stencil = 0; stencil < STENCILFORMAT_COUNT; ++stencil)
                    {
                        if (TryFormat(depthFormats[depth], stencilFormats[stencil]))
                        {
                            /// Add mode to allowed modes
                            FormatProperties::Mode mode;
                            mode.depth = depth;
                            mode.stencil = stencil;
                            mProps[x].modes.push_back(mode);
                        }
                    }
                }
                else
                {

                    if (TryPackedFormat(depthFormats[depth]))
                    {
                        /// Add mode to allowed modes
                        FormatProperties::Mode mode;
                        mode.depth = depth;
                        mode.stencil = 0;
                        mProps[x].modes.push_back(mode);
                    }
                }
            }
        }
        // Delete texture and framebuffer
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
        glDeleteFramebuffersEXT(1, &fb);

        // Workaround for NVIDIA / Linux 169.21 driver problem
        // see http://www.ogre3d.org/phpBB2/viewtopic.php?t=38037&start=25
        glFinish();

        if (fmt != GL_NONE)
            glDeleteTextures(1, &tid);
    }

    // It seems a bug in nVidia driver: glBindFramebufferEXT should restore
    // draw and read buffers, but in some unclear circumstances it won't.
    glDrawBuffer(old_drawbuffer);
    glReadBuffer(old_readbuffer);

    for (size_t x = 0; x < PIXEL_FORMAT_MAX; ++x)
    {
        if (mProps[x].valid)
        {
            DI_INFO("Valid format for FBO targets: %s", DiPixelBox::GetPixelTypeName((DiPixelFormat)x).c_str());
        }
    }
}
GLRenderTarget::~GLRenderTarget() {
	glDeleteFramebuffersEXT(1, &fboId);
}
Example #13
0
Raycaster::DataItem::~DataItem(void)
	{
	/* Destroy the depth texture and framebuffer: */
	glDeleteFramebuffersEXT(1,&depthFramebufferID);
	glDeleteTextures(1,&depthTextureID);
	}
Example #14
0
void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels)
{
	const int w = GPU_texture_width(ofs->color);
	const int h = GPU_texture_height(ofs->color);

	if (GPU_texture_target(ofs->color) == GL_TEXTURE_2D_MULTISAMPLE) {
		/* For a multi-sample texture,
		 * we need to create an intermediate buffer to blit to,
		 * before its copied using 'glReadPixels' */

		/* not needed since 'ofs' needs to be bound to the framebuffer already */
// #define USE_FBO_CTX_SWITCH

		GLuint fbo_blit = 0;
		GLuint tex_blit = 0;
		GLenum status;

		/* create texture for new 'fbo_blit' */
		glGenTextures(1, &tex_blit);
		if (!tex_blit) {
			goto finally;
		}

		glBindTexture(GL_TEXTURE_2D, tex_blit);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, type, 0);

#ifdef USE_FBO_CTX_SWITCH
		/* read from multi-sample buffer */
		glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, ofs->color->fb->object);
		glFramebufferTexture2DEXT(
		        GL_READ_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + ofs->color->fb_attachment,
		        GL_TEXTURE_2D_MULTISAMPLE, ofs->color->bindcode, 0);
		status = glCheckFramebufferStatusEXT(GL_READ_FRAMEBUFFER_EXT);
		if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
			goto finally;
		}
#endif

		/* write into new single-sample buffer */
		glGenFramebuffersEXT(1, &fbo_blit);
		glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fbo_blit);
		glFramebufferTexture2DEXT(
		        GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
		        GL_TEXTURE_2D, tex_blit, 0);
		status = glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT);
		if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
			goto finally;
		}

		/* perform the copy */
		glBlitFramebufferEXT(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);

		/* read the results */
		glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, fbo_blit);
		glReadPixels(0, 0, w, h, GL_RGBA, type, pixels);

#ifdef USE_FBO_CTX_SWITCH
		/* restore the original frame-bufer */
		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ofs->color->fb->object);
#undef USE_FBO_CTX_SWITCH
#endif


finally:
		/* cleanup */
		if (tex_blit) {
			glDeleteTextures(1, &tex_blit);
		}
		if (fbo_blit) {
			glDeleteFramebuffersEXT(1, &fbo_blit);
		}

		GPU_ASSERT_NO_GL_ERRORS("Read Multi-Sample Pixels");
	}
	else {
		glReadPixels(0, 0, w, h, GL_RGBA, type, pixels);
	}
}
Example #15
0
enum piglit_result piglit_display(void)
{
	enum piglit_result res;
	GLuint fb, rb;
	GLenum status;

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glClearColor(0, 0, 0, 0);
	glClear(GL_COLOR_BUFFER_BIT);

	/* Create the FBO. */
	glGenRenderbuffersEXT(1, &rb);
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb);
	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, f.iformat, BUF_SIZE, BUF_SIZE);
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);

	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT,
				     GL_RENDERBUFFER_EXT, rb);
	glViewport(0, 0, BUF_SIZE, BUF_SIZE);
	glDrawBuffer(GL_NONE);
	glReadBuffer(GL_NONE);
	status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
	if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
		printf("FBO incomplete status 0x%X\n", status);
		piglit_report_result(PIGLIT_SKIP);
	}

	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glPixelStorei(GL_PACK_ALIGNMENT, 1);

	switch (test) {
	case CLEAR:
		puts("Testing glClear(depth).");
		res = test_clear();
		break;
	case READPIXELS:
		puts("Testing glReadPixels(depth).");
		res = test_readpixels();
		break;
	case DRAWPIXELS:
		puts("Testing glDrawPixels(depth).");
		res = test_drawpixels();
		break;
	case COPYPIXELS:
	case BLIT:
		puts(test == BLIT ?
		     "Testing glBlitFramebuffer(depth)." :
		     "Testing glCopyPixels(depth).");
		res = test_copy();
		break;
	default:
		assert(0);
	}

	/* Cleanup. */
	glDeleteFramebuffersEXT(1, &fb);
	glDeleteRenderbuffersEXT(1, &rb);

	glutSwapBuffers();

	assert(glGetError() == 0);
	return res;
}
Example #16
0
Framebuffer::~Framebuffer () {
    if (framebufferID != 0) {
        glDeleteFramebuffersEXT(1, &framebufferID);
        framebufferID = 0;
    }
}
static void
generate_and_display_drawbuffers(int count)
{
	GLuint tex[16], fb, fs, vs, prog;
	GLenum attachments[16], status;
	int i;
	char fs_output_line[256];
	char fs_full_source[1024];

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

	for (i = 0; i < count; i++) {
		tex[i] = attach_texture(i);
		attachments[i] = GL_COLOR_ATTACHMENT0 + i;
	}

	status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
	if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
		fprintf(stderr, "fbo incomplete (status = 0x%04x)\n", status);
		piglit_report_result(PIGLIT_SKIP);
	}

	glDrawBuffersARB(count, attachments);

	/* Clear all to 0.25 so we see if the shader rendering happens. */
	glClearColor(clear_value, clear_value, clear_value, clear_value);
	glClear(GL_COLOR_BUFFER_BIT);

	/* Build the shader that spams green to all outputs. */
	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);

	strcpy(fs_full_source, fs_source_start);
		
	for (i = 0; i < count; i++) {
		sprintf(fs_output_line, fs_source_output, i, output_values[i * 4], 
				output_values[(i * 4) + 1], output_values[(i * 4) + 2], 
				output_values[(i * 4) + 3]);
		
		strcat(fs_full_source, fs_output_line);
	}
	
	strcat(fs_full_source, fs_source_end);

	assert(strlen(fs_full_source) + 1 < sizeof(fs_full_source) / sizeof(fs_full_source[0]));
	
	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_full_source);

	prog = piglit_link_simple_program(vs, fs);
	glUseProgram(prog);

	glEnable(GL_BLEND);
	glBlendFunc(GL_ONE, GL_ONE);
	glBlendEquation(GL_FUNC_ADD);

	/* Now render to all the color buffers. */
	piglit_draw_rect(-1, -1, 2, 2);

	glDisable(GL_BLEND);
	
	/* OK, now draw each of these textures to the winsys framebuffer. */
	glUseProgram(0);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glEnable(GL_TEXTURE_2D);
	for (i = 0; i < count; i++) {
		glBindTexture(GL_TEXTURE_2D, tex[i]);
		piglit_draw_rect_tex(16 * i, 16 * (count - 1),
					 16, 16,
					 0, 0,
					 1, 1);
	}
	glDisable(GL_TEXTURE_2D);

	for (i = 0; i < count; i++) {
		glDeleteTextures(1, &tex[i]);
	}
	glDeleteFramebuffersEXT(1, &fb);
}
static void
generate_and_display_drawbuffers(int count)
{
	GLuint tex[16], fb, fs, vs, prog;
	GLenum attachments[16], status, error;
	char *fs_count_source;
	int i;

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

	for (i = 0; i < count; i++) {
		tex[i] = attach_texture(i);
		attachments[i] = GL_COLOR_ATTACHMENT0 + i;
	}

	status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
	if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
		fprintf(stderr, "fbo incomplete (status = 0x%04x)\n", status);
		piglit_report_result(PIGLIT_SKIP);
	}

	glDrawBuffersARB(count, attachments);

	/* Clear all to red so we see if the shader rendering happens. */
	glClearColor(1.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	/* Build the shader that spams green to all outputs. */
	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);

	fs_count_source = malloc(strlen(fs_source) + 5);
	sprintf(fs_count_source, fs_source, count);
	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_count_source);
	free(fs_count_source);

	prog = piglit_link_simple_program(vs, fs);
	glUseProgram(prog);

	error = glGetError();
	if (error) {
		fprintf(stderr, "glUseProgram error: 0x%x\n", error);
		piglit_report_result(PIGLIT_FAIL);
	}

	/* Now render to all the color buffers. */
	piglit_draw_rect(-1, -1, 2, 2);

	/* OK, now draw each of these textures to the winsys framebuffer. */
	glUseProgram(0);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glEnable(GL_TEXTURE_2D);
	for (i = 0; i < count; i++) {
		glBindTexture(GL_TEXTURE_2D, tex[i]);
		piglit_draw_rect_tex(16 * i, 16 * (count - 1),
				     16, 16,
				     0, 0,
				     1, 1);
	}
	glDisable(GL_TEXTURE_2D);

	for (i = 0; i < count; i++) {
		glDeleteTextures(1, &tex[i]);
	}
	glDeleteFramebuffersEXT(1, &fb);
}
Example #19
0
FrameBuffer::~FrameBuffer()
{
    glDeleteFramebuffersEXT(1, &frameBufferObject);
    glDeleteRenderbuffersEXT( 1, &depthbuffer );
}
Example #20
0
framebuffer_obj_t::~framebuffer_obj_t()
{
    if( id_)
        glDeleteFramebuffersEXT( 1, &id_);
}
Example #21
0
 FramebufferObject::~FramebufferObject()
 {
   glDeleteFramebuffersEXT(1, &id_);
 }
Example #22
0
bool spoutGLDXinterop::CreateInterop(HWND hWnd, char* sendername, unsigned int width, unsigned int height, DWORD dwFormat, bool bReceive)
{
	bool bRet = true;
	DWORD format;
	D3DFORMAT DX9format = D3DFMT_A8R8G8B8; // fixed format for DX9 (21)

	// Needs an openGL context to work
	if(!wglGetCurrentContext()) {
		// MessageBoxA(NULL, "CreateInterop - no GL context", "Warning", MB_OK);
		return false;
	}

	if(bUseDX9) {
		// printf("CreateInterop - DX9 mode - format D3DFMT_A8R8G8B8 (%d) \n", DX9format);
		// DirectX 9
		format = (DWORD)DX9format;
	}
	else {
		// DirectX 11
		// Is this a DX11 texture or a DX9 sender texture?
		if(dwFormat > 0) {
			// printf("CreateInterop - DX11 mode - format %d \n", dwFormat);
			format = (DXGI_FORMAT)dwFormat;
		}
		else {
			// printf("CreateInterop - DX11 mode - default compatible format %d \n", DX11format);
			format = (DWORD)DX11format; // DXGI_FORMAT_B8G8R8A8_UNORM default compatible with DX9
		}
	}

	// Formats
	// DXGI_FORMAT_R8G8B8A8_UNORM; // default DX11 format - not compatible with DX9 (28)
	// DXGI_FORMAT_B8G8R8A8_UNORM; // compatoble DX11 format - works with DX9 (87)

	// Quit now if the receiver can't access the shared memory info of the sender
	// Otherwise m_dxShareHandle is set by getSharedTextureInfo and is the
	// shared texture handle of the Sender texture
	if (bReceive && !getSharedTextureInfo(sendername)) {
		// printf("CreateInterop error 1\n");
		return false;
	}

	// Check the sender format for a DX9 receiver
	// It can only be from a DX9 sender (format 0)
	// or from a compatible DX11 sender (format 87)
	if(bReceive && bUseDX9) {
		if(!(m_TextureInfo.format == 0 || m_TextureInfo.format == 87)) {
			// printf("CreateInterop - Incompatible format %d \n", m_TextureInfo.format);
			return false;
		}
	}

	// Make sure DirectX has been initialized
	// Creates a global pointer to the DirectX device (DX11 g_pd3dDevice or DX9 m_pDevice)
	if(!OpenDirectX(hWnd, bUseDX9)) {
		return false;
	}

	// Allow for sender updates
	// When a sender size changes, the new texture has to be re-registered
	if(m_hInteropDevice != NULL &&  m_hInteropObject != NULL) {
		// printf("CreateInterop - wglDXUnregisterObjectNV\n");
		wglDXUnregisterObjectNV(m_hInteropDevice, m_hInteropObject);
		m_hInteropObject = NULL;
	}

	// Create an fbo for copying textures
	if(m_fbo) {
		// Delete the fbo before the texture so that any texture attachment is released
		// printf("CreateInterop - deleting fbo\n");
		glDeleteFramebuffersEXT(1, &m_fbo);
		m_fbo = 0;
	}
	glGenFramebuffersEXT(1, &m_fbo); 

	// Create a local opengl texture that will be linked to a shared DirectX texture
	if(m_glTexture) {
		// printf("CreateInterop - deleting texture\n");
		glDeleteTextures(1, &m_glTexture);
		m_glTexture = 0;
	}
	glGenTextures(1, &m_glTexture);


	// Create textures and GLDX interop objects
	if(bUseDX9)	bRet = CreateDX9interop(width, height, format, bReceive);
	else bRet = CreateDX11interop(width, height, format, bReceive);

	if(!bRet) {
		// printf("CreateInterop error 2\n");
		return false;
	}

	// Now the global shared texture handle - m_dxShareHandle - has been set so a sender can be created
	// this creates the sender shared memory map and registers the sender
	if (!bReceive) {

		// We are done with the format
		// So for DirectX 9, set to zero to identify the sender as DirectX 9
		if(bUseDX9) format = 0; 
		if(!senders.CreateSender(sendername, width, height, m_dxShareHandle, format))
			return false;

	}

	// Set up local values for this instance
	// Needed for texture read and write size checks
	m_TextureInfo.width			= (unsigned __int32)width;
	m_TextureInfo.height		= (unsigned __int32)height;
	m_TextureInfo.shareHandle	= (unsigned __int32)m_dxShareHandle;
	m_TextureInfo.format		= format;

	// Initialize general texture transfer sync mutex - either sender or receiver can do this
	spoutdx.CreateAccessMutex(sendername, m_hAccessMutex);

	// Now it has initialized OK
	m_bInitialized = true;

	//
	// Now we have globals for this instance
	//
	// m_TextureInfo.width			- width of the texture
	// m_TextureInfo.height			- height of the texture
	// m_TextureInfo.shareHandle	- handle of the shared texture
	// m_TextureInfo.format			- format of the texture
	// m_glTexture					- a linked opengl texture
	// m_dxTexture					- a linked, shared DirectX texture created here
	// m_hInteropDevice				- handle to interop device created by wglDXOpenDeviceNV by init
	// m_hInteropObject				- handle to the connected texture created by wglDXRegisterObjectNV
	// m_hAccessMutex				- mutex for texture access lock
	// m_bInitialized				- whether it initialized OK

	// true means the init was OK, not the connection
	return true; 

}
Example #23
0
 ~Framebuffer(){
     glDeleteFramebuffersEXT(1, &m_id);
     glDeleteRenderbuffersEXT(1, &m_depth_rbo);
     glDeleteTextures(1, &m_texture);
 }
Example #24
0
enum piglit_result
piglit_display(void)
{
	GLboolean pass = GL_TRUE;
	int x, y;
	GLuint tex, fb;
	float blue[] =   {1, 0, 0, 0};
	float green[] = {0, 1, 0, 0};
	bool draw_green;
	float *draw_colors[] = {blue, green};
	float w_screen = 2.0f * TEX_WIDTH / piglit_width;
	float h_screen = 2.0f * TEX_HEIGHT / piglit_height;

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_2D, tex);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
		     TEX_WIDTH, TEX_HEIGHT, 0,
		     GL_RGBA, GL_UNSIGNED_BYTE, NULL);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
				  GL_COLOR_ATTACHMENT0_EXT,
				  GL_TEXTURE_2D,
				  tex,
				  0);
	assert(glGetError() == 0);

	assert(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) ==
	       GL_FRAMEBUFFER_COMPLETE_EXT);

	draw_green = true;
	for (y = 0; y <= piglit_height - TEX_HEIGHT; y += TEX_HEIGHT) {
		float y_screen = -1.0 + 2.0 * ((float)y / piglit_height);

		for (x = 0; x <= piglit_width - TEX_WIDTH; x += TEX_WIDTH) {
			float x_screen = -1.0 + 2.0 * ((float)x / piglit_width);

			glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
			glDisable(GL_TEXTURE_2D);
			glColor4fv(draw_colors[draw_green]);
			piglit_draw_rect(-1, -1, 2, 2);

			glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
			glEnable(GL_TEXTURE_2D);
			piglit_draw_rect_tex(x_screen, y_screen,
					     w_screen, h_screen,
					     0, 0,
					     1, 1);

			draw_green = !draw_green;
		}
		/* Make it a checkerboard. */
		draw_green = !draw_green;
	}

	glDeleteFramebuffersEXT(1, &fb);
	glDeleteTextures(1, &tex);

	draw_green = true;
	for (y = 0; y <= piglit_height - TEX_HEIGHT; y += TEX_HEIGHT) {
		for (x = 0; x <= piglit_width - TEX_WIDTH; x += TEX_WIDTH) {
			float *expected = draw_colors[draw_green];

			pass = pass && piglit_probe_rect_rgb(x, y,
							     TEX_WIDTH,
							     TEX_HEIGHT,
							     expected);

			draw_green = !draw_green;
		}
		draw_green = !draw_green;
	}

	glutSwapBuffers();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Example #25
0
File: arbfp.c Project: Zoxc/piglit
enum piglit_result
piglit_display(void)
{
	GLboolean pass = GL_TRUE;
	GLuint tex0, tex1, fb;
	GLenum status;
	const GLenum attachments[] = {
		GL_COLOR_ATTACHMENT0_EXT,
		GL_COLOR_ATTACHMENT1_EXT,
	};

	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

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

	tex0 = attach_texture(0);
	tex1 = attach_texture(1);

	glDrawBuffersATI(2, attachments);

	status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
	if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
		fprintf(stderr, "fbo incomplete (status = 0x%04x)\n", status);
		piglit_report_result(PIGLIT_SKIP);
	}

	/* Clear render targets (textures) to red */
	glClearColor(1.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	glMultiTexCoord4fv(GL_TEXTURE0, result0);
	glMultiTexCoord4fv(GL_TEXTURE1, result1);

        glEnable(GL_FRAGMENT_PROGRAM_ARB);
	piglit_draw_rect(0, 0, piglit_width, piglit_height);
        glDisable(GL_FRAGMENT_PROGRAM_ARB);

	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);

	/* Draw the two green textures to halves of the window. */
	glEnable(GL_TEXTURE_2D);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glBindTexture(GL_TEXTURE_2D, tex0);
	piglit_draw_rect_tex(0, 0,
			     piglit_width / 2, piglit_height,
			     0, 0, 1, 1);
	glBindTexture(GL_TEXTURE_2D, tex1);
	piglit_draw_rect_tex(piglit_width / 2, 0,
			     piglit_width / 2, piglit_height,
			     0, 0, 1, 1);
	glDisable(GL_TEXTURE_2D);
	glDeleteTextures(1, &tex0);
	glDeleteTextures(1, &tex1);
	glDeleteFramebuffersEXT(1, &fb);

	pass = pass && piglit_probe_rect_rgba(0, 0, piglit_width / 2, piglit_height,
					     result0);
	pass = pass && piglit_probe_rect_rgba(piglit_width / 2, 0, piglit_width / 2, piglit_height,
					     result1);

	piglit_present_results();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
void ShivaVGWindowSurfacePrivate::ensureContext(QWidget *widget)
{
#if defined(Q_WS_X11)
    Window win = widget->winId();
    if (win != drawable) {
        if (context)
            glXDestroyContext(X11->display, context);
        drawable = win;
    }
    if (context == 0) {
        const QX11Info *xinfo = qt_x11Info(widget);
        int spec[64];
        int i = 0;
        spec[i++] = GLX_DOUBLEBUFFER;
        spec[i++] = GLX_DEPTH_SIZE;
        spec[i++] = 1;
        spec[i++] = GLX_STENCIL_SIZE;
        spec[i++] = 1;
        spec[i++] = GLX_RGBA;
        spec[i++] = GLX_RED_SIZE;
        spec[i++] = 1;
        spec[i++] = GLX_GREEN_SIZE;
        spec[i++] = 1;
        spec[i++] = GLX_BLUE_SIZE;
        spec[i++] = 1;
        spec[i++] = GLX_SAMPLE_BUFFERS_ARB;
        spec[i++] = 1;
        spec[i++] = GLX_SAMPLES_ARB;
        spec[i++] = 4;
        spec[i] = XNone;
        XVisualInfo *visual = glXChooseVisual
            (xinfo->display(), xinfo->screen(), spec);
        context = glXCreateContext(X11->display, visual, 0, True);
        if (!context)
            qWarning("glXCreateContext: could not create GL context for VG rendering");
    }
#else
    Q_UNUSED(widget);
#endif
#if defined(QVG_USE_FBO)
    if (needsResize && fbo) {
#if defined(Q_WS_X11)
        glXMakeCurrent(X11->display, drawable, context);
#endif
        glDeleteTextures(1, &texture);
        glDeleteFramebuffersEXT(1, &fbo);
#if defined(Q_WS_X11)
        glXMakeCurrent(X11->display, 0, 0);
#endif
        fbo = 0;
        texture = 0;
    }
    if (!fbo) {
#if defined(Q_WS_X11)
        glXMakeCurrent(X11->display, drawable, context);
#endif
        glGenFramebuffersEXT(1, &fbo);
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);

        glGenTextures(1, &texture);
        glBindTexture(GL_TEXTURE_2D, texture);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, size.width(), size.height(), 0,
                     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glFramebufferTexture2DEXT
            (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D,
             texture, 0);

        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
#if defined(Q_WS_X11)
        glXMakeCurrent(X11->display, 0, 0);
#endif
    }
#endif
    needsResize = false;
}
Example #27
0
static int create_fbo(void)
{
	GLuint tex, fb;
	GLint maxsize;
	GLenum status;
	int x0, x1, y0, y1;
	GLenum glerror;

	maxsize = find_max_texture_size();
	printf("max 2D texture size: %d x %d\n", maxsize, maxsize);

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_2D, tex);

	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, maxsize, maxsize,
		     0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

	glerror = glGetError();

	switch (glerror) {
	case GL_NO_ERROR:
		break;
	case GL_OUT_OF_MEMORY:
		puts("Got GL_OUT_OF_MEMORY.");
		piglit_report_result(PIGLIT_PASS);
	default:
		printf("Unexpected error: %s\n",
		       piglit_get_gl_enum_name(glerror));
		piglit_report_result(PIGLIT_FAIL);
	}

	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
				  GL_COLOR_ATTACHMENT0_EXT,
				  GL_TEXTURE_2D,
				  tex, 0);
	if (!piglit_check_gl_error(GL_NO_ERROR))
		piglit_report_result(PIGLIT_FAIL);

	status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
	if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
		printf("FBO incomplete\n");
		piglit_report_result(PIGLIT_SKIP);
	}

	glViewport(0, 0, maxsize, maxsize);
	piglit_ortho_projection(maxsize, maxsize, GL_FALSE);

	glClearColor(1.0, 1.0, 1.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);

	x0 = maxsize / 4;
	x1 = maxsize * 3 / 4;
	y0 = maxsize / 4;
	y1 = maxsize * 3 / 4;
	draw_color_sub_rect(x0, y0, maxsize);
	draw_color_sub_rect(x1, y0, maxsize);
	draw_color_sub_rect(x1, y1, maxsize);
	draw_color_sub_rect(x0, y1, maxsize);

	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
	glDeleteFramebuffersEXT(1, &fb);

	return tex;
}
Example #28
0
//----------------------------------------------------------------------------
void OpenGL::DestroyFrameBuffer (GLuint& framebuffer)
{
	glDeleteFramebuffersEXT(1, &framebuffer);
	framebuffer = 0;
}
Example #29
0
void ShutDown(GLvoid)
{
	glDeleteFramebuffersEXT(1, &fbo);
	glDeleteRenderbuffersEXT(1, &depthBuffer);
	glDeleteTextures(1,&img);
}
Example #30
0
void
piglit_init(int argc, char **argv)
{
	GLint max_samples, sample_buffers, samples, rb_samples;
	GLuint rb, fb;
	GLenum status;
	bool pass = true;
	int i;

	piglit_require_extension("GL_EXT_framebuffer_multisample");

	glGetIntegerv(GL_MAX_SAMPLES, &max_samples);

	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER, fb);

	glDrawBuffer(GL_COLOR_ATTACHMENT0);
	glReadBuffer(GL_COLOR_ATTACHMENT0);

	for (i = 0; i < max_samples; i++) {
		glGenRenderbuffersEXT(1, &rb);
		glBindRenderbufferEXT(GL_RENDERBUFFER, rb);
		glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER,
						    max_samples,
						    GL_RGBA, 1, 1);

		glFramebufferRenderbufferEXT(GL_FRAMEBUFFER,
					     GL_COLOR_ATTACHMENT0,
					     GL_RENDERBUFFER, rb);

		status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
		if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
			fprintf(stderr, "FBO incomplete\n");
			piglit_report_result(PIGLIT_FAIL);
		}

		glGetRenderbufferParameterivEXT(GL_RENDERBUFFER,
						GL_RENDERBUFFER_SAMPLES,
						&rb_samples);

		glGetIntegerv(GL_SAMPLES, &samples);
		if (rb_samples != samples) {
			fprintf(stderr,
				"FBO reported GL_SAMPLES %d for "
				"rb samples %d\n",
				samples, rb_samples);
			pass = false;
		}

		glGetIntegerv(GL_SAMPLE_BUFFERS, &sample_buffers);
		if ((rb_samples != 0) != (sample_buffers == 1)) {
			fprintf(stderr,
				"FBO reported GL_SAMPLE_BUFFERS %d for "
				"rb samples %d\n",
				sample_buffers, samples);
			pass = false;
		}

		glDeleteRenderbuffersEXT(1, &rb);
	}

	glDeleteFramebuffersEXT(1, &fb);

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}