📄 osmesa.c
字号:
/* * Mesa 3-D graphics library * Version: 6.5.3 * * Copyright (C) 1999-2007 Brian Paul 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, sublicense, * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL * BRIAN PAUL 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. *//* * Off-Screen Mesa rendering / Rendering into client memory space * * Note on thread safety: this driver is thread safe. All * functions are reentrant. The notion of current context is * managed by the core _mesa_make_current() and _mesa_get_current_context() * functions. Those functions are thread-safe. */#include "main/glheader.h"#include "GL/osmesa.h"#include "main/context.h"#include "main/extensions.h"#include "main/framebuffer.h"#include "main/imports.h"#include "main/mtypes.h"#include "main/renderbuffer.h"#include "swrast/swrast.h"#include "swrast_setup/swrast_setup.h"#include "swrast/s_context.h"#include "swrast/s_lines.h"#include "swrast/s_triangle.h"#include "tnl/tnl.h"#include "tnl/t_context.h"#include "tnl/t_pipeline.h"#include "drivers/common/driverfuncs.h"#include "vbo/vbo.h"/** * OSMesa rendering context, derived from core Mesa GLcontext. */struct osmesa_context{ GLcontext mesa; /*< Base class - this must be first */ GLvisual *gl_visual; /*< Describes the buffers */ struct gl_renderbuffer *rb; /*< The user's colorbuffer */ GLframebuffer *gl_buffer; /*< The framebuffer, containing user's rb */ GLenum format; /*< User-specified context format */ GLint userRowLength; /*< user-specified number of pixels per row */ GLint rInd, gInd, bInd, aInd;/*< index offsets for RGBA formats */ GLvoid *rowaddr[MAX_HEIGHT]; /*< address of first pixel in each image row */ GLboolean yup; /*< TRUE -> Y increases upward */ /*< FALSE -> Y increases downward */};static INLINE OSMesaContextOSMESA_CONTEXT(GLcontext *ctx){ /* Just cast, since we're using structure containment */ return (OSMesaContext) ctx;}/**********************************************************************//*** Private Device Driver Functions ***//**********************************************************************/static const GLubyte *get_string( GLcontext *ctx, GLenum name ){ (void) ctx; switch (name) { case GL_RENDERER:#if CHAN_BITS == 32 return (const GLubyte *) "Mesa OffScreen32";#elif CHAN_BITS == 16 return (const GLubyte *) "Mesa OffScreen16";#else return (const GLubyte *) "Mesa OffScreen";#endif default: return NULL; }}static voidosmesa_update_state( GLcontext *ctx, GLuint new_state ){ /* easy - just propogate */ _swrast_InvalidateState( ctx, new_state ); _swsetup_InvalidateState( ctx, new_state ); _tnl_InvalidateState( ctx, new_state ); _vbo_InvalidateState( ctx, new_state );}/**********************************************************************//***** Read/write spans/arrays of pixels *****//**********************************************************************//* 8-bit RGBA */#define NAME(PREFIX) PREFIX##_RGBA8#define RB_TYPE GLubyte#define SPAN_VARS \ const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);#define INIT_PIXEL_PTR(P, X, Y) \ GLubyte *P = (GLubyte *) osmesa->rowaddr[Y] + 4 * (X)#define INC_PIXEL_PTR(P) P += 4#define STORE_PIXEL(DST, X, Y, VALUE) \ DST[0] = VALUE[RCOMP]; \ DST[1] = VALUE[GCOMP]; \ DST[2] = VALUE[BCOMP]; \ DST[3] = VALUE[ACOMP]#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \ DST[0] = VALUE[RCOMP]; \ DST[1] = VALUE[GCOMP]; \ DST[2] = VALUE[BCOMP]; \ DST[3] = 255#define FETCH_PIXEL(DST, SRC) \ DST[RCOMP] = SRC[0]; \ DST[GCOMP] = SRC[1]; \ DST[BCOMP] = SRC[2]; \ DST[ACOMP] = SRC[3]#include "swrast/s_spantemp.h"/* 16-bit RGBA */#define NAME(PREFIX) PREFIX##_RGBA16#define RB_TYPE GLushort#define SPAN_VARS \ const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);#define INIT_PIXEL_PTR(P, X, Y) \ GLushort *P = (GLushort *) osmesa->rowaddr[Y] + 4 * (X)#define INC_PIXEL_PTR(P) P += 4#define STORE_PIXEL(DST, X, Y, VALUE) \ DST[0] = VALUE[RCOMP]; \ DST[1] = VALUE[GCOMP]; \ DST[2] = VALUE[BCOMP]; \ DST[3] = VALUE[ACOMP]#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \ DST[0] = VALUE[RCOMP]; \ DST[1] = VALUE[GCOMP]; \ DST[2] = VALUE[BCOMP]; \ DST[3] = 65535#define FETCH_PIXEL(DST, SRC) \ DST[RCOMP] = SRC[0]; \ DST[GCOMP] = SRC[1]; \ DST[BCOMP] = SRC[2]; \ DST[ACOMP] = SRC[3]#include "swrast/s_spantemp.h"/* 32-bit RGBA */#define NAME(PREFIX) PREFIX##_RGBA32#define RB_TYPE GLfloat#define SPAN_VARS \ const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);#define INIT_PIXEL_PTR(P, X, Y) \ GLfloat *P = (GLfloat *) osmesa->rowaddr[Y] + 4 * (X)#define INC_PIXEL_PTR(P) P += 4#define STORE_PIXEL(DST, X, Y, VALUE) \ DST[0] = MAX2((VALUE[RCOMP]), 0.0F); \ DST[1] = MAX2((VALUE[GCOMP]), 0.0F); \ DST[2] = MAX2((VALUE[BCOMP]), 0.0F); \ DST[3] = CLAMP((VALUE[ACOMP]), 0.0F, 1.0F)#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \ DST[0] = MAX2((VALUE[RCOMP]), 0.0F); \ DST[1] = MAX2((VALUE[GCOMP]), 0.0F); \ DST[2] = MAX2((VALUE[BCOMP]), 0.0F); \ DST[3] = 1.0F#define FETCH_PIXEL(DST, SRC) \ DST[RCOMP] = SRC[0]; \ DST[GCOMP] = SRC[1]; \ DST[BCOMP] = SRC[2]; \ DST[ACOMP] = SRC[3]#include "swrast/s_spantemp.h"/* 8-bit BGRA */#define NAME(PREFIX) PREFIX##_BGRA8#define RB_TYPE GLubyte#define SPAN_VARS \ const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);#define INIT_PIXEL_PTR(P, X, Y) \ GLubyte *P = (GLubyte *) osmesa->rowaddr[Y] + 4 * (X)#define INC_PIXEL_PTR(P) P += 4#define STORE_PIXEL(DST, X, Y, VALUE) \ DST[2] = VALUE[RCOMP]; \ DST[1] = VALUE[GCOMP]; \ DST[0] = VALUE[BCOMP]; \ DST[3] = VALUE[ACOMP]#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \ DST[2] = VALUE[RCOMP]; \ DST[1] = VALUE[GCOMP]; \ DST[0] = VALUE[BCOMP]; \ DST[3] = 255#define FETCH_PIXEL(DST, SRC) \ DST[RCOMP] = SRC[2]; \ DST[GCOMP] = SRC[1]; \ DST[BCOMP] = SRC[0]; \ DST[ACOMP] = SRC[3]#include "swrast/s_spantemp.h"/* 16-bit BGRA */#define NAME(PREFIX) PREFIX##_BGRA16#define RB_TYPE GLushort#define SPAN_VARS \ const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);#define INIT_PIXEL_PTR(P, X, Y) \ GLushort *P = (GLushort *) osmesa->rowaddr[Y] + 4 * (X)#define INC_PIXEL_PTR(P) P += 4#define STORE_PIXEL(DST, X, Y, VALUE) \ DST[2] = VALUE[RCOMP]; \ DST[1] = VALUE[GCOMP]; \ DST[0] = VALUE[BCOMP]; \ DST[3] = VALUE[ACOMP]#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \ DST[2] = VALUE[RCOMP]; \ DST[1] = VALUE[GCOMP]; \ DST[0] = VALUE[BCOMP]; \ DST[3] = 65535#define FETCH_PIXEL(DST, SRC) \ DST[RCOMP] = SRC[2]; \ DST[GCOMP] = SRC[1]; \ DST[BCOMP] = SRC[0]; \ DST[ACOMP] = SRC[3]#include "swrast/s_spantemp.h"/* 32-bit BGRA */#define NAME(PREFIX) PREFIX##_BGRA32#define RB_TYPE GLfloat#define SPAN_VARS \ const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);#define INIT_PIXEL_PTR(P, X, Y) \ GLfloat *P = (GLfloat *) osmesa->rowaddr[Y] + 4 * (X)#define INC_PIXEL_PTR(P) P += 4#define STORE_PIXEL(DST, X, Y, VALUE) \ DST[2] = VALUE[RCOMP]; \ DST[1] = VALUE[GCOMP]; \ DST[0] = VALUE[BCOMP]; \ DST[3] = VALUE[ACOMP]#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \ DST[2] = VALUE[RCOMP]; \ DST[1] = VALUE[GCOMP]; \ DST[0] = VALUE[BCOMP]; \ DST[3] = 1.0F#define FETCH_PIXEL(DST, SRC) \ DST[RCOMP] = SRC[2]; \ DST[GCOMP] = SRC[1]; \ DST[BCOMP] = SRC[0]; \ DST[ACOMP] = SRC[3]#include "swrast/s_spantemp.h"/* 8-bit ARGB */#define NAME(PREFIX) PREFIX##_ARGB8#define RB_TYPE GLubyte#define SPAN_VARS \ const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);#define INIT_PIXEL_PTR(P, X, Y) \ GLubyte *P = (GLubyte *) osmesa->rowaddr[Y] + 4 * (X)#define INC_PIXEL_PTR(P) P += 4#define STORE_PIXEL(DST, X, Y, VALUE) \ DST[1] = VALUE[RCOMP]; \ DST[2] = VALUE[GCOMP]; \ DST[3] = VALUE[BCOMP]; \ DST[0] = VALUE[ACOMP]#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \ DST[1] = VALUE[RCOMP]; \ DST[2] = VALUE[GCOMP]; \ DST[3] = VALUE[BCOMP]; \ DST[0] = 255#define FETCH_PIXEL(DST, SRC) \ DST[RCOMP] = SRC[1]; \ DST[GCOMP] = SRC[2]; \ DST[BCOMP] = SRC[3]; \ DST[ACOMP] = SRC[0]#include "swrast/s_spantemp.h"/* 16-bit ARGB */#define NAME(PREFIX) PREFIX##_ARGB16#define RB_TYPE GLushort#define SPAN_VARS \ const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);#define INIT_PIXEL_PTR(P, X, Y) \ GLushort *P = (GLushort *) osmesa->rowaddr[Y] + 4 * (X)#define INC_PIXEL_PTR(P) P += 4#define STORE_PIXEL(DST, X, Y, VALUE) \ DST[1] = VALUE[RCOMP]; \ DST[2] = VALUE[GCOMP]; \ DST[3] = VALUE[BCOMP]; \ DST[0] = VALUE[ACOMP]#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \ DST[1] = VALUE[RCOMP]; \ DST[2] = VALUE[GCOMP]; \ DST[3] = VALUE[BCOMP]; \ DST[0] = 65535#define FETCH_PIXEL(DST, SRC) \ DST[RCOMP] = SRC[1]; \ DST[GCOMP] = SRC[2]; \ DST[BCOMP] = SRC[3]; \ DST[ACOMP] = SRC[0]#include "swrast/s_spantemp.h"/* 32-bit ARGB */#define NAME(PREFIX) PREFIX##_ARGB32#define RB_TYPE GLfloat#define SPAN_VARS \ const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);#define INIT_PIXEL_PTR(P, X, Y) \ GLfloat *P = (GLfloat *) osmesa->rowaddr[Y] + 4 * (X)#define INC_PIXEL_PTR(P) P += 4#define STORE_PIXEL(DST, X, Y, VALUE) \ DST[1] = VALUE[RCOMP]; \ DST[2] = VALUE[GCOMP]; \ DST[3] = VALUE[BCOMP]; \ DST[0] = VALUE[ACOMP]#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \ DST[1] = VALUE[RCOMP]; \ DST[2] = VALUE[GCOMP]; \ DST[3] = VALUE[BCOMP]; \ DST[0] = 1.0F#define FETCH_PIXEL(DST, SRC) \ DST[RCOMP] = SRC[1]; \ DST[GCOMP] = SRC[2]; \ DST[BCOMP] = SRC[3]; \ DST[ACOMP] = SRC[0]#include "swrast/s_spantemp.h"/* 8-bit RGB */#define NAME(PREFIX) PREFIX##_RGB8#define RB_TYPE GLubyte#define SPAN_VARS \ const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);#define INIT_PIXEL_PTR(P, X, Y) \ GLubyte *P = (GLubyte *) osmesa->rowaddr[Y] + 3 * (X)#define INC_PIXEL_PTR(P) P += 3#define STORE_PIXEL(DST, X, Y, VALUE) \ DST[0] = VALUE[RCOMP]; \ DST[1] = VALUE[GCOMP]; \ DST[2] = VALUE[BCOMP]#define FETCH_PIXEL(DST, SRC) \ DST[RCOMP] = SRC[0]; \ DST[GCOMP] = SRC[1]; \ DST[BCOMP] = SRC[2]; \ DST[ACOMP] = 255#include "swrast/s_spantemp.h"/* 16-bit RGB */#define NAME(PREFIX) PREFIX##_RGB16#define RB_TYPE GLushort#define SPAN_VARS \ const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);#define INIT_PIXEL_PTR(P, X, Y) \ GLushort *P = (GLushort *) osmesa->rowaddr[Y] + 3 * (X)#define INC_PIXEL_PTR(P) P += 3#define STORE_PIXEL(DST, X, Y, VALUE) \ DST[0] = VALUE[RCOMP]; \ DST[1] = VALUE[GCOMP]; \ DST[2] = VALUE[BCOMP]#define FETCH_PIXEL(DST, SRC) \ DST[RCOMP] = SRC[0]; \ DST[GCOMP] = SRC[1]; \ DST[BCOMP] = SRC[2]; \ DST[ACOMP] = 65535U#include "swrast/s_spantemp.h"/* 32-bit RGB */#define NAME(PREFIX) PREFIX##_RGB32#define RB_TYPE GLfloat#define SPAN_VARS \ const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);#define INIT_PIXEL_PTR(P, X, Y) \ GLfloat *P = (GLfloat *) osmesa->rowaddr[Y] + 3 * (X)#define INC_PIXEL_PTR(P) P += 3#define STORE_PIXEL(DST, X, Y, VALUE) \ DST[0] = VALUE[RCOMP]; \ DST[1] = VALUE[GCOMP]; \ DST[2] = VALUE[BCOMP]#define FETCH_PIXEL(DST, SRC) \ DST[RCOMP] = SRC[0]; \ DST[GCOMP] = SRC[1]; \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -