⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 intel_fbo.c

📁 mesa-6.5-minigui源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************************************************************** *  * 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. *  **************************************************************************/#include "imports.h"#include "mtypes.h"#include "fbobject.h"#include "framebuffer.h"#include "renderbuffer.h"#include "context.h"#include "texformat.h"#include "texrender.h"#include "intel_context.h"#include "intel_buffers.h"#include "intel_bufmgr.h"#include "intel_depthstencil.h"#include "intel_fbo.h"#include "intel_mipmap_tree.h"#include "intel_regions.h"#include "intel_span.h"#define INTEL_RB_CLASS 0x12345678/* XXX FBO: move this to intel_context.h (inlined) *//** * Return a gl_renderbuffer ptr casted to intel_renderbuffer. * NULL will be returned if the rb isn't really an intel_renderbuffer. * This is determiend by checking the ClassID. */struct intel_renderbuffer *intel_renderbuffer( struct gl_renderbuffer *rb ){   struct intel_renderbuffer *irb = (struct intel_renderbuffer *) rb;   if (irb && irb->Base.ClassID == INTEL_RB_CLASS) {      /*_mesa_warning(NULL, "Returning non-intel Rb\n");*/      return irb;   }   else      return NULL;}struct intel_renderbuffer *intel_get_renderbuffer(struct gl_framebuffer *fb, GLuint attIndex){   return intel_renderbuffer(fb->Attachment[attIndex].Renderbuffer);}struct intel_region *intel_get_rb_region(struct gl_framebuffer *fb, GLuint attIndex){   struct intel_renderbuffer *irb      = intel_renderbuffer(fb->Attachment[attIndex].Renderbuffer);   if (irb)      return irb->region;   else      return NULL;}/** * Create a new framebuffer object. */static struct gl_framebuffer *intel_new_framebuffer(GLcontext *ctx, GLuint name){   /* there's no intel_framebuffer at this time, just use Mesa's class */   return _mesa_new_framebuffer(ctx, name);}static voidintel_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);   if (irb->PairedStencil || irb->PairedDepth) {      intel_unpair_depth_stencil(ctx, irb);   }   if (intel && irb->region) {      intel_region_release(intel, &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 GLbooleanintel_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) {      /*LOCK_HARDWARE(intel);*/      intel_region_release(intel, &irb->region);      /*UNLOCK_HARDWARE(intel);*/   }   /* 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 */      _mesa_debug(ctx, "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;   }}/** * Called for each hardware renderbuffer when a _window_ is resized. * Just update fields. * Not used for user-created renderbuffers! */static GLbooleanintel_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;   rb->_ActualFormat = internalFormat;   return GL_TRUE;}static GLbooleanintel_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;}/** * Create a new intel_renderbuffer which corresponds to an on-screen window, * not a user-created renderbuffer. * \param width  the screen width * \param height  the screen height */struct intel_renderbuffer *intel_create_renderbuffer(GLenum intFormat, GLsizei width, GLsizei height,                          int offset, int pitch, int cpp, void *map){   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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -