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

📄 glview.cpp

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/* * Mesa 3-D graphics library * Version:  6.1 *  * Copyright (C) 1999-2004  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. */#include <assert.h>#include <stdio.h>extern "C" {#include "glheader.h"#include "version.h"#include "buffers.h"#include "bufferobj.h"#include "context.h"#include "colormac.h"#include "depth.h"#include "extensions.h"#include "macros.h"#include "matrix.h"#include "mtypes.h"#include "texformat.h"#include "texobj.h"#include "teximage.h"#include "texstore.h"#include "vbo/vbo.h"#include "swrast/swrast.h"#include "swrast_setup/swrast_setup.h"#include "swrast/s_context.h"#include "swrast/s_depth.h"#include "swrast/s_lines.h"#include "swrast/s_triangle.h"#include "swrast/s_trispan.h"#include "tnl/tnl.h"#include "tnl/t_context.h"#include "tnl/t_pipeline.h"#include "drivers/common/driverfuncs.h"}	// extern "C"#include <interface/Screen.h>#include <GLView.h>// BeOS component ordering for B_RGBA32 bitmap format#if B_HOST_IS_LENDIAN	#define BE_RCOMP 2	#define BE_GCOMP 1	#define BE_BCOMP 0	#define BE_ACOMP 3	#define PACK_B_RGBA32(color) (color[BCOMP] | (color[GCOMP] << 8) | \							(color[RCOMP] << 16) | (color[ACOMP] << 24))	#define PACK_B_RGB32(color) (color[BCOMP] | (color[GCOMP] << 8) | \  							(color[RCOMP] << 16) | 0xFF000000)#else	// Big Endian B_RGBA32 bitmap format	#define BE_RCOMP 1	#define BE_GCOMP 2	#define BE_BCOMP 3	#define BE_ACOMP 0	#define PACK_B_RGBA32(color) (color[ACOMP] | (color[RCOMP] << 8) | \							(color[GCOMP] << 16) | (color[BCOMP] << 24))	#define PACK_B_RGB32(color) ((color[RCOMP] << 8) | (color[GCOMP] << 16) | \  							(color[BCOMP] << 24) | 0xFF000000)#endif#define FLIP(coord) (LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.y-(coord) - 1) const char * color_space_name(color_space space);//// This object hangs off of the BGLView object.  We have to use// Be's BGLView class as-is to maintain binary compatibility (we// can't add new members to it).  Instead we just put all our data// in this class and use BGLVIew::m_gc to point to it.//class MesaDriver{friend class BGLView;public:	MesaDriver();	~MesaDriver();		void 		Init(BGLView * bglview, GLcontext * c, GLvisual * v, GLframebuffer * b);	void 		LockGL();	void 		UnlockGL();	void 		SwapBuffers() const;	status_t 	CopyPixelsOut(BPoint source, BBitmap *dest);	status_t 	CopyPixelsIn(BBitmap *source, BPoint dest);	void CopySubBuffer(GLint x, GLint y, GLuint width, GLuint height) const;	void Draw(BRect updateRect) const;private:	MesaDriver(const MesaDriver &rhs);  // copy constructor illegal	MesaDriver &operator=(const MesaDriver &rhs);  // assignment oper. illegal	GLcontext * 	m_glcontext;	GLvisual * 		m_glvisual;	GLframebuffer *	m_glframebuffer;	BGLView *		m_bglview;	BBitmap *		m_bitmap;	GLchan 			m_clear_color[4];  // buffer clear color	GLuint 			m_clear_index;      // buffer clear color index	GLint 			m_bottom;           // used for flipping Y coords	GLuint 			m_width;	GLuint			m_height;	   // Mesa Device Driver callback functions   static void 		UpdateState(GLcontext *ctx, GLuint new_state);   static void 		ClearIndex(GLcontext *ctx, GLuint index);   static void 		ClearColor(GLcontext *ctx, const GLfloat color[4]);   static void 		Clear(GLcontext *ctx, GLbitfield mask,                                GLboolean all, GLint x, GLint y,                                GLint width, GLint height);   static void 		ClearFront(GLcontext *ctx, GLboolean all, GLint x, GLint y,                          GLint width, GLint height);   static void 		ClearBack(GLcontext *ctx, GLboolean all, GLint x, GLint y,                         GLint width, GLint height);   static void 		Index(GLcontext *ctx, GLuint index);   static void 		Color(GLcontext *ctx, GLubyte r, GLubyte g,                     GLubyte b, GLubyte a);   static void 		SetBuffer(GLcontext *ctx, GLframebuffer *colorBuffer,                             GLenum mode);   static void 		GetBufferSize(GLframebuffer * framebuffer, GLuint *width,                             GLuint *height);   static void		Error(GLcontext *ctx);   static const GLubyte *	GetString(GLcontext *ctx, GLenum name);   static void          Viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h);   // Front-buffer functions   static void 		WriteRGBASpanFront(const GLcontext *ctx, GLuint n,                                  GLint x, GLint y,                                  CONST GLubyte rgba[][4],                                  const GLubyte mask[]);   static void 		WriteRGBSpanFront(const GLcontext *ctx, GLuint n,                                 GLint x, GLint y,                                 CONST GLubyte rgba[][3],                                 const GLubyte mask[]);   static void 		WriteMonoRGBASpanFront(const GLcontext *ctx, GLuint n,                                      GLint x, GLint y,                                      const GLchan color[4],                                      const GLubyte mask[]);   static void 		WriteRGBAPixelsFront(const GLcontext *ctx, GLuint n,                                    const GLint x[], const GLint y[],                                    CONST GLubyte rgba[][4],                                    const GLubyte mask[]);   static void 		WriteMonoRGBAPixelsFront(const GLcontext *ctx, GLuint n,                                        const GLint x[], const GLint y[],                                        const GLchan color[4],                                        const GLubyte mask[]);   static void 		WriteCI32SpanFront(const GLcontext *ctx, GLuint n,                                  GLint x, GLint y,                                  const GLuint index[], const GLubyte mask[]);   static void 		WriteCI8SpanFront(const GLcontext *ctx, GLuint n,                                 GLint x, GLint y,                                 const GLubyte index[], const GLubyte mask[]);   static void 		WriteMonoCISpanFront(const GLcontext *ctx, GLuint n,                                    GLint x, GLint y,                                    GLuint colorIndex, const GLubyte mask[]);   static void 		WriteCI32PixelsFront(const GLcontext *ctx,                                    GLuint n, const GLint x[], const GLint y[],                                    const GLuint index[], const GLubyte mask[]);   static void 		WriteMonoCIPixelsFront(const GLcontext *ctx, GLuint n,                                      const GLint x[], const GLint y[],                                      GLuint colorIndex, const GLubyte mask[]);   static void 		ReadCI32SpanFront(const GLcontext *ctx,                                 GLuint n, GLint x, GLint y, GLuint index[]);   static void 		ReadRGBASpanFront(const GLcontext *ctx, GLuint n,                                 GLint x, GLint y,                                 GLubyte rgba[][4]);   static void 		ReadCI32PixelsFront(const GLcontext *ctx,                                   GLuint n, const GLint x[], const GLint y[],                                   GLuint indx[], const GLubyte mask[]);   static void 		ReadRGBAPixelsFront(const GLcontext *ctx,                                   GLuint n, const GLint x[], const GLint y[],                                   GLubyte rgba[][4], const GLubyte mask[]);   // Back buffer functions   static void 		WriteRGBASpanBack(const GLcontext *ctx, GLuint n,                                  GLint x, GLint y,                                  CONST GLubyte rgba[][4],                                  const GLubyte mask[]);   static void 		WriteRGBSpanBack(const GLcontext *ctx, GLuint n,                                 GLint x, GLint y,                                 CONST GLubyte rgba[][3],                                 const GLubyte mask[]);   static void 		WriteMonoRGBASpanBack(const GLcontext *ctx, GLuint n,                                     GLint x, GLint y,                                     const GLchan color[4],                                     const GLubyte mask[]);   static void 		WriteRGBAPixelsBack(const GLcontext *ctx, GLuint n,                                   const GLint x[], const GLint y[],                                   CONST GLubyte rgba[][4],                                   const GLubyte mask[]);   static void 		WriteMonoRGBAPixelsBack(const GLcontext *ctx, GLuint n,                                       const GLint x[], const GLint y[],                                       const GLchan color[4],                                       const GLubyte mask[]);   static void 		WriteCI32SpanBack(const GLcontext *ctx, GLuint n,                                 GLint x, GLint y,                                 const GLuint index[], const GLubyte mask[]);   static void 		WriteCI8SpanBack(const GLcontext *ctx, GLuint n, GLint x, GLint y,                                const GLubyte index[], const GLubyte mask[]);   static void 		WriteMonoCISpanBack(const GLcontext *ctx, GLuint n,                                   GLint x, GLint y, GLuint colorIndex,                                   const GLubyte mask[]);   static void 		WriteCI32PixelsBack(const GLcontext *ctx,                                   GLuint n, const GLint x[], const GLint y[],                                   const GLuint index[], const GLubyte mask[]);   static void 		WriteMonoCIPixelsBack(const GLcontext *ctx,                                     GLuint n, const GLint x[], const GLint y[],                                     GLuint colorIndex, const GLubyte mask[]);   static void 		ReadCI32SpanBack(const GLcontext *ctx,                                GLuint n, GLint x, GLint y, GLuint index[]);   static void 		ReadRGBASpanBack(const GLcontext *ctx, GLuint n,                                GLint x, GLint y,                                GLubyte rgba[][4]);   static void 		ReadCI32PixelsBack(const GLcontext *ctx,                                  GLuint n, const GLint x[], const GLint y[],                                  GLuint indx[], const GLubyte mask[]);   static void 		ReadRGBAPixelsBack(const GLcontext *ctx,                                  GLuint n, const GLint x[], const GLint y[],                                  GLubyte rgba[][4], const GLubyte mask[]);};//------------------------------------------------------------------// Public interface methods//------------------------------------------------------------------//// Input:  rect - initial rectangle//         name - window name//         resizingMode - example: B_FOLLOW_NONE//         mode - usually 0 ?//         options - Bitwise-OR of BGL_* tokens//BGLView::BGLView(BRect rect, char *name,                 ulong resizingMode, ulong mode,                 ulong options)   : BView(rect, name, B_FOLLOW_ALL_SIDES, mode | B_WILL_DRAW | B_FRAME_EVENTS) //  | B_FULL_UPDATE_ON_RESIZE){	// We don't support single buffering (yet): double buffering forced.	options |= BGL_DOUBLE;   const GLboolean rgbFlag = ((options & BGL_INDEX) == 0);   const GLboolean alphaFlag = ((options & BGL_ALPHA) == BGL_ALPHA);   const GLboolean dblFlag = ((options & BGL_DOUBLE) == BGL_DOUBLE);   const GLboolean stereoFlag = false;   const GLint depth = (options & BGL_DEPTH) ? 16 : 0;   const GLint stencil = (options & BGL_STENCIL) ? 8 : 0;   const GLint accum = (options & BGL_ACCUM) ? 16 : 0;   const GLint index = (options & BGL_INDEX) ? 32 : 0;   const GLint red = rgbFlag ? 8 : 0;   const GLint green = rgbFlag ? 8 : 0;   const GLint blue = rgbFlag ? 8 : 0;   const GLint alpha = alphaFlag ? 8 : 0;	m_options = options | BGL_INDIRECT;   struct dd_function_table functions;    if (!rgbFlag) {      fprintf(stderr, "Mesa Warning: color index mode not supported\n");   }   // Allocate auxiliary data object   MesaDriver * md = new MesaDriver();   // examine option flags and create gl_context struct   GLvisual * visual = _mesa_create_visual( rgbFlag,                                            dblFlag,                                            stereoFlag,                                            red, green, blue, alpha,                                            index,                                            depth,                                            stencil,                                            accum, accum, accum, accum,                                            1                                            );	// Initialize device driver function table	_mesa_init_driver_functions(&functions);	functions.GetString 	= md->GetString;	functions.UpdateState 	= md->UpdateState;	functions.GetBufferSize = md->GetBufferSize;	functions.Clear 		= md->Clear;	functions.ClearIndex 	= md->ClearIndex;	functions.ClearColor 	= md->ClearColor;	functions.Error			= md->Error;        functions.Viewport      = md->Viewport;	// create core context	GLcontext *ctx = _mesa_create_context(visual, NULL, &functions, md);	if (! ctx) {         _mesa_destroy_visual(visual);         delete md;         return;      }   _mesa_enable_sw_extensions(ctx);   _mesa_enable_1_3_extensions(ctx);   _mesa_enable_1_4_extensions(ctx);   _mesa_enable_1_5_extensions(ctx);   // create core framebuffer   GLframebuffer * buffer = _mesa_create_framebuffer(visual,                                              depth > 0 ? GL_TRUE : GL_FALSE,                                              stencil > 0 ? GL_TRUE: GL_FALSE,                                              accum > 0 ? GL_TRUE : GL_FALSE,                                              alphaFlag                                              );   /* Initialize the software rasterizer and helper modules.    */   _swrast_CreateContext(ctx);   _vbo_CreateContext(ctx);   _tnl_CreateContext(ctx);   _swsetup_CreateContext(ctx);   _swsetup_Wakeup(ctx);   md->Init(this, ctx, visual, buffer );   // Hook aux data into BGLView object   m_gc = md;   // some stupid applications (Quake2) don't even think about calling LockGL()   // before using glGetString and friends... so make sure there is at least a   // valid context.   if (!_mesa_get_current_context()) {      LockGL();      // not needed, we don't have a looper yet: UnlockLooper();   }}BGLView::~BGLView(){   // printf("BGLView destructor\n");   MesaDriver * md = (MesaDriver *) m_gc;   assert(md);   delete md;}void BGLView::LockGL(){   MesaDriver * md = (MesaDriver *) m_gc;   assert(md);   md->LockGL();}void BGLView::UnlockGL(){   MesaDriver * md = (MesaDriver *) m_gc;   assert(md);   md->UnlockGL();}void BGLView::SwapBuffers(){	SwapBuffers(false);}

⌨️ 快捷键说明

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