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

📄 ggimesa.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 2 页
字号:
/* GGI-Driver for MESA *  * Copyright (C) 1997-1998  Uwe Maurer  -  uwe_maurer@t-online.de  *                    2002  Filip Spacek * * 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. * --------------------------------------------------------------------- * This code was derived from the following source of information: * * svgamesa.c and ddsample.c by Brian Paul *  */#ifdef HAVE_CONFIG_H#include "conf.h"#endif#include <ggi/mesa/ggimesa_int.h>#include <ggi/mesa/debug.h>#include "extensions.h"#include "buffers.h"#include "colormac.h"#include "imports.h"#include "matrix.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 "vbo/vbo.h"#include "teximage.h"#include "texformat.h"#include "texstore.h"/* We use LibGG to manage config files */#include <ggi/gg.h>/* XXX: Those #defines should be provided via  * config.h */#define GGIMESAPATHTAG	"pAtHTAg"#define GGIMESACONFDIR	"pAtHTAg/usr/local/etc/ggi"#define GGIMESATAGLEN	7#define GGIMESACONFFILE	"ggimesa.conf"/* Static variables */static int _ggimesaLibIsUp = 0;static void *_ggimesaConfigHandle;static char _ggimesaconfstub[512] = GGIMESACONFDIR;static char *_ggimesaconfdir = _ggimesaconfstub+GGIMESATAGLEN;int _ggimesaDebugSync = 0;uint32 _ggimesaDebugState = 0;/* Extension ID. Defaulting to -1 should make segfault on abuse more likely... */ggi_extid _ggiMesaID = -1;#define SUBLIB_PREFIX	"MesaGGIdl_"/* * Returns the directory where global config files are kept */ const char *ggiMesaGetConfDir(void){#ifdef __WIN32__	/* On Win32 we allow overriding of the compiled in path. */	const char *envdir = getenv("GGI_CONFDIR");	if (envdir) return envdir;#endif	return _ggimesaconfdir;}/* Dummy function which returns -1   We use this to reset the function pointers */static int _ggi_error(void){	GGIMESADPRINT_CORE("_ggi_error() called\n");		return -1;}static int changed(ggi_visual_t vis, int whatchanged){	GLcontext *ctx;	ctx = _mesa_get_current_context();	GGIMESADPRINT_CORE("changed() called\n");			switch (whatchanged) {	case GGI_CHG_APILIST:	{		char api[GGI_MAX_APILEN];		char args[GGI_MAX_APILEN];		int i;		const char *fname;		ggi_dlhandle *lib;		GLvisual *gl_vis = &(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual);		GLframebuffer *gl_fb = &(LIBGGI_MESAEXT(vis)->mesa_buffer);				/* Initialize the framebuffer to provide all necessary		   buffers in software. The target libraries that are loaded		   next are free to modify this according to their		   capabilities. 		 */		 /* FIXME: if the target changes capabilities we'll leak 		    swrast's memory !!! Need to deallocate first */		_mesa_initialize_framebuffer(gl_fb, gl_vis,					 gl_vis->depthBits > 0,					 gl_vis->stencilBits > 0,					 gl_vis->accumRedBits > 0,					 gl_vis->alphaBits > 0);		for (i = 0; ggiGetAPI(vis, i, api, args) == 0; i++) {			strcat(api, "-mesa");			GGIMESADPRINT_CORE("GGIMesa: looking for"					"a sublib named %s\n", api);			fname = ggMatchConfig(_ggimesaConfigHandle, api, NULL);			if (fname == NULL) {				/* No special implementation for this sublib */				continue;			}			lib = ggiExtensionLoadDL(vis, fname, args, NULL,						 SUBLIB_PREFIX);		}		/* The targets have cleared everything they can do from 		   the framebuffer structure so we provide the rest in sw		 */		/*_swrast_alloc_buffers(gl_fb);*/				break;	} 	}	return 0;}int ggiMesaInit(){	int err;	char *str;	char *conffile;		GGIMESADPRINT_CORE("ggiMesaInit() called\n");		_ggimesaLibIsUp++;	if (_ggimesaLibIsUp > 1) return 0; /* Initialize only at first call */		str = getenv("GGIMESA_DEBUGSYNC");	if (str != NULL) {		_ggimesaDebugSync = 1;	}		str = getenv("GGIMESA_DEBUG");	if (str != NULL) {		_ggimesaDebugState = atoi(str);		GGIMESADPRINT_CORE("%s Debugging=%d\n",			_ggimesaDebugSync ? "sync" : "async",			_ggimesaDebugState);	}		conffile = malloc(strlen(ggiMesaGetConfDir()) + 1			  + strlen(GGIMESACONFFILE) +1);	if (conffile == NULL) {		fprintf(stderr, "GGIMesa: unable to allocate memory for config filename.\n");		return GGI_ENOMEM;	}	sprintf(conffile, "%s%c%s",		ggiMesaGetConfDir(), '/', GGIMESACONFFILE);	err = ggLoadConfig(conffile, &_ggimesaConfigHandle);	if (err != GGI_OK) {		fprintf(stderr, "GGIMesa: Couldn't open %s\n",			conffile);		free(conffile);		_ggimesaLibIsUp--;		return err;	}	free(conffile);		_ggiMesaID = ggiExtensionRegister("GGIMesa",					 sizeof(struct ggi_mesa_ext), changed);	if (_ggiMesaID < 0) {		fprintf(stderr, "GGIMesa: failed to register as extension\n");		_ggimesaLibIsUp--;		ggFreeConfig(_ggimesaConfigHandle);		return _ggiMesaID;	}		return 0;}int ggiMesaExit(void){	int rc;	GGIMESADPRINT_CORE("ggiMesaExit() called\n");	if (!_ggimesaLibIsUp) return -1;	if (_ggimesaLibIsUp > 1) {		/* Exit only at last call */		_ggimesaLibIsUp--;		return 0;	}		rc = ggiExtensionUnregister(_ggiMesaID);	ggFreeConfig(_ggimesaConfigHandle);	_ggimesaLibIsUp = 0;	return rc;}static void gl_ggiUpdateState(GLcontext *ctx, GLuint new_state);static void gl_ggiGetSize(GLframebuffer *fb, GLuint *width, GLuint *height){	/* FIXME: this is a hack to work around the new interface */	GLcontext *ctx;	ggi_mesa_context_t ggi_ctx;	ctx = _mesa_get_current_context();	ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;		GGIMESADPRINT_CORE("gl_ggiGetSize() called\n");		*width = LIBGGI_VIRTX(ggi_ctx->ggi_visual);	*height = LIBGGI_VIRTY(ggi_ctx->ggi_visual);	printf("returning %d, %d\n", *width, *height);}/** * We only implement this function as a mechanism to check if the * framebuffer size has changed (and update corresponding state). */static void gl_ggiViewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h){   GLuint newWidth, newHeight;   GLframebuffer *buffer = ctx->WinSysDrawBuffer;   gl_ggiGetSize( buffer, &newWidth, &newHeight );   if (buffer->Width != newWidth || buffer->Height != newHeight) {      _mesa_resize_framebuffer(ctx, buffer, newWidth, newHeight );   }}static void gl_ggiSetIndex(GLcontext *ctx, GLuint ci){	ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;		GGIMESADPRINT_CORE("gl_ggiSetIndex() called\n");		ggiSetGCForeground(ggi_ctx->ggi_visual, ci);	ggi_ctx->color = (ggi_pixel)ci;}static void gl_ggiSetClearIndex(GLcontext *ctx, GLuint ci){		ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;	GGIMESADPRINT_CORE("gl_ggiSetClearIndex() called\n");	ggiSetGCForeground(ggi_ctx->ggi_visual, ci);	ggi_ctx->clearcolor = (ggi_pixel)ci;}static void gl_ggiSetClearColor(GLcontext *ctx, const GLfloat color[4]){	ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;	ggi_color rgb;	ggi_pixel col;	GLubyte byteColor[3];	GGIMESADPRINT_CORE("gl_ggiSetClearColor() called\n");		CLAMPED_FLOAT_TO_UBYTE(byteColor[0], color[0]);	CLAMPED_FLOAT_TO_UBYTE(byteColor[1], color[1]);	CLAMPED_FLOAT_TO_UBYTE(byteColor[2], color[2]);	rgb.r = (uint16)byteColor[0] << SHIFT;	rgb.g = (uint16)byteColor[1] << SHIFT;	rgb.b = (uint16)byteColor[2] << SHIFT;	col = ggiMapColor(ggi_ctx->ggi_visual, &rgb);	ggiSetGCForeground(ggi_ctx->ggi_visual, col);	ggi_ctx->clearcolor = col;}static void gl_ggiClear(GLcontext *ctx, GLbitfield mask){	ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;        int x = ctx->DrawBuffer->_Xmin;        int y = ctx->DrawBuffer->_Ymin;        int w = ctx->DrawBuffer->_Xmax - x;        int h = ctx->DrawBuffer->_Ymax - y;        GLboolean all = (w == ctx->DrawBuffer->Width && h == ctx->DrawBuffer->height)		GGIMESADPRINT_CORE("gl_ggiClear() called\n");	if (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)) {		ggiSetGCForeground(ggi_ctx->ggi_visual, ggi_ctx->clearcolor);		if (all) {			int w, h;			w = LIBGGI_VIRTX(ggi_ctx->ggi_visual);			h = LIBGGI_VIRTX(ggi_ctx->ggi_visual);			ggiDrawBox(ggi_ctx->ggi_visual, 0, 0, w, h);		} else {			ggiDrawBox(ggi_ctx->ggi_visual, x, y, //FLIP(y),

⌨️ 快捷键说明

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