2007-11-07 10:04:59 -08:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
|
|
|
|
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
2008-09-18 15:17:05 -06:00
|
|
|
#include "main/imports.h"
|
2009-01-22 15:43:40 -07:00
|
|
|
#include "main/macros.h"
|
2008-09-18 15:17:05 -06:00
|
|
|
#include "main/mtypes.h"
|
|
|
|
#include "main/fbobject.h"
|
|
|
|
#include "main/framebuffer.h"
|
|
|
|
#include "main/renderbuffer.h"
|
|
|
|
#include "main/context.h"
|
|
|
|
#include "main/texrender.h"
|
2009-08-10 13:43:00 -06:00
|
|
|
#include "drivers/common/meta.h"
|
2007-11-07 10:04:59 -08:00
|
|
|
|
|
|
|
#include "intel_context.h"
|
2009-12-09 11:36:45 -08:00
|
|
|
#include "intel_batchbuffer.h"
|
2007-11-07 10:04:59 -08:00
|
|
|
#include "intel_buffers.h"
|
|
|
|
#include "intel_fbo.h"
|
|
|
|
#include "intel_mipmap_tree.h"
|
|
|
|
#include "intel_regions.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define FILE_DEBUG_FLAG DEBUG_FBO
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new framebuffer object.
|
|
|
|
*/
|
|
|
|
static struct gl_framebuffer *
|
|
|
|
intel_new_framebuffer(GLcontext * ctx, GLuint name)
|
|
|
|
{
|
|
|
|
/* Only drawable state in intel_framebuffer at this time, just use Mesa's
|
|
|
|
* class
|
|
|
|
*/
|
|
|
|
return _mesa_new_framebuffer(ctx, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-29 14:57:31 -07:00
|
|
|
/** Called by gl_renderbuffer::Delete() */
|
2007-11-07 10:04:59 -08:00
|
|
|
static void
|
|
|
|
intel_delete_renderbuffer(struct gl_renderbuffer *rb)
|
|
|
|
{
|
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
|
|
|
struct intel_context *intel = intel_context(ctx);
|
|
|
|
struct intel_renderbuffer *irb = intel_renderbuffer(rb);
|
|
|
|
|
|
|
|
ASSERT(irb);
|
|
|
|
|
2008-08-24 17:59:10 +10:00
|
|
|
if (irb->span_cache != NULL)
|
|
|
|
_mesa_free(irb->span_cache);
|
|
|
|
|
2007-11-07 10:04:59 -08:00
|
|
|
if (intel && irb->region) {
|
|
|
|
intel_region_release(&irb->region);
|
|
|
|
}
|
|
|
|
|
|
|
|
_mesa_free(irb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a pointer to a specific pixel in a renderbuffer.
|
|
|
|
*/
|
|
|
|
static void *
|
|
|
|
intel_get_pointer(GLcontext * ctx, struct gl_renderbuffer *rb,
|
|
|
|
GLint x, GLint y)
|
|
|
|
{
|
|
|
|
/* By returning NULL we force all software rendering to go through
|
|
|
|
* the span routines.
|
|
|
|
*/
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called via glRenderbufferStorageEXT() to set the format and allocate
|
|
|
|
* storage for a user-created renderbuffer.
|
|
|
|
*/
|
|
|
|
static GLboolean
|
|
|
|
intel_alloc_renderbuffer_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
|
|
|
|
GLenum internalFormat,
|
|
|
|
GLuint width, GLuint height)
|
|
|
|
{
|
|
|
|
struct intel_context *intel = intel_context(ctx);
|
|
|
|
struct intel_renderbuffer *irb = intel_renderbuffer(rb);
|
|
|
|
int cpp;
|
2009-12-08 15:51:18 -08:00
|
|
|
GLuint pitch;
|
2007-11-07 10:04:59 -08:00
|
|
|
|
|
|
|
ASSERT(rb->Name != 0);
|
|
|
|
|
|
|
|
switch (internalFormat) {
|
|
|
|
case GL_R3_G3_B2:
|
|
|
|
case GL_RGB4:
|
|
|
|
case GL_RGB5:
|
2009-10-08 20:27:27 -06:00
|
|
|
rb->Format = MESA_FORMAT_RGB565;
|
2007-11-07 10:04:59 -08:00
|
|
|
rb->DataType = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
|
|
|
case GL_RGB:
|
|
|
|
case GL_RGB8:
|
|
|
|
case GL_RGB10:
|
|
|
|
case GL_RGB12:
|
|
|
|
case GL_RGB16:
|
2009-12-08 09:57:27 -08:00
|
|
|
rb->Format = MESA_FORMAT_ARGB8888; /* XXX: Need xrgb8888 */
|
2008-08-24 17:59:10 +10:00
|
|
|
rb->DataType = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
2007-11-07 10:04:59 -08:00
|
|
|
case GL_RGBA:
|
|
|
|
case GL_RGBA2:
|
|
|
|
case GL_RGBA4:
|
|
|
|
case GL_RGB5_A1:
|
|
|
|
case GL_RGBA8:
|
|
|
|
case GL_RGB10_A2:
|
|
|
|
case GL_RGBA12:
|
|
|
|
case GL_RGBA16:
|
2009-10-08 20:27:27 -06:00
|
|
|
rb->Format = MESA_FORMAT_ARGB8888;
|
2007-11-07 10:04:59 -08:00
|
|
|
rb->DataType = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
|
|
|
case GL_STENCIL_INDEX:
|
|
|
|
case GL_STENCIL_INDEX1_EXT:
|
|
|
|
case GL_STENCIL_INDEX4_EXT:
|
|
|
|
case GL_STENCIL_INDEX8_EXT:
|
|
|
|
case GL_STENCIL_INDEX16_EXT:
|
|
|
|
/* alloc a depth+stencil buffer */
|
2009-10-21 20:02:33 -06:00
|
|
|
rb->Format = MESA_FORMAT_S8_Z24;
|
2007-11-07 10:04:59 -08:00
|
|
|
rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
|
|
|
|
break;
|
|
|
|
case GL_DEPTH_COMPONENT16:
|
2009-10-08 20:27:27 -06:00
|
|
|
rb->Format = MESA_FORMAT_Z16;
|
2007-11-07 10:04:59 -08:00
|
|
|
rb->DataType = GL_UNSIGNED_SHORT;
|
|
|
|
break;
|
|
|
|
case GL_DEPTH_COMPONENT:
|
|
|
|
case GL_DEPTH_COMPONENT24:
|
|
|
|
case GL_DEPTH_COMPONENT32:
|
2009-10-21 20:02:33 -06:00
|
|
|
rb->Format = MESA_FORMAT_S8_Z24;
|
2007-11-07 10:04:59 -08:00
|
|
|
rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
|
|
|
|
break;
|
|
|
|
case GL_DEPTH_STENCIL_EXT:
|
|
|
|
case GL_DEPTH24_STENCIL8_EXT:
|
2009-10-21 20:02:33 -06:00
|
|
|
rb->Format = MESA_FORMAT_S8_Z24;
|
2007-11-07 10:04:59 -08:00
|
|
|
rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_mesa_problem(ctx,
|
|
|
|
"Unexpected format in intel_alloc_renderbuffer_storage");
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-10-08 20:27:27 -06:00
|
|
|
rb->_BaseFormat = _mesa_base_fbo_format(ctx, internalFormat);
|
2009-12-08 16:06:13 -08:00
|
|
|
cpp = _mesa_get_format_bytes(rb->Format);
|
2009-10-08 20:27:27 -06:00
|
|
|
|
2007-11-07 10:04:59 -08:00
|
|
|
intelFlush(ctx);
|
|
|
|
|
|
|
|
/* free old region */
|
|
|
|
if (irb->region) {
|
|
|
|
intel_region_release(&irb->region);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate new memory region/renderbuffer */
|
|
|
|
|
2009-12-08 15:51:18 -08:00
|
|
|
/* Choose a pitch to match hardware requirements:
|
|
|
|
*/
|
|
|
|
pitch = ((cpp * width + 63) & ~63) / cpp;
|
|
|
|
|
|
|
|
/* alloc hardware renderbuffer */
|
|
|
|
DBG("Allocating %d x %d Intel RBO (pitch %d)\n", width, height, pitch);
|
2007-11-07 10:04:59 -08:00
|
|
|
|
2009-12-08 15:51:18 -08:00
|
|
|
irb->region = intel_region_alloc(intel, I915_TILING_NONE, cpp,
|
|
|
|
width, height, pitch, GL_TRUE);
|
|
|
|
if (!irb->region)
|
|
|
|
return GL_FALSE; /* out of memory? */
|
2007-11-07 10:04:59 -08:00
|
|
|
|
2009-12-08 15:51:18 -08:00
|
|
|
ASSERT(irb->region->buffer);
|
2007-11-07 10:04:59 -08:00
|
|
|
|
2009-12-08 15:51:18 -08:00
|
|
|
rb->Width = width;
|
|
|
|
rb->Height = height;
|
2007-11-07 10:04:59 -08:00
|
|
|
|
2009-12-08 15:51:18 -08:00
|
|
|
return GL_TRUE;
|
2007-11-07 10:04:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called for each hardware renderbuffer when a _window_ is resized.
|
|
|
|
* Just update fields.
|
|
|
|
* Not used for user-created renderbuffers!
|
|
|
|
*/
|
|
|
|
static GLboolean
|
|
|
|
intel_alloc_window_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
|
|
|
|
GLenum internalFormat, GLuint width, GLuint height)
|
|
|
|
{
|
|
|
|
ASSERT(rb->Name == 0);
|
|
|
|
rb->Width = width;
|
|
|
|
rb->Height = height;
|
2009-10-08 20:27:27 -06:00
|
|
|
rb->InternalFormat = internalFormat;
|
2007-11-07 10:04:59 -08:00
|
|
|
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2009-01-29 14:57:31 -07:00
|
|
|
|
2007-11-07 10:04:59 -08:00
|
|
|
static void
|
|
|
|
intel_resize_buffers(GLcontext *ctx, struct gl_framebuffer *fb,
|
|
|
|
GLuint width, GLuint height)
|
|
|
|
{
|
|
|
|
struct intel_framebuffer *intel_fb = (struct intel_framebuffer*)fb;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
_mesa_resize_framebuffer(ctx, fb, width, height);
|
|
|
|
|
|
|
|
fb->Initialized = GL_TRUE; /* XXX remove someday */
|
|
|
|
|
|
|
|
if (fb->Name != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure all window system renderbuffers are up to date */
|
2009-01-14 01:14:32 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
2007-11-07 10:04:59 -08:00
|
|
|
struct gl_renderbuffer *rb = &intel_fb->color_rb[i]->Base;
|
|
|
|
|
|
|
|
/* only resize if size is changing */
|
|
|
|
if (rb && (rb->Width != width || rb->Height != height)) {
|
|
|
|
rb->AllocStorage(ctx, rb, rb->InternalFormat, width, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-29 14:57:31 -07:00
|
|
|
|
|
|
|
/** Dummy function for gl_renderbuffer::AllocStorage() */
|
2007-11-07 10:04:59 -08:00
|
|
|
static GLboolean
|
|
|
|
intel_nop_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
|
|
|
|
GLenum internalFormat, GLuint width, GLuint height)
|
|
|
|
{
|
|
|
|
_mesa_problem(ctx, "intel_op_alloc_storage should never be called.");
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-09 16:55:32 -05:00
|
|
|
void
|
|
|
|
intel_renderbuffer_set_region(struct intel_renderbuffer *rb,
|
|
|
|
struct intel_region *region)
|
|
|
|
{
|
|
|
|
struct intel_region *old;
|
|
|
|
|
|
|
|
old = rb->region;
|
|
|
|
rb->region = NULL;
|
|
|
|
intel_region_reference(&rb->region, region);
|
|
|
|
intel_region_release(&old);
|
|
|
|
}
|
2007-11-07 10:04:59 -08:00
|
|
|
|
2009-01-29 14:57:31 -07:00
|
|
|
|
2007-11-07 10:04:59 -08:00
|
|
|
/**
|
|
|
|
* Create a new intel_renderbuffer which corresponds to an on-screen window,
|
|
|
|
* not a user-created renderbuffer.
|
|
|
|
*/
|
|
|
|
struct intel_renderbuffer *
|
2009-10-29 19:12:50 -06:00
|
|
|
intel_create_renderbuffer(gl_format format)
|
2007-11-07 10:04:59 -08:00
|
|
|
{
|
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
|
|
|
|
|
|
|
struct intel_renderbuffer *irb;
|
|
|
|
const GLuint name = 0;
|
|
|
|
|
|
|
|
irb = CALLOC_STRUCT(intel_renderbuffer);
|
|
|
|
if (!irb) {
|
|
|
|
_mesa_error(ctx, GL_OUT_OF_MEMORY, "creating renderbuffer");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
_mesa_init_renderbuffer(&irb->Base, name);
|
|
|
|
irb->Base.ClassID = INTEL_RB_CLASS;
|
|
|
|
|
2009-10-29 19:12:50 -06:00
|
|
|
switch (format) {
|
|
|
|
case MESA_FORMAT_RGB565:
|
2009-10-08 20:27:27 -06:00
|
|
|
irb->Base._BaseFormat = GL_RGB;
|
2007-11-07 10:04:59 -08:00
|
|
|
irb->Base.DataType = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
2009-10-29 19:12:50 -06:00
|
|
|
case MESA_FORMAT_XRGB8888:
|
2009-12-07 17:06:07 -08:00
|
|
|
/* XXX this is a hack since XRGB surfaces don't seem to work
|
|
|
|
* properly yet. Reading the alpha channel returns 0 instead of 1.
|
|
|
|
*/
|
|
|
|
format = MESA_FORMAT_ARGB8888;
|
2009-02-25 22:54:51 -08:00
|
|
|
irb->Base._BaseFormat = GL_RGB;
|
|
|
|
irb->Base.DataType = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
2009-10-29 19:12:50 -06:00
|
|
|
case MESA_FORMAT_ARGB8888:
|
2007-11-07 10:04:59 -08:00
|
|
|
irb->Base._BaseFormat = GL_RGBA;
|
|
|
|
irb->Base.DataType = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
2009-10-29 19:12:50 -06:00
|
|
|
case MESA_FORMAT_Z16:
|
2007-11-07 10:04:59 -08:00
|
|
|
irb->Base._BaseFormat = GL_DEPTH_COMPONENT;
|
|
|
|
irb->Base.DataType = GL_UNSIGNED_SHORT;
|
|
|
|
break;
|
2009-10-29 19:12:50 -06:00
|
|
|
case MESA_FORMAT_X8_Z24:
|
2007-11-07 10:04:59 -08:00
|
|
|
irb->Base._BaseFormat = GL_DEPTH_COMPONENT;
|
|
|
|
irb->Base.DataType = GL_UNSIGNED_INT;
|
|
|
|
break;
|
2009-10-29 19:12:50 -06:00
|
|
|
case MESA_FORMAT_S8_Z24:
|
2009-10-08 20:27:27 -06:00
|
|
|
irb->Base._BaseFormat = GL_DEPTH_STENCIL;
|
2007-11-07 10:04:59 -08:00
|
|
|
irb->Base.DataType = GL_UNSIGNED_INT_24_8_EXT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_mesa_problem(NULL,
|
|
|
|
"Unexpected intFormat in intel_create_renderbuffer");
|
2009-10-28 13:09:44 -06:00
|
|
|
_mesa_free(irb);
|
2007-11-07 10:04:59 -08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-29 19:12:50 -06:00
|
|
|
irb->Base.Format = format;
|
|
|
|
irb->Base.InternalFormat = irb->Base._BaseFormat;
|
2007-11-07 10:04:59 -08:00
|
|
|
|
|
|
|
/* intel-specific methods */
|
|
|
|
irb->Base.Delete = intel_delete_renderbuffer;
|
|
|
|
irb->Base.AllocStorage = intel_alloc_window_storage;
|
|
|
|
irb->Base.GetPointer = intel_get_pointer;
|
|
|
|
|
|
|
|
return irb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new renderbuffer object.
|
|
|
|
* Typically called via glBindRenderbufferEXT().
|
|
|
|
*/
|
|
|
|
static struct gl_renderbuffer *
|
|
|
|
intel_new_renderbuffer(GLcontext * ctx, GLuint name)
|
|
|
|
{
|
|
|
|
/*struct intel_context *intel = intel_context(ctx); */
|
|
|
|
struct intel_renderbuffer *irb;
|
|
|
|
|
|
|
|
irb = CALLOC_STRUCT(intel_renderbuffer);
|
|
|
|
if (!irb) {
|
|
|
|
_mesa_error(ctx, GL_OUT_OF_MEMORY, "creating renderbuffer");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
_mesa_init_renderbuffer(&irb->Base, name);
|
|
|
|
irb->Base.ClassID = INTEL_RB_CLASS;
|
|
|
|
|
|
|
|
/* intel-specific methods */
|
|
|
|
irb->Base.Delete = intel_delete_renderbuffer;
|
|
|
|
irb->Base.AllocStorage = intel_alloc_renderbuffer_storage;
|
|
|
|
irb->Base.GetPointer = intel_get_pointer;
|
|
|
|
/* span routines set in alloc_storage function */
|
|
|
|
|
|
|
|
return &irb->Base;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called via glBindFramebufferEXT().
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
intel_bind_framebuffer(GLcontext * ctx, GLenum target,
|
|
|
|
struct gl_framebuffer *fb, struct gl_framebuffer *fbread)
|
|
|
|
{
|
|
|
|
if (target == GL_FRAMEBUFFER_EXT || target == GL_DRAW_FRAMEBUFFER_EXT) {
|
|
|
|
intel_draw_buffer(ctx, fb);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* don't need to do anything if target == GL_READ_FRAMEBUFFER_EXT */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called via glFramebufferRenderbufferEXT().
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
intel_framebuffer_renderbuffer(GLcontext * ctx,
|
|
|
|
struct gl_framebuffer *fb,
|
|
|
|
GLenum attachment, struct gl_renderbuffer *rb)
|
|
|
|
{
|
|
|
|
DBG("Intel FramebufferRenderbuffer %u %u\n", fb->Name, rb ? rb->Name : 0);
|
|
|
|
|
|
|
|
intelFlush(ctx);
|
|
|
|
|
|
|
|
_mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb);
|
|
|
|
intel_draw_buffer(ctx, fb);
|
|
|
|
}
|
|
|
|
|
2009-01-29 14:57:31 -07:00
|
|
|
|
2008-03-14 11:39:08 +08:00
|
|
|
static GLboolean
|
|
|
|
intel_update_wrapper(GLcontext *ctx, struct intel_renderbuffer *irb,
|
2008-08-24 17:59:10 +10:00
|
|
|
struct gl_texture_image *texImage)
|
2007-11-07 10:04:59 -08:00
|
|
|
{
|
2009-09-27 20:40:35 -06:00
|
|
|
gl_format texFormat;
|
2009-04-09 18:30:12 -07:00
|
|
|
|
2009-09-30 20:28:45 -06:00
|
|
|
if (texImage->TexFormat == MESA_FORMAT_ARGB8888) {
|
2009-01-14 16:28:55 -07:00
|
|
|
irb->Base.DataType = GL_UNSIGNED_BYTE;
|
2007-11-07 10:04:59 -08:00
|
|
|
DBG("Render to RGBA8 texture OK\n");
|
|
|
|
}
|
2009-10-29 19:12:50 -06:00
|
|
|
else if (texImage->TexFormat == MESA_FORMAT_XRGB8888) {
|
|
|
|
irb->Base.DataType = GL_UNSIGNED_BYTE;
|
|
|
|
DBG("Render to XGBA8 texture OK\n");
|
|
|
|
}
|
2009-09-30 20:28:45 -06:00
|
|
|
else if (texImage->TexFormat == MESA_FORMAT_RGB565) {
|
2009-04-09 18:30:12 -07:00
|
|
|
irb->Base.DataType = GL_UNSIGNED_BYTE;
|
2007-11-07 10:04:59 -08:00
|
|
|
DBG("Render to RGB5 texture OK\n");
|
|
|
|
}
|
2009-09-30 20:28:45 -06:00
|
|
|
else if (texImage->TexFormat == MESA_FORMAT_ARGB1555) {
|
2009-04-09 18:30:12 -07:00
|
|
|
irb->Base.DataType = GL_UNSIGNED_BYTE;
|
|
|
|
DBG("Render to ARGB1555 texture OK\n");
|
|
|
|
}
|
2009-09-30 20:28:45 -06:00
|
|
|
else if (texImage->TexFormat == MESA_FORMAT_ARGB4444) {
|
2009-04-09 18:30:12 -07:00
|
|
|
irb->Base.DataType = GL_UNSIGNED_BYTE;
|
|
|
|
DBG("Render to ARGB4444 texture OK\n");
|
|
|
|
}
|
2009-09-30 20:28:45 -06:00
|
|
|
else if (texImage->TexFormat == MESA_FORMAT_Z16) {
|
2009-01-14 16:28:55 -07:00
|
|
|
irb->Base.DataType = GL_UNSIGNED_SHORT;
|
2007-11-07 10:04:59 -08:00
|
|
|
DBG("Render to DEPTH16 texture OK\n");
|
2009-01-14 16:28:55 -07:00
|
|
|
}
|
2009-10-21 20:02:33 -06:00
|
|
|
else if (texImage->TexFormat == MESA_FORMAT_S8_Z24) {
|
2009-01-14 16:28:55 -07:00
|
|
|
irb->Base.DataType = GL_UNSIGNED_INT_24_8_EXT;
|
2008-03-14 11:39:08 +08:00
|
|
|
DBG("Render to DEPTH_STENCIL texture OK\n");
|
2007-11-07 10:04:59 -08:00
|
|
|
}
|
|
|
|
else {
|
2009-09-30 20:28:45 -06:00
|
|
|
DBG("Render to texture BAD FORMAT %d\n", texImage->TexFormat);
|
2008-03-14 11:39:08 +08:00
|
|
|
return GL_FALSE;
|
2007-11-07 10:04:59 -08:00
|
|
|
}
|
|
|
|
|
2009-10-08 20:27:27 -06:00
|
|
|
irb->Base.Format = texImage->TexFormat;
|
|
|
|
|
2009-09-30 20:28:45 -06:00
|
|
|
texFormat = texImage->TexFormat;
|
2009-09-27 20:40:35 -06:00
|
|
|
|
2009-10-08 20:27:27 -06:00
|
|
|
irb->Base.InternalFormat = texImage->InternalFormat;
|
|
|
|
irb->Base._BaseFormat = _mesa_base_fbo_format(ctx, irb->Base.InternalFormat);
|
2007-11-07 10:04:59 -08:00
|
|
|
irb->Base.Width = texImage->Width;
|
|
|
|
irb->Base.Height = texImage->Height;
|
|
|
|
|
|
|
|
irb->Base.Delete = intel_delete_renderbuffer;
|
|
|
|
irb->Base.AllocStorage = intel_nop_alloc_storage;
|
|
|
|
|
2008-03-14 11:39:08 +08:00
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2009-01-29 14:57:31 -07:00
|
|
|
|
2008-03-14 11:39:08 +08:00
|
|
|
/**
|
|
|
|
* When glFramebufferTexture[123]D is called this function sets up the
|
|
|
|
* gl_renderbuffer wrapper around the texture image.
|
|
|
|
* This will have the region info needed for hardware rendering.
|
|
|
|
*/
|
|
|
|
static struct intel_renderbuffer *
|
|
|
|
intel_wrap_texture(GLcontext * ctx, struct gl_texture_image *texImage)
|
|
|
|
{
|
2009-01-29 14:57:31 -07:00
|
|
|
const GLuint name = ~0; /* not significant, but distinct for debugging */
|
2008-03-14 11:39:08 +08:00
|
|
|
struct intel_renderbuffer *irb;
|
|
|
|
|
|
|
|
/* make an intel_renderbuffer to wrap the texture image */
|
|
|
|
irb = CALLOC_STRUCT(intel_renderbuffer);
|
|
|
|
if (!irb) {
|
|
|
|
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glFramebufferTexture");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
_mesa_init_renderbuffer(&irb->Base, name);
|
|
|
|
irb->Base.ClassID = INTEL_RB_CLASS;
|
|
|
|
|
|
|
|
if (!intel_update_wrapper(ctx, irb, texImage)) {
|
|
|
|
_mesa_free(irb);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-07 10:04:59 -08:00
|
|
|
return irb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by glFramebufferTexture[123]DEXT() (and other places) to
|
|
|
|
* prepare for rendering into texture memory. This might be called
|
|
|
|
* many times to choose different texture levels, cube faces, etc
|
|
|
|
* before intel_finish_render_texture() is ever called.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
intel_render_texture(GLcontext * ctx,
|
|
|
|
struct gl_framebuffer *fb,
|
|
|
|
struct gl_renderbuffer_attachment *att)
|
|
|
|
{
|
|
|
|
struct gl_texture_image *newImage
|
|
|
|
= att->Texture->Image[att->CubeMapFace][att->TextureLevel];
|
|
|
|
struct intel_renderbuffer *irb = intel_renderbuffer(att->Renderbuffer);
|
|
|
|
struct intel_texture_image *intel_image;
|
2009-07-09 09:32:21 -07:00
|
|
|
GLuint dst_x, dst_y;
|
2007-11-07 10:04:59 -08:00
|
|
|
|
|
|
|
(void) fb;
|
|
|
|
|
|
|
|
ASSERT(newImage);
|
|
|
|
|
2009-05-20 14:16:34 -07:00
|
|
|
intel_image = intel_texture_image(newImage);
|
|
|
|
if (!intel_image->mt) {
|
|
|
|
/* Fallback on drawing to a texture that doesn't have a miptree
|
|
|
|
* (has a border, width/height 0, etc.)
|
2008-12-06 15:47:23 -08:00
|
|
|
*/
|
2009-01-29 14:57:31 -07:00
|
|
|
_mesa_reference_renderbuffer(&att->Renderbuffer, NULL);
|
|
|
|
_mesa_render_texture(ctx, fb, att);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (!irb) {
|
2007-11-07 10:04:59 -08:00
|
|
|
irb = intel_wrap_texture(ctx, newImage);
|
|
|
|
if (irb) {
|
|
|
|
/* bind the wrapper to the attachment point */
|
|
|
|
_mesa_reference_renderbuffer(&att->Renderbuffer, &irb->Base);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* fallback to software rendering */
|
|
|
|
_mesa_render_texture(ctx, fb, att);
|
|
|
|
return;
|
|
|
|
}
|
2009-01-29 14:57:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!intel_update_wrapper(ctx, irb, newImage)) {
|
2008-03-14 11:39:08 +08:00
|
|
|
_mesa_reference_renderbuffer(&att->Renderbuffer, NULL);
|
|
|
|
_mesa_render_texture(ctx, fb, att);
|
|
|
|
return;
|
2007-11-07 10:04:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
DBG("Begin render texture tid %x tex=%u w=%d h=%d refcount=%d\n",
|
|
|
|
_glthread_GetID(),
|
|
|
|
att->Texture->Name, newImage->Width, newImage->Height,
|
|
|
|
irb->Base.RefCount);
|
|
|
|
|
|
|
|
/* point the renderbufer's region to the texture image region */
|
|
|
|
if (irb->region != intel_image->mt->region) {
|
|
|
|
if (irb->region)
|
|
|
|
intel_region_release(&irb->region);
|
|
|
|
intel_region_reference(&irb->region, intel_image->mt->region);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compute offset of the particular 2D image within the texture region */
|
2009-07-09 09:32:21 -07:00
|
|
|
intel_miptree_get_image_offset(intel_image->mt,
|
|
|
|
att->TextureLevel,
|
|
|
|
att->CubeMapFace,
|
|
|
|
att->Zoffset,
|
|
|
|
&dst_x, &dst_y);
|
|
|
|
|
|
|
|
intel_image->mt->region->draw_offset = (dst_y * intel_image->mt->pitch +
|
|
|
|
dst_x) * intel_image->mt->cpp;
|
|
|
|
intel_image->mt->region->draw_x = dst_x;
|
|
|
|
intel_image->mt->region->draw_y = dst_y;
|
2009-11-04 14:54:09 -08:00
|
|
|
intel_image->used_as_render_target = GL_TRUE;
|
2007-11-07 10:04:59 -08:00
|
|
|
|
|
|
|
/* update drawing region, etc */
|
|
|
|
intel_draw_buffer(ctx, fb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by Mesa when rendering to a texture is done.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
intel_finish_render_texture(GLcontext * ctx,
|
|
|
|
struct gl_renderbuffer_attachment *att)
|
|
|
|
{
|
2009-12-09 11:36:45 -08:00
|
|
|
struct intel_context *intel = intel_context(ctx);
|
2009-11-04 14:54:09 -08:00
|
|
|
struct gl_texture_object *tex_obj = att->Texture;
|
|
|
|
struct gl_texture_image *image =
|
|
|
|
tex_obj->Image[att->CubeMapFace][att->TextureLevel];
|
|
|
|
struct intel_texture_image *intel_image = intel_texture_image(image);
|
|
|
|
|
|
|
|
/* Flag that this image may now be validated into the object's miptree. */
|
|
|
|
intel_image->used_as_render_target = GL_FALSE;
|
2007-11-07 10:04:59 -08:00
|
|
|
|
2009-12-09 11:36:45 -08:00
|
|
|
/* Since we've (probably) rendered to the texture and will (likely) use
|
|
|
|
* it in the texture domain later on in this batchbuffer, flush the
|
|
|
|
* batch. Once again, we wish for a domain tracker in libdrm to cover
|
|
|
|
* usage inside of a batchbuffer like GEM does in the kernel.
|
|
|
|
*/
|
|
|
|
intel_batchbuffer_emit_mi_flush(intel->batch);
|
|
|
|
}
|
2007-11-07 10:04:59 -08:00
|
|
|
|
2009-01-20 15:30:22 -07:00
|
|
|
/**
|
|
|
|
* Do additional "completeness" testing of a framebuffer object.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
intel_validate_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb)
|
|
|
|
{
|
2009-01-22 15:32:38 -07:00
|
|
|
const struct intel_renderbuffer *depthRb =
|
|
|
|
intel_get_renderbuffer(fb, BUFFER_DEPTH);
|
|
|
|
const struct intel_renderbuffer *stencilRb =
|
|
|
|
intel_get_renderbuffer(fb, BUFFER_STENCIL);
|
2009-04-09 18:30:12 -07:00
|
|
|
int i;
|
2009-01-22 15:32:38 -07:00
|
|
|
|
|
|
|
if (stencilRb && stencilRb != depthRb) {
|
|
|
|
/* we only support combined depth/stencil buffers, not separate
|
|
|
|
* stencil buffers.
|
|
|
|
*/
|
|
|
|
fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
|
|
|
|
}
|
2009-02-26 16:51:50 -07:00
|
|
|
|
2009-04-09 18:30:12 -07:00
|
|
|
for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
|
|
|
|
struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[i];
|
|
|
|
struct intel_renderbuffer *irb = intel_renderbuffer(rb);
|
|
|
|
|
|
|
|
if (rb == NULL)
|
|
|
|
continue;
|
|
|
|
|
2009-05-20 14:05:03 -07:00
|
|
|
if (irb == NULL) {
|
|
|
|
fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-12-08 09:57:27 -08:00
|
|
|
switch (irb->Base.Format) {
|
2009-04-09 18:30:12 -07:00
|
|
|
case MESA_FORMAT_ARGB8888:
|
2009-10-29 19:12:50 -06:00
|
|
|
case MESA_FORMAT_XRGB8888:
|
2009-04-09 18:30:12 -07:00
|
|
|
case MESA_FORMAT_RGB565:
|
|
|
|
case MESA_FORMAT_ARGB1555:
|
|
|
|
case MESA_FORMAT_ARGB4444:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
|
2009-02-26 16:51:50 -07:00
|
|
|
}
|
|
|
|
}
|
2009-01-20 15:30:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-07 10:04:59 -08:00
|
|
|
/**
|
|
|
|
* Do one-time context initializations related to GL_EXT_framebuffer_object.
|
|
|
|
* Hook in device driver functions.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
intel_fbo_init(struct intel_context *intel)
|
|
|
|
{
|
|
|
|
intel->ctx.Driver.NewFramebuffer = intel_new_framebuffer;
|
|
|
|
intel->ctx.Driver.NewRenderbuffer = intel_new_renderbuffer;
|
|
|
|
intel->ctx.Driver.BindFramebuffer = intel_bind_framebuffer;
|
|
|
|
intel->ctx.Driver.FramebufferRenderbuffer = intel_framebuffer_renderbuffer;
|
|
|
|
intel->ctx.Driver.RenderTexture = intel_render_texture;
|
|
|
|
intel->ctx.Driver.FinishRenderTexture = intel_finish_render_texture;
|
|
|
|
intel->ctx.Driver.ResizeBuffers = intel_resize_buffers;
|
2009-01-20 15:30:22 -07:00
|
|
|
intel->ctx.Driver.ValidateFramebuffer = intel_validate_framebuffer;
|
2009-09-19 17:06:15 -06:00
|
|
|
intel->ctx.Driver.BlitFramebuffer = _mesa_meta_BlitFramebuffer;
|
2007-11-07 10:04:59 -08:00
|
|
|
}
|