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

📄 osmesa.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 4 页
字号:
   DST[BCOMP] = SRC[2];  \   DST[ACOMP] = 1.0F#include "swrast/s_spantemp.h"/* 8-bit BGR */#define NAME(PREFIX) PREFIX##_BGR8#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[2] = VALUE[RCOMP];  \   DST[1] = VALUE[GCOMP];  \   DST[0] = VALUE[BCOMP]#define FETCH_PIXEL(DST, SRC) \   DST[RCOMP] = SRC[2];  \   DST[GCOMP] = SRC[1];  \   DST[BCOMP] = SRC[0];  \   DST[ACOMP] = 255#include "swrast/s_spantemp.h"/* 16-bit BGR */#define NAME(PREFIX) PREFIX##_BGR16#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[2] = VALUE[RCOMP];  \   DST[1] = VALUE[GCOMP];  \   DST[0] = VALUE[BCOMP]#define FETCH_PIXEL(DST, SRC) \   DST[RCOMP] = SRC[2];  \   DST[GCOMP] = SRC[1];  \   DST[BCOMP] = SRC[0];  \   DST[ACOMP] = 65535#include "swrast/s_spantemp.h"/* 32-bit BGR */#define NAME(PREFIX) PREFIX##_BGR32#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[2] = VALUE[RCOMP];  \   DST[1] = VALUE[GCOMP];  \   DST[0] = VALUE[BCOMP]#define FETCH_PIXEL(DST, SRC) \   DST[RCOMP] = SRC[2];  \   DST[GCOMP] = SRC[1];  \   DST[BCOMP] = SRC[0];  \   DST[ACOMP] = 1.0F#include "swrast/s_spantemp.h"/* 16-bit 5/6/5 RGB */#define NAME(PREFIX) PREFIX##_RGB_565#define RB_TYPE GLubyte#define SPAN_VARS \   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);#define INIT_PIXEL_PTR(P, X, Y) \   GLushort *P = (GLushort *) osmesa->rowaddr[Y] + (X)#define INC_PIXEL_PTR(P) P += 1#define STORE_PIXEL(DST, X, Y, VALUE) \   *DST = ( (((VALUE[RCOMP]) & 0xf8) << 8) | (((VALUE[GCOMP]) & 0xfc) << 3) | ((VALUE[BCOMP]) >> 3) )#define FETCH_PIXEL(DST, SRC) \   DST[RCOMP] = ( (((*SRC) >> 8) & 0xf8) | (((*SRC) >> 11) & 0x7) ); \   DST[GCOMP] = ( (((*SRC) >> 3) & 0xfc) | (((*SRC) >>  5) & 0x3) ); \   DST[BCOMP] = ( (((*SRC) << 3) & 0xf8) | (((*SRC)      ) & 0x7) ); \   DST[ACOMP] = CHAN_MAX#include "swrast/s_spantemp.h"/* color index */#define NAME(PREFIX) PREFIX##_CI#define CI_MODE#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] + (X)#define INC_PIXEL_PTR(P) P += 1#define STORE_PIXEL(DST, X, Y, VALUE) \   *DST = VALUE[0]#define FETCH_PIXEL(DST, SRC) \   DST = SRC[0]#include "swrast/s_spantemp.h"/** * Macros for optimized line/triangle rendering. * Only for 8-bit channel, RGBA, BGRA, ARGB formats. */#define PACK_RGBA(DST, R, G, B, A)	\do {					\   (DST)[osmesa->rInd] = R;		\   (DST)[osmesa->gInd] = G;		\   (DST)[osmesa->bInd] = B;		\   (DST)[osmesa->aInd] = A;		\} while (0)#define PIXELADDR4(X,Y)  ((GLchan *) osmesa->rowaddr[Y] + 4 * (X))/** * Draw a flat-shaded, RGB line into an osmesa buffer. */#define NAME flat_rgba_line#define CLIP_HACK 1#define SETUP_CODE						\   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);		\   const GLchan *color = vert1->color;#define PLOT(X, Y)						\do {								\   GLchan *p = PIXELADDR4(X, Y);				\   PACK_RGBA(p, color[0], color[1], color[2], color[3]);	\} while (0)#ifdef WIN32#include "..\swrast\s_linetemp.h"#else#include "swrast/s_linetemp.h"#endif/** * Draw a flat-shaded, Z-less, RGB line into an osmesa buffer. */#define NAME flat_rgba_z_line#define CLIP_HACK 1#define INTERP_Z 1#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE#define SETUP_CODE					\   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);	\   const GLchan *color = vert1->color;#define PLOT(X, Y)					\do {							\   if (Z < *zPtr) {					\      GLchan *p = PIXELADDR4(X, Y);			\      PACK_RGBA(p, color[RCOMP], color[GCOMP],		\                   color[BCOMP], color[ACOMP]);		\      *zPtr = Z;					\   }							\} while (0)#ifdef WIN32#include "..\swrast\s_linetemp.h"#else#include "swrast/s_linetemp.h"#endif/** * Analyze context state to see if we can provide a fast line drawing * function.  Otherwise, return NULL. */static swrast_line_funcosmesa_choose_line_function( GLcontext *ctx ){   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);   const SWcontext *swrast = SWRAST_CONTEXT(ctx);   if (osmesa->rb->DataType != GL_UNSIGNED_BYTE)      return NULL;   if (ctx->RenderMode != GL_RENDER)      return NULL;   if (ctx->Line.SmoothFlag)              return NULL;   if (ctx->Texture._EnabledUnits)        return NULL;   if (ctx->Light.ShadeModel != GL_FLAT)  return NULL;   if (ctx->Line.Width != 1.0F)           return NULL;   if (ctx->Line.StippleFlag)             return NULL;   if (ctx->Line.SmoothFlag)              return NULL;   if (osmesa->format != OSMESA_RGBA &&       osmesa->format != OSMESA_BGRA &&       osmesa->format != OSMESA_ARGB)     return NULL;   if (swrast->_RasterMask==DEPTH_BIT       && ctx->Depth.Func==GL_LESS       && ctx->Depth.Mask==GL_TRUE       && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS) {      return (swrast_line_func) flat_rgba_z_line;   }   if (swrast->_RasterMask == 0) {      return (swrast_line_func) flat_rgba_line;   }   return (swrast_line_func) NULL;}/**********************************************************************//*****                 Optimized triangle rendering               *****//**********************************************************************//* * Smooth-shaded, z-less triangle, RGBA color. */#define NAME smooth_rgba_z_triangle#define INTERP_Z 1#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE#define INTERP_RGB 1#define INTERP_ALPHA 1#define SETUP_CODE \   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);#define RENDER_SPAN( span ) {					\   GLuint i;							\   GLchan *img = PIXELADDR4(span.x, span.y); 			\   for (i = 0; i < span.end; i++, img += 4) {			\      const GLuint z = FixedToDepth(span.z);			\      if (z < zRow[i]) {					\         PACK_RGBA(img, FixedToChan(span.red),			\            FixedToChan(span.green), FixedToChan(span.blue),	\            FixedToChan(span.alpha));				\         zRow[i] = z;						\      }								\      span.red += span.redStep;					\      span.green += span.greenStep;				\      span.blue += span.blueStep;				\      span.alpha += span.alphaStep;				\      span.z += span.zStep;					\   }                                                            \}#ifdef WIN32#include "..\swrast\s_tritemp.h"#else#include "swrast/s_tritemp.h"#endif/* * Flat-shaded, z-less triangle, RGBA color. */#define NAME flat_rgba_z_triangle#define INTERP_Z 1#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE#define SETUP_CODE						\   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);		\   GLuint pixel;						\   PACK_RGBA((GLchan *) &pixel, v2->color[0], v2->color[1],	\                                v2->color[2], v2->color[3]);#define RENDER_SPAN( span ) {				\   GLuint i;						\   GLuint *img = (GLuint *) PIXELADDR4(span.x, span.y);	\   for (i = 0; i < span.end; i++) {			\      const GLuint z = FixedToDepth(span.z);		\      if (z < zRow[i]) {				\         img[i] = pixel;				\         zRow[i] = z;					\      }							\      span.z += span.zStep;				\   }                                                    \}#ifdef WIN32#include "..\swrast\s_tritemp.h"#else#include "swrast/s_tritemp.h"#endif/** * Return pointer to an optimized triangle function if possible. */static swrast_tri_funcosmesa_choose_triangle_function( GLcontext *ctx ){   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);   const SWcontext *swrast = SWRAST_CONTEXT(ctx);   if (osmesa->rb->DataType != GL_UNSIGNED_BYTE)      return (swrast_tri_func) NULL;   if (ctx->RenderMode != GL_RENDER)    return (swrast_tri_func) NULL;   if (ctx->Polygon.SmoothFlag)         return (swrast_tri_func) NULL;   if (ctx->Polygon.StippleFlag)        return (swrast_tri_func) NULL;   if (ctx->Texture._EnabledUnits)      return (swrast_tri_func) NULL;   if (osmesa->format != OSMESA_RGBA &&       osmesa->format != OSMESA_BGRA &&       osmesa->format != OSMESA_ARGB)   return (swrast_tri_func) NULL;   if (ctx->Polygon.CullFlag &&        ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)                                        return (swrast_tri_func) NULL;   if (swrast->_RasterMask == DEPTH_BIT &&       ctx->Depth.Func == GL_LESS &&       ctx->Depth.Mask == GL_TRUE &&       ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS) {      if (ctx->Light.ShadeModel == GL_SMOOTH) {         return (swrast_tri_func) smooth_rgba_z_triangle;      }      else {         return (swrast_tri_func) flat_rgba_z_triangle;      }   }   return (swrast_tri_func) NULL;}/* Override for the swrast triangle-selection function.  Try to use one * of our internal triangle functions, otherwise fall back to the * standard swrast functions. */static voidosmesa_choose_triangle( GLcontext *ctx ){   SWcontext *swrast = SWRAST_CONTEXT(ctx);   swrast->Triangle = osmesa_choose_triangle_function( ctx );   if (!swrast->Triangle)      _swrast_choose_triangle( ctx );}static voidosmesa_choose_line( GLcontext *ctx ){   SWcontext *swrast = SWRAST_CONTEXT(ctx);   swrast->Line = osmesa_choose_line_function( ctx );   if (!swrast->Line)      _swrast_choose_line( ctx );}/** * Recompute the values of the context's rowaddr array. */static voidcompute_row_addresses( OSMesaContext osmesa ){   GLint bytesPerPixel, bytesPerRow, i;   GLubyte *origin = (GLubyte *) osmesa->rb->Data;   GLint bpc; /* bytes per channel */   GLint rowlength; /* in pixels */   GLint height = osmesa->rb->Height;   if (osmesa->userRowLength)      rowlength = osmesa->userRowLength;   else      rowlength = osmesa->rb->Width;   if (osmesa->rb->DataType == GL_UNSIGNED_BYTE)      bpc = 1;   else if (osmesa->rb->DataType == GL_UNSIGNED_SHORT)      bpc = 2;   else if (osmesa->rb->DataType == GL_FLOAT)      bpc = 4;   else {      _mesa_problem(&osmesa->mesa,                    "Unexpected datatype in osmesa::compute_row_addresses");      return;   }   if (osmesa->format == OSMESA_COLOR_INDEX) {      /* CI mode */      bytesPerPixel = 1 * sizeof(GLubyte);   }   else if ((osmesa->format == OSMESA_RGB) || (osmesa->format == OSMESA_BGR)) {      /* RGB mode */      bytesPerPixel = 3 * bpc;   }   else if (osmesa->format == OSMESA_RGB_565) {      /* 5/6/5 RGB pixel in 16 bits */      bytesPerPixel = 2;   }   else {      /* RGBA mode */      bytesPerPixel = 4 * bpc;   }   bytesPerRow = rowlength * bytesPerPixel;   if (osmesa->yup) {      /* Y=0 is bottom line of window */      for (i = 0; i < height; i++) {         osmesa->rowaddr[i] = (GLvoid *) ((GLubyte *) origin + i * bytesPerRow);      }   }   else {      /* Y=0 is top line of window */      for (i = 0; i < height; i++) {         GLint j = height - i - 1;         osmesa->rowaddr[i] = (GLvoid *) ((GLubyte *) origin + j * bytesPerRow);

⌨️ 快捷键说明

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