コード例 #1
0
static GLboolean
intel_update_wrapper(GLcontext *ctx, struct intel_renderbuffer *irb, 
                          struct gl_texture_image *texImage)
{
   if (texImage->TexFormat == &_mesa_texformat_argb8888) {
      irb->Base._ActualFormat = GL_RGBA8;
      irb->Base._BaseFormat = GL_RGBA;
      DBG("Render to RGBA8 texture OK\n");
   }
   else if (texImage->TexFormat == &_mesa_texformat_rgb565) {
      irb->Base._ActualFormat = GL_RGB5;
      irb->Base._BaseFormat = GL_RGB;
      DBG("Render to RGB5 texture OK\n");
   }
   else if (texImage->TexFormat == &_mesa_texformat_z16) {
      irb->Base._ActualFormat = GL_DEPTH_COMPONENT16;
      irb->Base._BaseFormat = GL_DEPTH_COMPONENT;
      DBG("Render to DEPTH16 texture OK\n");
   } else if (texImage->TexFormat == &_mesa_texformat_z24_s8) {
      irb->Base._ActualFormat = GL_DEPTH24_STENCIL8_EXT;
      irb->Base._BaseFormat = GL_DEPTH_STENCIL_EXT;
      DBG("Render to DEPTH_STENCIL texture OK\n");
   }
   else {
      DBG("Render to texture BAD FORMAT %d\n",
	  texImage->TexFormat->MesaFormat);
      return GL_FALSE;
   }

   irb->Base.InternalFormat = irb->Base._ActualFormat;
   irb->Base.Width = texImage->Width;
   irb->Base.Height = texImage->Height;
   irb->Base.DataType = GL_UNSIGNED_BYTE;       /* FBO XXX fix */
   irb->Base.RedBits = texImage->TexFormat->RedBits;
   irb->Base.GreenBits = texImage->TexFormat->GreenBits;
   irb->Base.BlueBits = texImage->TexFormat->BlueBits;
   irb->Base.AlphaBits = texImage->TexFormat->AlphaBits;
   irb->Base.DepthBits = texImage->TexFormat->DepthBits;

   irb->Base.Delete = intel_delete_renderbuffer;
   irb->Base.AllocStorage = intel_nop_alloc_storage;
   intel_set_span_functions(&irb->Base);

   irb->RenderToTexture = GL_TRUE;

   return GL_TRUE;
}
コード例 #2
0
void
intel_renderbuffer_map(struct intel_context *intel, struct gl_renderbuffer *rb)
{
   struct intel_renderbuffer *irb = intel_renderbuffer(rb);

   if (irb == NULL || irb->region == NULL)
      return;

   drm_intel_gem_bo_map_gtt(irb->region->buffer);

   rb->Data = irb->region->buffer->virtual;
   rb->RowStride = irb->region->pitch;

   /* Flip orientation if it's the window system buffer */
   if (!rb->Name) {
      rb->Data += rb->RowStride * (irb->region->height - 1) * irb->region->cpp;
      rb->RowStride = -rb->RowStride;
   }

   intel_set_span_functions(intel, rb);
}
コード例 #3
0
/**
 * Create a new intel_renderbuffer which corresponds to an on-screen window,
 * not a user-created renderbuffer.
 */
struct intel_renderbuffer *
intel_create_renderbuffer(GLenum intFormat)
{
   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;

   switch (intFormat) {
   case GL_RGB5:
      irb->Base._ActualFormat = GL_RGB5;
      irb->Base._BaseFormat = GL_RGBA;
      irb->Base.RedBits = 5;
      irb->Base.GreenBits = 6;
      irb->Base.BlueBits = 5;
      irb->Base.DataType = GL_UNSIGNED_BYTE;
      break;
   case GL_RGBA8:
      irb->Base._ActualFormat = GL_RGBA8;
      irb->Base._BaseFormat = GL_RGBA;
      irb->Base.RedBits = 8;
      irb->Base.GreenBits = 8;
      irb->Base.BlueBits = 8;
      irb->Base.AlphaBits = 8;
      irb->Base.DataType = GL_UNSIGNED_BYTE;
      break;
   case GL_STENCIL_INDEX8_EXT:
      irb->Base._ActualFormat = GL_STENCIL_INDEX8_EXT;
      irb->Base._BaseFormat = GL_STENCIL_INDEX;
      irb->Base.StencilBits = 8;
      irb->Base.DataType = GL_UNSIGNED_BYTE;
      break;
   case GL_DEPTH_COMPONENT16:
      irb->Base._ActualFormat = GL_DEPTH_COMPONENT16;
      irb->Base._BaseFormat = GL_DEPTH_COMPONENT;
      irb->Base.DepthBits = 16;
      irb->Base.DataType = GL_UNSIGNED_SHORT;
      break;
   case GL_DEPTH_COMPONENT24:
      irb->Base._ActualFormat = GL_DEPTH24_STENCIL8_EXT;
      irb->Base._BaseFormat = GL_DEPTH_COMPONENT;
      irb->Base.DepthBits = 24;
      irb->Base.DataType = GL_UNSIGNED_INT;
      break;
   case GL_DEPTH24_STENCIL8_EXT:
      irb->Base._ActualFormat = GL_DEPTH24_STENCIL8_EXT;
      irb->Base._BaseFormat = GL_DEPTH_STENCIL_EXT;
      irb->Base.DepthBits = 24;
      irb->Base.StencilBits = 8;
      irb->Base.DataType = GL_UNSIGNED_INT_24_8_EXT;
      break;
   default:
      _mesa_problem(NULL,
                    "Unexpected intFormat in intel_create_renderbuffer");
      return NULL;
   }

   irb->Base.InternalFormat = intFormat;

   /* intel-specific methods */
   irb->Base.Delete = intel_delete_renderbuffer;
   irb->Base.AllocStorage = intel_alloc_window_storage;
   irb->Base.GetPointer = intel_get_pointer;
   /* This sets the Get/PutRow/Value functions */
   intel_set_span_functions(&irb->Base);

   return irb;
}
コード例 #4
0
/**
 * 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);
   GLboolean softwareBuffer = GL_FALSE;
   int cpp;

   ASSERT(rb->Name != 0);

   switch (internalFormat) {
   case GL_R3_G3_B2:
   case GL_RGB4:
   case GL_RGB5:
      rb->_ActualFormat = GL_RGB5;
      rb->DataType = GL_UNSIGNED_BYTE;
      rb->RedBits = 5;
      rb->GreenBits = 6;
      rb->BlueBits = 5;
      cpp = 2;
      break;
   case GL_RGB:
   case GL_RGB8:
   case GL_RGB10:
   case GL_RGB12:
   case GL_RGB16:
   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:
      rb->_ActualFormat = GL_RGBA8;
      rb->DataType = GL_UNSIGNED_BYTE;
      rb->RedBits = 8;
      rb->GreenBits = 8;
      rb->BlueBits = 8;
      rb->AlphaBits = 8;
      cpp = 4;
      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 */
      rb->_ActualFormat = GL_DEPTH24_STENCIL8_EXT;
      rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
      rb->StencilBits = 8;
      cpp = 4;
      break;
   case GL_DEPTH_COMPONENT16:
      rb->_ActualFormat = GL_DEPTH_COMPONENT16;
      rb->DataType = GL_UNSIGNED_SHORT;
      rb->DepthBits = 16;
      cpp = 2;
      break;
   case GL_DEPTH_COMPONENT:
   case GL_DEPTH_COMPONENT24:
   case GL_DEPTH_COMPONENT32:
      rb->_ActualFormat = GL_DEPTH24_STENCIL8_EXT;
      rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
      rb->DepthBits = 24;
      cpp = 4;
      break;
   case GL_DEPTH_STENCIL_EXT:
   case GL_DEPTH24_STENCIL8_EXT:
      rb->_ActualFormat = GL_DEPTH24_STENCIL8_EXT;
      rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
      rb->DepthBits = 24;
      rb->StencilBits = 8;
      cpp = 4;
      break;
   default:
      _mesa_problem(ctx,
                    "Unexpected format in intel_alloc_renderbuffer_storage");
      return GL_FALSE;
   }

   intelFlush(ctx);

   /* free old region */
   if (irb->region) {
      intel_region_release(&irb->region);
   }

   /* allocate new memory region/renderbuffer */
   if (softwareBuffer) {
      return _mesa_soft_renderbuffer_storage(ctx, rb, internalFormat,
                                             width, height);
   }
   else {
      /* Choose a pitch to match hardware requirements:
       */
      GLuint pitch = ((cpp * width + 63) & ~63) / cpp;

      /* alloc hardware renderbuffer */
      DBG("Allocating %d x %d Intel RBO (pitch %d)\n", width,
	  height, pitch);

      irb->region = intel_region_alloc(intel, cpp, pitch, height);
      if (!irb->region)
         return GL_FALSE;       /* out of memory? */

      ASSERT(irb->region->buffer);

      rb->Width = width;
      rb->Height = height;

      /* This sets the Get/PutRow/Value functions */
      intel_set_span_functions(&irb->Base);

      return GL_TRUE;
   }
}