bool renderTheme( float s = 8.0f, float lw = 2.0f, const osgWidget::Color& lc = osgWidget::Color(0.0f, 0.0f, 0.0f, 1.0f), const osgWidget::Color& fc = osgWidget::Color(1.0f, 1.0f, 1.0f, 1.0f) ) { if(!allocateSurface(s * 8.0f, s)) return false; if(!createContext()) return false; // Some variables to make this easier to work with... float r = s * 0.75f; float top = osg::PI + osg::PI_2; float bottom = osg::PI_2; float left = osg::PI; float right = 0.0f; setLineWidth(lw * 2.0f); // Create the upper-left region. arc(s, s, r, left, top); _finalizeCorner(s, s, lc, fc); // Create the top border region. _drawBorder(s + (s - r), 0.0f, r, s, 0.0f, s, lc, fc); // Create the upper-right region. arc(s * 2.0f, s, r, top, right); _finalizeCorner(s * 2.0f, s, lc, fc); // Create the left border. _drawBorder((s * 3.0f) + (s - r), 0.0f, r, s, 0.0f, s, lc, fc); // Create the right border. _drawBorder((s * 4.0f), 0.0f, r, s, r, s, lc, fc); fill(); // Create the bottom-left region. arc(s * 6.0f, 0.0f, r, bottom, left); _finalizeCorner(s * 6.0f, 0.0f, lc, fc); // Create the bottom border region. _drawBorder((s * 6.0f), 0.0f, r, s, r, s, lc, fc); // Create the bottom-right region. arc(s * 7.0f, 0.0f, r, right, bottom); _finalizeCorner(s * 7.0f, 0.0f, lc, fc); flipVertical(); return true; }
bool D3D9WPFRenderer::checkResize( bool isDeviceLost ) { bool isDeviceReset = false; //resize the system if the desired width or height is more than we can support. if ( mDesiredWidth > m_displayWidth || mDesiredHeight > m_displayHeight || isDeviceLost ) { m_displayWidth = PxMax( mDesiredWidth, m_displayWidth ); m_displayHeight = PxMax( mDesiredHeight, m_displayHeight ); if ( isDeviceLost ) { physx::PxU64 res = m_d3dDevice->TestCooperativeLevel(); if(res == D3D_OK || res == D3DERR_DEVICENOTRESET) //if device is lost, device has to be ready for reset { isDeviceReset = true; onDeviceLost(); onDeviceReset(); } } else { releaseSurface(); releaseDepthStencilSurface(); allocateSurface(); buildDepthStencilSurface(); // set out initial states... m_d3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); m_d3dDevice->SetRenderState(D3DRS_LIGHTING, 0); m_d3dDevice->SetRenderState(D3DRS_ZENABLE, 1); } } //else just mess with the viewport so we only render pixel-by-pixel D3DVIEWPORT9 viewport = {0}; m_d3dDevice->GetViewport(&viewport); if ( viewport.Width != mDesiredWidth || viewport.Height != mDesiredHeight ) { viewport.X = 0; viewport.Y = 0; viewport.Width = (DWORD)mDesiredWidth; viewport.Height = (DWORD)mDesiredHeight; viewport.MinZ = 0.0f; viewport.MaxZ = 1.0f; m_d3dDevice->SetViewport(&viewport); } return isDeviceReset; }
bool Image::allocateSurface(const osg::Image* image) { if(!image) return false; if(_surface) return false; const osgCairo::Image* test = dynamic_cast<const osgCairo::Image*>(image); if(test) { OSGCAIRO_WARN << "Cannot allocate from an existing osgCairo::Image; " "use copy construction instead; this method is only intended " "for allocating from a traditional osg::Image." << std::endl ; return false; } GLenum format = image->getPixelFormat(); if(format == GL_ALPHA || format == GL_LUMINANCE) return allocateSurface( image->s(), image->t(), CAIRO_FORMAT_A8, static_cast<const unsigned char*>(image->getDataPointer()) ); else if(format != GL_RGB && format != GL_RGBA) { OSGCAIRO_WARN << "Can only allocate ARGB32 surfaces from GL_RGB/GL_RGBA Image sources." << std::endl ; return false; } allocateImage(image->s(), image->t(), 1, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV); if(!osg::Image::valid()) return false; _pixelFormat = GL_BGRA; const unsigned char* data = image->data(); unsigned int numPixels = image->s() * image->t(); unsigned int offset = 4; if(format == GL_RGB) offset = 3; for(unsigned int i = 0; i < numPixels; i++) { unsigned char a = data[i * offset + 3]; unsigned char r = data[i * offset + 2]; unsigned char g = data[i * offset + 1]; unsigned char b = data[i * offset]; // We want ARGB32 from a _SOURCE_ that _DOES_ have an alpha // channel; therefore, we need to premultiply. if(format == GL_RGBA) { _data[i * 4] = (r * a) / 255; _data[i * 4 + 1] = (g * a) / 255; _data[i * 4 + 2] = (b * a) / 255; _data[i * 4 + 3] = a; } // Otherwise, we're loading from a source with no alpha // channel. This doesn't make a lot of sense to do, unless // the user is planning on using CAIRO_OPERATOR_CLEAR at // some point during their drawing. else { _data[i * 4] = r; _data[i * 4 + 1] = g; _data[i * 4 + 2] = b; _data[i * 4 + 3] = 255; } } // Remove any previous surface allocation. if(_surface) cairo_surface_destroy(_surface); _surface = cairo_image_surface_create_for_data( _data, CAIRO_FORMAT_ARGB32, image->s(), image->t(), cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, image->s()) ); if(!valid()) return false; dirty(); return true; }
void D3D9WPFRenderer::onDeviceReset() { allocateSurface(); D3D9Renderer::onDeviceReset(); }