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

📄 svgamesa.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Id: svgamesa.c,v 1.27 2006/10/15 18:51:22 brianp Exp $ *//* * Mesa 3-D graphics library * Version:  5.0 * Copyright (C) 1995-2002  Brian Paul * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//* * SVGA driver for Mesa. * Original author:  Brian Paul * Additional authors:  Slawomir Szczyrba <steev@hot.pl>  (Mesa 3.2) */#ifdef HAVE_CONFIG_H#include "conf.h"#endif#ifdef SVGA#include <stdio.h>#include <stdlib.h>#include <string.h>#include <vga.h>#include "GL/svgamesa.h"#include "buffers.h"#include "context.h"#include "extensions.h"#include "imports.h"#include "matrix.h"#include "mtypes.h"#include "swrast/swrast.h"#include "svgapix.h"#include "svgamesa8.h"#include "svgamesa15.h"#include "svgamesa16.h"#include "svgamesa24.h"#include "svgamesa32.h"struct svga_buffer SVGABuffer;vga_modeinfo * SVGAInfo;SVGAMesaContext SVGAMesa;    /* the current context */#ifdef SVGA_DEBUG#include <sys/types.h>#include <signal.h>FILE * logfile;char cbuf[1024]={0};void SVGAlog(char * what){ logfile=fopen("svgamesa.log","a"); if (!logfile) return; fprintf(logfile,"%s\n",what); fclose(logfile);}#endif/**********************************************************************//*****                       Init stuff...                        *****//**********************************************************************/int SVGAMesaInit( int GraphMode ){   vga_init();   if (!vga_hasmode(GraphMode))   {    fprintf(stderr,"GraphMode %d unavailable...",GraphMode);#ifdef SVGA_DEBUG    SVGAlog("SVGAMesaInit: invalid GraphMode (doesn't exist)");#endif    return(1);   }   SVGAInfo=vga_getmodeinfo(GraphMode);   if (SVGAInfo->flags & IS_MODEX)   {    fprintf(stderr,"ModeX not implemented...");#ifdef SVGA_DEBUG    SVGAlog("SVGAMesaInit: invalid GraphMode (ModeX)");#endif    return(2);   }   if (!SVGAInfo->bytesperpixel)   {    fprintf(stderr,"1 / 4 bit color not implemented...");#ifdef SVGA_DEBUG    SVGAlog("SVGAMesaInit: invalid GraphMode (1 or 4 bit)");#endif    return(3);   }   switch (SVGAInfo->colors) {    case   256: SVGABuffer.Depth = 8;  break;    case 32768: SVGABuffer.Depth = 15; break;    case 65536: SVGABuffer.Depth = 16; break;    default: SVGABuffer.Depth = SVGAInfo->bytesperpixel<<3; break;   }   SVGABuffer.BufferSize=SVGAInfo->linewidth*SVGAInfo->height;#ifdef SVGA_DEBUG   sprintf(cbuf,"SVGAMesaInit: double buffer info.\n" \                 "              depth  : %d\n" \                 "              mode   : %d\n" \		 "              width  : %d\n" \		 "              height : %d\n" \		 "              bufsize: %d\n", \		 SVGABuffer.Depth,GraphMode,SVGAInfo->linewidth, \		 SVGAInfo->height,SVGABuffer.BufferSize);   SVGAlog(cbuf);#endif   SVGABuffer.FrontBuffer=(void*)malloc(SVGABuffer.BufferSize + 4);   if (!SVGABuffer.FrontBuffer) {    {     fprintf(stderr,"Not enough RAM for FRONT_LEFT_BUFFER...");#ifdef SVGA_DEBUG     SVGAlog("SVGAMesaInit: Not enough RAM (front buffer)");#endif     return(4);    }   }#ifdef SVGA_DEBUG   sprintf(cbuf,"SVGAMesaInit: FrontBuffer - %p",SVGABuffer.FrontBuffer);   SVGAlog(cbuf);#endif   SVGABuffer.BackBuffer=(void*)malloc(SVGABuffer.BufferSize + 4);   if (!SVGABuffer.BackBuffer) {    {     free(SVGABuffer.FrontBuffer);     fprintf(stderr,"Not enough RAM for BACK_LEFT_BUFFER...");#ifdef SVGA_DEBUG     SVGAlog("SVGAMesaInit: Not enough RAM (back buffer)");#endif     return(5);    }   }#ifdef SVGA_DEBUG   sprintf(cbuf,"SVGAMesaInit: BackBuffer - %p",SVGABuffer.BackBuffer);   SVGAlog(cbuf);#endif   vga_setmode(GraphMode);   SVGABuffer.VideoRam=vga_getgraphmem();#ifdef SVGA_DEBUG   sprintf(cbuf,"SVGAMesaInit: VRAM - %p",SVGABuffer.VideoRam);   SVGAlog(cbuf);   sprintf(cbuf,"SVGAMesaInit: done. (Mode %d)",GraphMode);   SVGAlog(cbuf);#endif   SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;   SVGABuffer.ReadBuffer = SVGABuffer.BackBuffer;   return 0;}int SVGAMesaClose( void ){   vga_setmode(TEXT);   free(SVGABuffer.FrontBuffer);   free(SVGABuffer.BackBuffer);   return 0;}void SVGAMesaSetCI(int ndx, GLubyte red, GLubyte green, GLubyte blue){   if (ndx<256)      vga_setpalette(ndx, red>>2, green>>2, blue>>2);}/**********************************************************************//*****                 Miscellaneous functions                    *****//**********************************************************************/static void copy_buffer( const GLubyte * buffer) { int size = SVGABuffer.BufferSize, page = 0;#ifdef SVGA_DEBUG   sprintf(cbuf,"copy_buffer: copy %p to %p",buffer,SVGABuffer.VideoRam);   SVGAlog(cbuf);#endif while(size>0) { vga_setpage(page++);  if (size>>16) {   memcpy(SVGABuffer.VideoRam,buffer,0x10000);   buffer+=0x10000;  }else{   memcpy(SVGABuffer.VideoRam,buffer,size & 0xffff);  }  size-=0xffff; }}static void get_buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height ){   *width = SVGAMesa->width = vga_getxdim();   *height = SVGAMesa->height = vga_getydim();}/** * We only implement this function as a mechanism to check if the * framebuffer size has changed (and update corresponding state). */static void viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h){   GLuint newWidth, newHeight;   GLframebuffer *buffer = ctx->WinSysDrawBuffer;   get_buffer_size( buffer, &newWidth, &newHeight );   if (buffer->Width != newWidth || buffer->Height != newHeight) {      _mesa_resize_framebuffer(ctx, buffer, newWidth, newHeight );   }}static void set_buffer( GLcontext *ctx, GLframebuffer *colorBuffer,                        GLenum buffer ){   /* We can ignore colorBuffer since we don't support a MakeCurrentRead()    * function.    */   (void) colorBuffer;   if (buffer == GL_FRONT_LEFT) {      SVGABuffer.ReadBuffer = SVGABuffer.FrontBuffer;      SVGABuffer.DrawBuffer = SVGABuffer.FrontBuffer;#if 0      void * tmpptr;      /*    vga_waitretrace(); */      copy_buffer(SVGABuffer.FrontBuffer);      tmpptr=SVGABuffer.BackBuffer;      SVGABuffer.BackBuffer=SVGABuffer.FrontBuffer;      SVGABuffer.FrontBuffer=tmpptr;#endif   }   else if (buffer == GL_BACK_LEFT) {      SVGABuffer.ReadBuffer = SVGABuffer.BackBuffer;      SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;#if 0      /*    vga_waitretrace(); */      copy_buffer(SVGABuffer.BackBuffer);#endif   }}

⌨️ 快捷键说明

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