void MesaDriver::GetBufferSize(GLframebuffer * framebuffer, GLuint *width, GLuint *height) { GET_CURRENT_CONTEXT(ctx); if (!ctx) return; MesaDriver * md = (MesaDriver *) ctx->DriverCtx; BGLView *bglview = md->m_bglview; assert(bglview); BRect b = bglview->Bounds(); *width = (GLuint) b.IntegerWidth() + 1; // (b.right - b.left + 1); *height = (GLuint) b.IntegerHeight() + 1; // (b.bottom - b.top + 1); md->m_bottom = (GLint) b.bottom; if (ctx->Visual.doubleBufferMode) { if (*width != md->m_width || *height != md->m_height) { // allocate new size of back buffer bitmap if (md->m_bitmap) delete md->m_bitmap; BRect rect(0.0, 0.0, *width - 1, *height - 1); md->m_bitmap = new BBitmap(rect, B_RGBA32); } } else { md->m_bitmap = NULL; } md->m_width = *width; md->m_height = *height; }
OpenGLView::OpenGLView() : BGroupView("OpenGLView", B_VERTICAL) { BGLView* glView = new BGLView(BRect(0, 0, 1, 1), "gl info", B_FOLLOW_NONE, 0, BGL_RGB | BGL_DOUBLE); glView->Hide(); AddChild(glView); glView->LockGL(); float tabViewWidth = this->StringWidth("M") * 42; float tabViewHeight = this->StringWidth("M") * 16; BTabView *tabView = new BTabView("tab view", B_WIDTH_FROM_LABEL); tabView->SetExplicitMinSize(BSize(tabViewWidth, tabViewHeight)); tabView->AddTab(new CapabilitiesView()); tabView->AddTab(new ExtensionsView()); glView->UnlockGL(); GroupLayout()->SetSpacing(0); BLayoutBuilder::Group<>(this) .AddGroup(B_HORIZONTAL, 0) .Add(new GearsView()) .AddGroup(B_VERTICAL, B_USE_DEFAULT_SPACING) .SetInsets(0, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .Add(new InfoView()) .Add(tabView) .End() .AddGlue() .End(); }
void MesaDriver::UnlockGL() { if (m_bglview->Looper()->IsLocked()) m_bglview->UnlockLooper(); // Could call _mesa_make_current(NULL, NULL) but it would just // hinder performance }
void MesaDriver::SwapBuffers() const { _mesa_notifySwapBuffers(m_glcontext); if (m_bitmap) { m_bglview->LockLooper(); m_bglview->DrawBitmap(m_bitmap); m_bglview->UnlockLooper(); }; }
void MesaDriver::LockGL() { m_bglview->LockLooper(); UpdateState(m_glcontext, 0); _mesa_make_current(m_glcontext, m_glframebuffer); }
OpenGLView::OpenGLView() : BGroupView("OpenGLView", B_VERTICAL) { BGLView* glView = new BGLView(BRect(0, 0, 1, 1), "gl info", B_FOLLOW_NONE, 0, BGL_RGB | BGL_DOUBLE); glView->Hide(); AddChild(glView); glView->LockGL(); BMenu* menu = new BMenu(B_TRANSLATE("Automatic")); menu->SetRadioMode(true); menu->SetLabelFromMarked(true); menu->AddItem(new BMenuItem(B_TRANSLATE("Automatic"), new BMessage(MENU_AUTO_MESSAGE))); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem(B_TRANSLATE("Software Rasterizer"), new BMessage(MENU_SWRAST_MESSAGE))); menu->AddItem(new BMenuItem(B_TRANSLATE("Gallium Software Pipe"), new BMessage(MENU_SWPIPE_MESSAGE))); menu->AddItem(new BMenuItem(B_TRANSLATE("Gallium LLVM Pipe"), new BMessage(MENU_SWLLVM_MESSAGE))); BMenuField* menuField = new BMenuField("renderer", B_TRANSLATE("3D Rendering Engine:"), menu); // TODO: Set current Renderer menuField->SetEnabled(false); BTabView *tabView = new BTabView("tab view", B_WIDTH_FROM_LABEL); tabView->AddTab(new InfoView()); tabView->AddTab(new CapabilitiesView()); tabView->AddTab(new ExtensionsView()); glView->UnlockGL(); GroupLayout()->SetSpacing(0); BLayoutBuilder::Group<>(this) .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .Add(menuField) .AddGroup(B_HORIZONTAL) .Add(tabView) .SetInsets(0, B_USE_DEFAULT_SPACING, 0, 0); }
void MesaDriver::CopySubBuffer(GLint x, GLint y, GLuint width, GLuint height) const { if (m_bitmap) { // Source bitmap and view's bitmap are same size. // Source and dest rectangle are the same. // Note (x,y) = (0,0) is the lower-left corner, have to flip Y BRect srcAndDest; srcAndDest.left = x; srcAndDest.right = x + width - 1; srcAndDest.bottom = m_bottom - y; srcAndDest.top = srcAndDest.bottom - height + 1; m_bglview->DrawBitmap(m_bitmap, srcAndDest, srcAndDest); } }
void MesaDriver::WriteMonoRGBAPixelsFront(const GLcontext *ctx, GLuint n, const GLint x[], const GLint y[], const GLchan color[4], const GLubyte mask[]) { MesaDriver *md = (MesaDriver *) ctx->DriverCtx; BGLView *bglview = md->m_bglview; assert(bglview); // plot points using current color bglview->SetHighColor(color[RCOMP], color[GCOMP], color[BCOMP]); if (mask) { for (GLuint i = 0; i < n; i++) { if (mask[i]) { Plot(bglview, x[i], md->m_bottom - y[i]); } } } else { for (GLuint i = 0; i < n; i++) { Plot(bglview, x[i], md->m_bottom - y[i]); } } }
void MesaDriver::WriteRGBAPixelsFront(const GLcontext *ctx, GLuint n, const GLint x[], const GLint y[], CONST GLubyte rgba[][4], const GLubyte mask[] ) { MesaDriver *md = (MesaDriver *) ctx->DriverCtx; BGLView *bglview = md->m_bglview; assert(bglview); if (mask) { for (GLuint i = 0; i < n; i++) { if (mask[i]) { bglview->SetHighColor(rgba[i][0], rgba[i][1], rgba[i][2]); Plot(bglview, x[i], md->m_bottom - y[i]); } } } else { for (GLuint i = 0; i < n; i++) { bglview->SetHighColor(rgba[i][0], rgba[i][1], rgba[i][2]); Plot(bglview, x[i], md->m_bottom - y[i]); } } }
void MesaDriver::WriteMonoRGBASpanFront(const GLcontext *ctx, GLuint n, GLint x, GLint y, const GLchan color[4], const GLubyte mask[]) { MesaDriver *md = (MesaDriver *) ctx->DriverCtx; BGLView *bglview = md->m_bglview; assert(bglview); int flippedY = md->m_bottom - y; bglview->SetHighColor(color[RCOMP], color[GCOMP], color[BCOMP]); if (mask) { for (GLuint i = 0; i < n; i++) { if (mask[i]) { Plot(bglview, x++, flippedY); } } } else { for (GLuint i = 0; i < n; i++) { Plot(bglview, x++, flippedY); } } }
void MesaDriver::WriteRGBSpanFront(const GLcontext *ctx, GLuint n, GLint x, GLint y, CONST GLubyte rgba[][3], const GLubyte mask[]) { MesaDriver *md = (MesaDriver *) ctx->DriverCtx; BGLView *bglview = md->m_bglview; assert(bglview); int flippedY = md->m_bottom - y; if (mask) { for (GLuint i = 0; i < n; i++) { if (mask[i]) { bglview->SetHighColor(rgba[i][0], rgba[i][1], rgba[i][2]); Plot(bglview, x++, flippedY); } } } else { for (GLuint i = 0; i < n; i++) { bglview->SetHighColor(rgba[i][0], rgba[i][1], rgba[i][2]); Plot(bglview, x++, flippedY); } } }
void MesaDriver::ClearFront(GLcontext *ctx, GLboolean all, GLint x, GLint y, GLint width, GLint height) { MesaDriver *md = (MesaDriver *) ctx->DriverCtx; BGLView *bglview = md->m_bglview; assert(bglview); bglview->SetHighColor(md->m_clear_color[BE_RCOMP], md->m_clear_color[BE_GCOMP], md->m_clear_color[BE_BCOMP], md->m_clear_color[BE_ACOMP]); bglview->SetLowColor(md->m_clear_color[BE_RCOMP], md->m_clear_color[BE_GCOMP], md->m_clear_color[BE_BCOMP], md->m_clear_color[BE_ACOMP]); if (all) { BRect b = bglview->Bounds(); bglview->FillRect(b); } else { // XXX untested BRect b; b.left = x; b.right = x + width; b.bottom = md->m_height - y - 1; b.top = b.bottom - height; bglview->FillRect(b); } // restore drawing color #if 0 bglview->SetHighColor(md->mColor[BE_RCOMP], md->mColor[BE_GCOMP], md->mColor[BE_BCOMP], md->mColor[BE_ACOMP]); bglview->SetLowColor(md->mColor[BE_RCOMP], md->mColor[BE_GCOMP], md->mColor[BE_BCOMP], md->mColor[BE_ACOMP]); #endif }
void MesaDriver::Draw(BRect updateRect) const { if (m_bitmap) m_bglview->DrawBitmap(m_bitmap, updateRect, updateRect); }