📄 idirectfbgl_mesa.c
字号:
/* * Copyright (C) 2004-2005 Claudio Ciccani <klan@users.sf.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * * Based on glfbdev.c, written by Brian Paul. * */#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <directfb.h>#include <direct/messages.h>#include <direct/interface.h>#include <direct/mem.h>#ifdef CLAMP# undef CLAMP#endif #include "GL/directfbgl.h"#include "glheader.h"#include "buffers.h"#include "context.h"#include "extensions.h"#include "framebuffer.h"#include "renderbuffer.h"#include "imports.h"#include "texformat.h"#include "teximage.h"#include "texstore.h"#include "array_cache/acache.h"#include "swrast/swrast.h"#include "swrast_setup/swrast_setup.h"#include "tnl/tnl.h"#include "tnl/t_context.h"#include "tnl/t_pipeline.h"#include "drivers/common/driverfuncs.h"static DFBResultProbe( void *data );static DFBResultConstruct( IDirectFBGL *thiz, IDirectFBSurface *surface );#include <direct/interface_implementation.h>DIRECT_INTERFACE_IMPLEMENTATION( IDirectFBGL, Mesa )/* * private data struct of IDirectFBGL */typedef struct { int ref; /* reference counter */ bool locked; IDirectFBSurface *surface; DFBSurfacePixelFormat format; int width; int height; struct { __u8 *start; __u8 *end; int pitch; } video; GLvisual visual; GLframebuffer framebuffer; GLcontext context; struct gl_renderbuffer render;} IDirectFBGL_data;static bool dfb_mesa_setup_visual ( GLvisual *visual, DFBSurfacePixelFormat format );static bool dfb_mesa_create_context ( GLcontext *context, GLframebuffer *framebuffer, GLvisual *visual, DFBSurfacePixelFormat format, IDirectFBGL_data *data );static void dfb_mesa_destroy_context( GLcontext *context, GLframebuffer *framebuffer );static voidIDirectFBGL_Destruct( IDirectFBGL *thiz ){ IDirectFBGL_data *data = (IDirectFBGL_data*) thiz->priv; dfb_mesa_destroy_context( &data->context, &data->framebuffer ); data->surface->Release( data->surface ); DIRECT_DEALLOCATE_INTERFACE( thiz );}static DFBResultIDirectFBGL_AddRef( IDirectFBGL *thiz ){ DIRECT_INTERFACE_GET_DATA( IDirectFBGL ); data->ref++; return DFB_OK;}static DFBResultIDirectFBGL_Release( IDirectFBGL *thiz ){ DIRECT_INTERFACE_GET_DATA( IDirectFBGL ) if (--data->ref == 0) { IDirectFBGL_Destruct( thiz ); } return DFB_OK;}static DFBResultIDirectFBGL_Lock( IDirectFBGL *thiz ){ IDirectFBSurface *surface; int width = 0; int height = 0; DFBResult err; DIRECT_INTERFACE_GET_DATA( IDirectFBGL ); if (data->locked) return DFB_LOCKED; surface = data->surface; surface->GetSize( surface, &width, &height ); err = surface->Lock( surface, DSLF_READ | DSLF_WRITE, (void**) &data->video.start, &data->video.pitch ); if (err != DFB_OK) { D_ERROR( "DirectFBGL/Mesa: couldn't lock surface.\n" ); return err; } data->video.end = data->video.start + (height-1) * data->video.pitch; data->render.Data = data->video.start; if (data->width != width || data->height != height) { data->width = width; data->height = height; _mesa_ResizeBuffersMESA(); } data->locked = true; return DFB_OK;}static DFBResultIDirectFBGL_Unlock( IDirectFBGL *thiz ){ DIRECT_INTERFACE_GET_DATA( IDirectFBGL ); if (!data->locked) return DFB_OK; data->surface->Unlock( data->surface ); data->video.start = NULL; data->video.end = NULL; data->locked = false; return DFB_OK;}static DFBResultIDirectFBGL_GetAttributes( IDirectFBGL *thiz, DFBGLAttributes *attributes ){ GLvisual *visual; DIRECT_INTERFACE_GET_DATA( IDirectFBGL ); if (!attributes) return DFB_INVARG; visual = &data->visual; attributes->buffer_size = visual->rgbBits ? : visual->indexBits; attributes->depth_size = visual->depthBits; attributes->stencil_size = visual->stencilBits; attributes->aux_buffers = visual->numAuxBuffers; attributes->red_size = visual->redBits; attributes->green_size = visual->greenBits; attributes->blue_size = visual->blueBits; attributes->alpha_size = visual->alphaBits; attributes->accum_red_size = visual->accumRedBits; attributes->accum_green_size = visual->accumGreenBits; attributes->accum_blue_size = visual->accumBlueBits; attributes->accum_alpha_size = visual->accumAlphaBits; attributes->double_buffer = (visual->doubleBufferMode != 0); attributes->stereo = (visual->stereoMode != 0); return DFB_OK;}/* exported symbols */static DFBResultProbe( void *data ){ return DFB_OK;}static DFBResultConstruct( IDirectFBGL *thiz, IDirectFBSurface *surface ){ /* Allocate interface data. */ DIRECT_ALLOCATE_INTERFACE_DATA( thiz, IDirectFBGL ); /* Initialize interface data. */ data->ref = 1; data->surface = surface; surface->AddRef( surface ); surface->GetPixelFormat( surface, &data->format ); surface->GetSize( surface, &data->width, &data->height ); /* Configure visual. */ if (!dfb_mesa_setup_visual( &data->visual, data->format )) { D_ERROR( "DirectFBGL/Mesa: failed to initialize visual.\n" ); surface->Release( surface ); return DFB_UNSUPPORTED; } /* Create context. */ if (!dfb_mesa_create_context( &data->context, &data->framebuffer, &data->visual, data->format, data )) { D_ERROR( "DirectFBGL/Mesa: failed to create context.\n" ); surface->Release( surface ); return DFB_UNSUPPORTED; } /* Assign interface pointers. */ thiz->AddRef = IDirectFBGL_AddRef; thiz->Release = IDirectFBGL_Release; thiz->Lock = IDirectFBGL_Lock; thiz->Unlock = IDirectFBGL_Unlock; thiz->GetAttributes = IDirectFBGL_GetAttributes; return DFB_OK;}/* internal functions */static const GLubyte*get_string( GLcontext *ctx, GLenum pname ){ switch (pname) { case GL_VENDOR: return "Claudio Ciccani"; case GL_VERSION: return "1.0"; default: return NULL; }}static voidupdate_state( GLcontext *ctx, GLuint new_state ){ _swrast_InvalidateState( ctx, new_state ); _swsetup_InvalidateState( ctx, new_state ); _ac_InvalidateState( ctx, new_state ); _tnl_InvalidateState( ctx, new_state );}static voidget_buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height ){ GLcontext *ctx = _mesa_get_current_context(); IDirectFBGL_data *data = (IDirectFBGL_data*) ctx->DriverCtx; *width = (GLuint) data->width; *height = (GLuint) data->height;}static voidset_viewport( GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h ){ _mesa_ResizeBuffersMESA();}/* required but not used */static voidset_buffer( GLcontext *ctx, GLframebuffer *buffer, GLuint bufferBit ){ return;}static voiddelete_renderbuffer( struct gl_renderbuffer *render ){ return;}static GLbooleanrenderbuffer_storage( GLcontext *ctx, struct gl_renderbuffer *render, GLenum internalFormat, GLuint width, GLuint height ){ return GL_TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -