status_t Layer::BufferManager::initEglImage(EGLDisplay dpy, const sp<GraphicBuffer>& buffer) { status_t err = NO_INIT; ssize_t index = mActiveBuffer; if (index >= 0) { if (!mFailover) { Image& texture(mBufferData[index].texture); err = mTextureManager.initEglImage(&texture, dpy, buffer); // if EGLImage fails, we switch to regular texture mode, and we // free all resources associated with using EGLImages. if (err == NO_ERROR) { mFailover = false; destroyTexture(&mFailoverTexture, dpy); } else { mFailover = true; const size_t num = mNumBuffers; for (size_t i=0 ; i<num ; i++) { destroyTexture(&mBufferData[i].texture, dpy); } } } else { // we failed once, don't try again err = BAD_VALUE; } } return err; }
int main( int argc, char** argv ) { glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH|GLUT_MULTISAMPLE ); glutCreateWindow( "ch3_03_Magic_Photographer" ); glutFullScreen(); glutIdleFunc( update ); glutDisplayFunc( render ); glutReshapeFunc( reshape ); glutKeyboardFunc( keyEvents ); if ( TextureManager::Inst()->LoadTexture("background.bmp", backgroundTexID, GL_BGR_EXT) ) { glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); } if ( !initializeKinect() ) return 1; colorTexture = createTexture(640, 480, GL_RGB, 3); playerColorTexture = createTexture(640, 480, GL_RGBA, 4); glutMainLoop(); destroyTexture( colorTexture ); destroyTexture( playerColorTexture ); destroyKinect(); return 0; }
int SdlApp::drawFrame(const ImageBuffer* imageBuffer) { SDL_Surface* surface = imageBuffer->toSdlSurface(); if (surface == nullptr) { // SDL_DestroyRenderer(mSdlRenderer); // SDL_DestroyWindow(mSdlWindow); // SDL_Quit(); return 1; } // create the texture SDL_Texture* texture = SDL_CreateTextureFromSurface(mSdlRenderer, surface); SDL_FreeSurface(surface); if (texture == nullptr) { SDL_DestroyRenderer(mSdlRenderer); SDL_DestroyWindow(mSdlWindow); std::cout << "SDL_CreateTextureFromSurface Error: " << SDL_GetError() << std::endl; SDL_Quit(); return 1; } SDL_RenderClear(mSdlRenderer); SDL_RenderCopy(mSdlRenderer, texture, nullptr, nullptr); SDL_RenderPresent(mSdlRenderer); destroyTexture(); mSdlTexture = texture; return 0; }
void SurfaceBuffer::destructBufferState() { destroyTexture(); if (m_buffer) { sendRelease(); if (m_handle) { if (m_shmBuffer) { delete static_cast<QImage *>(m_handle); #ifdef QT_COMPOSITOR_WAYLAND_GL } else { QWaylandClientBufferIntegration *hwIntegration = m_compositor->clientBufferIntegration(); hwIntegration->unlockNativeBuffer(m_handle, 0); #endif } } wl_list_remove(&m_destroy_listener.listener.link); } m_buffer = 0; m_handle = 0; m_committed = false; m_is_registered_for_buffer = false; m_is_displayed = false; m_image = QImage(); }
void destroyGBuffer(GBuffer& b) { for (usize i = 0; i < GBuffer::Count; i++) destroyTexture(b.textures[i]); if (b.fbo) glDeleteFramebuffers(1, &b.fbo); }
void QGLPixmapData::reclaimTexture() { if (!inTexturePool) return; forceToImage(); destroyTexture(); }
QGLPixmapData::~QGLPixmapData() { delete m_engine; destroyTexture(); qt_gl_unregister_pixmap(this); }
void Framework::update(){ if ( gFirstFrame ){ gFirstFrame = false; gImage = new Image( "background.dds" ); createTexture( &gTexture, gImage->width(), gImage->height(), gImage->data(), gImage->width(), gImage->height() ); SAFE_DELETE( gImage ); } setTexture( gTexture ); double p0[ 2 ] = { 100.0, 100.0 }; double p1[ 2 ] = { 200.0, 120.0 }; double p2[ 2 ] = { 120.0, 200.0 }; double t0[ 2 ] = { 0.0, 0.0 }; double t1[ 2 ] = { 1.0, 0.0 }; double t2[ 2 ] = { 0.0, 1.0 }; drawTriangle2D( p0, p1, p2, t0, t1, t2 ); //終了処理してみようか if ( isEndRequested() ){ destroyTexture( &gTexture ); } }
void QGLPixmapData::fill(const QColor &color) { if (!isValid()) return; bool hasAlpha = color.alpha() != 255; if (hasAlpha && !m_hasAlpha) { if (m_texture.id) { destroyTexture(); m_dirty = true; } m_hasAlpha = color.alpha() != 255; } if (useFramebufferObjects()) { m_source = QVolatileImage(); m_hasFillColor = true; m_fillColor = color; } else { forceToImage(); if (m_source.depth() == 32) { m_source.fill(PREMUL(color.rgba())); } else if (m_source.depth() == 1) { if (color == Qt::color1) m_source.fill(1); else m_source.fill(0); } } }
/************************************************************************* destroy all textures still active *************************************************************************/ void DirectX9Renderer::destroyAllTextures(void) { while (!d_texturelist.empty()) { destroyTexture(*(d_texturelist.begin())); } }
void QGLPixmapData::fromNativeType(void* pixmap, NativeType type) { if (type == QPixmapData::SgImage && pixmap) { #if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) RSgImage *sgImage = reinterpret_cast<RSgImage*>(pixmap); m_sgImage = new RSgImage; m_sgImage->Open(sgImage->Id()); TSgImageInfo info; sgImage->GetInfo(info); w = info.iSizeInPixels.iWidth; h = info.iSizeInPixels.iHeight; d = symbianPixeFormatBitsPerPixel((TUidPixelFormat)info.iPixelFormat); m_source = QVolatileImage(); m_hasAlpha = true; m_hasFillColor = false; m_dirty = true; is_null = (w <= 0 || h <= 0); #endif } else if (type == QPixmapData::FbsBitmap && pixmap) { CFbsBitmap *bitmap = reinterpret_cast<CFbsBitmap *>(pixmap); QSize size(bitmap->SizeInPixels().iWidth, bitmap->SizeInPixels().iHeight); if (size.width() == w && size.height() == h) setSerialNumber(++qt_gl_pixmap_serial); resize(size.width(), size.height()); m_source = QVolatileImage(bitmap); if (pixelType() == BitmapType) { m_source.ensureFormat(QImage::Format_MonoLSB); } else if (!knownGoodFormat(m_source.format())) { m_source.beginDataAccess(); QImage::Format format = idealFormat(m_source.imageRef(), Qt::AutoColor); m_source.endDataAccess(true); m_source.ensureFormat(format); } m_hasAlpha = m_source.hasAlphaChannel(); m_hasFillColor = false; m_dirty = true; d = m_source.depth(); } else if (type == QPixmapData::VolatileImage && pixmap) { // Support QS60Style in more efficient skin graphics retrieval. QVolatileImage *img = static_cast<QVolatileImage *>(pixmap); if (img->width() == w && img->height() == h) setSerialNumber(++qt_gl_pixmap_serial); resize(img->width(), img->height()); m_source = *img; m_hasAlpha = m_source.hasAlphaChannel(); m_hasFillColor = false; m_dirty = true; d = m_source.depth(); } else if (type == QPixmapData::NativeImageHandleProvider && pixmap) { destroyTexture(); nativeImageHandleProvider = static_cast<QNativeImageHandleProvider *>(pixmap); // Cannot defer the retrieval, we need at least the size right away. createFromNativeImageHandleProvider(); } }
status_t Layer::BufferManager::destroy(EGLDisplay dpy) { BufferData* const buffers = mBufferData; size_t num; { // scope for the lock Mutex::Autolock _l(mLock); num = mNumBuffers; for (size_t i=0 ; i<num ; i++) { buffers[i].buffer = 0; } } for (size_t i=0 ; i<num ; i++) { destroyTexture(&buffers[i].texture, dpy); } destroyTexture(&mFailoverTexture, dpy); return NO_ERROR; }
int SdlApp::quit() { destroyTexture(); SDL_DestroyRenderer(mSdlRenderer); SDL_DestroyWindow(mSdlWindow); SDL_Quit(); return 0; }
void Canvas::loadTexture( Ogre::TexturePtr texture, bool manageMode ) { destroyTexture(); mTexPtr = texture; mTexManaged = manageMode; }
void SurfaceBuffer::createTexture() { destroyTexture(); ClientBufferIntegration *hwIntegration = m_compositor->clientBufferIntegration(); #ifdef QT_COMPOSITOR_WAYLAND_GL m_texture = hwIntegration->textureForBuffer(m_buffer); hwIntegration->bindTextureToBuffer(m_buffer); #else Q_UNUSED(hwIntegration); #endif }
void destroyFBO(FBO *fbo) { if (fbo==NULL) { logError(TAG, "Cannot destroy Default FBO"); return; } GLuint drbId = fbo->mDepthRenderBuffer; GLuint fboId = fbo->mFBO; // switch to default FBO glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); // delete texture destroyTexture(fbo->mTexturePtrId); // delete depth buffer glDeleteRenderbuffersOES(1, &drbId); // delete framebuffer glDeleteFramebuffersOES(1, &fboId); }
QGLPixmapData::~QGLPixmapData() { #ifdef QT_SYMBIAN_SUPPORTS_SGIMAGE if (m_sgImage) { if (m_texture.id) { QGLSgImageTextureCleanup::cleanupForContext(m_ctx)->remove(m_texture.id); destroyTexture(); } m_sgImage->Close(); delete m_sgImage; m_sgImage = 0; } #endif delete m_engine; }
void Canvas::createExactTexture( int _width, int _height, TextureUsage _usage, PixelFormat _format ) { int width = std::max(1, _width); int height = std::max(1, _height); destroyTexture(); mTexture = RenderManager::getInstance().createTexture(mGenTexName); mTexture->setInvalidateListener(this); mTexture->createManual( width, height, _usage, _format ); mTexManaged = true; _setTextureName( mGenTexName ); correctUV(); requestUpdateCanvas( this, Event( true, true, mInvalidateData ) ); }
void QGLPixmapData::hibernate() { // If the image was imported (e.g, from an SgImage under Symbian), then // skip the hibernation, there is no sense in copying it back to main // memory because the data is most likely shared between several processes. bool skipHibernate = (m_texture.id && m_source.isNull()); #if defined(Q_OS_SYMBIAN) // However we have to proceed normally if the image was retrieved via // a handle provider. skipHibernate &= !nativeImageHandleProvider; #endif if (skipHibernate) return; forceToImage(); destroyTexture(); }
void Canvas::createExactTexture( int _width, int _height, Ogre::TextureUsage _usage, Ogre::PixelFormat _format ) { MYGUI_ASSERT( _width >= 0 && _height >= 0, "negative size" ); destroyTexture(); mTexPtr = Ogre::TextureManager::getSingleton().createManual( mGenTexName, ResourceManager::getInstance().getResourceGroup(), Ogre::TEX_TYPE_2D, _width, _height, 0, _format, _usage, this ); mTexPtr->load(); mTexManaged = true; }
void QGLPixmapData::createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace) { if (image.size() == QSize(w, h)) setSerialNumber(++qt_gl_pixmap_serial); resize(image.width(), image.height()); if (pixelType() == BitmapType) { QImage convertedImage = image.convertToFormat(QImage::Format_MonoLSB); if (image.format() == QImage::Format_MonoLSB) convertedImage.detach(); m_source = QVolatileImage(convertedImage); } else { QImage::Format format = idealFormat(image, flags); if (inPlace && image.data_ptr()->convertInPlace(format, flags)) { m_source = QVolatileImage(image); } else { QImage convertedImage = image.convertToFormat(format); // convertToFormat won't detach the image if format stays the same. if (image.format() == format) convertedImage.detach(); m_source = QVolatileImage(convertedImage); } } m_dirty = true; m_hasFillColor = false; m_hasAlpha = m_source.hasAlphaChannel(); w = image.width(); h = image.height(); is_null = (w <= 0 || h <= 0); d = m_source.depth(); destroyTexture(); }
void QGLPixmapData::resize(int width, int height) { if (width == w && height == h) return; if (width <= 0 || height <= 0) { width = 0; height = 0; } w = width; h = height; is_null = (w <= 0 || h <= 0); d = pixelType() == QPixmapData::PixmapType ? 32 : 1; destroyTexture(); m_source = QVolatileImage(); m_dirty = isValid(); setSerialNumber(++qt_gl_pixmap_serial); }
void BerkeliumWidget::shutdownOverride() { MyGUI::Gui::getInstance().eventFrameStart -= MyGUI::newDelegate(this, &BerkeliumWidget::notifyFrameStart); destroyTexture(); if (mWindow != nullptr) { mWindow->destroy(); mWindow = nullptr; } requestUpdateCanvas = nullptr; if (mWindowDelegate) { delete mWindowDelegate; mWindowDelegate = nullptr; } Base::shutdownOverride(); }
void freeSoundMenu() { int i; if (menu.widgets != NULL) { for (i=0;i<menu.widgetCount;i++) { freeWidget(menu.widgets[i]); } free(menu.widgets); menu.widgets = NULL; } if (menu.background != NULL) { destroyTexture(menu.background); menu.background = NULL; } }
void Framework::update(){ sleep( 16 ); if ( gFirstFrame ){ gFirstFrame = false; gImage = new Image( "background.dds" ); gImageWidth = gImage->width(); gImageHeight = gImage->height(); createTexture( &gTexture, gImageWidth, gImageHeight, gImage->data(), gImageWidth, gImageHeight ); SAFE_DELETE( gImage ); } setTexture( gTexture ); double rotation = static_cast< double >( gCount ); Vector2 scale( sin( rotation ) + 0.5, cos( rotation ) + 0.5 ); //行列作る Matrix23 m; m.setTranslation( Vector2( gImageWidth/2, gImageHeight/2 ) ); if ( gScaleFirst ){ m.rotate( rotation ); m.scale( scale ); }else{ m.scale( scale ); m.rotate( rotation ); } m.translate( Vector2( -gImageWidth/2, -gImageHeight/2 ) ); Vector2 p0( 0.0, 0.0 ); Vector2 p1( 100.0, 0.0 ); Vector2 p2( 0.0, 100.0 ); Vector2 p3( 100.0, 100.0 ); double t0[ 2 ] = { 0.0, 0.0 }; double t1[ 2 ] = { 1.0, 0.0 }; double t2[ 2 ] = { 0.0, 1.0 }; double t3[ 2 ] = { 1.0, 1.0 }; //行列乗算 m.multiply( &p0, p0 ); m.multiply( &p1, p1 ); m.multiply( &p2, p2 ); m.multiply( &p3, p3 ); //描画 //Vector2はそのままは渡せません。 drawTriangle2D( &p0.x, &p1.x, &p2.x, t0, t1, t2 ); //012 drawTriangle2D( &p3.x, &p1.x, &p2.x, t3, t1, t2 ); //312 //スペースで切り替え if ( Input::Manager::instance().keyboard().isTriggered( ' ' ) ){ gScaleFirst = !gScaleFirst; } ++gCount; drawDebugString( 0, 0, "press SPACE to swap ROTATION and SCALING" ); //終了処理してみようか if ( isEndRequested() ){ destroyTexture( &gTexture ); } }
ColourPanel::~ColourPanel() { destroyTexture(); }
//----------------------------------------------------------------------------// void DirectFBRenderer::destroyAllTextures() { while (!d_textures.empty()) destroyTexture(d_textures.begin()->first); }
//----------------------------------------------------------------------------// void IrrlichtRenderer::destroyAllTextures() { while (!d_textures.empty()) destroyTexture(**d_textures.begin()); }
//----------------------------------------------------------------------------// void Direct3D9Renderer::destroyAllTextures() { while (!d_textures.empty()) destroyTexture(**d_textures.begin()); }
int main(int argc, char **argv) { TestScene *scene = new TestScene(argc, argv, 2); GLuint tex_1 = initTexture(128, 128, carve_texture); GLuint tex_2 = initTexture(128, 128, brick_texture); GLuint tex_3 = initTexture(128, 128, leaf_texture); g_scale = 10.0; carve::interpolate::FaceVertexAttr<tex_t> fv_tex; carve::interpolate::FaceAttr<GLuint> f_tex_num; carve::mesh::MeshSet<3> *base = NULL; bool b = true; for (int x = -10; x <= +10; x += 5) { for (int y = -10; y <= +10; y += 5) { for (int z = -10; z <= +10; z += 5) { double rot = x * .17 + y * .06 + z * .09; carve::mesh::MeshSet<3> *r = texturedCube(fv_tex, f_tex_num, b ? tex_2 : tex_3, carve::math::Matrix::TRANS(x/2.5, y/2.5, z/2.5) * carve::math::Matrix::ROT(rot, 1,2,3)); b = !b; if (base) { carve::mesh::MeshSet<3> *temp = base; carve::csg::CSG csg; fv_tex.installHooks(csg); f_tex_num.installHooks(csg); base = csg.compute(temp, r, carve::csg::CSG::UNION); delete temp; delete r; } else { base = r; } } } } carve::mesh::MeshSet<3> *r1 = texturedCube(fv_tex, f_tex_num, tex_1, carve::math::Matrix::TRANS(0,0,4) * carve::math::Matrix::SCALE(4,4,4)); carve::mesh::MeshSet<3> *r2 = texturedCube(fv_tex, f_tex_num, tex_1, carve::math::Matrix::TRANS(0,0,5) * carve::math::Matrix::SCALE(2, 2, 2)); carve::csg::CSG csg; fv_tex.installHooks(csg); f_tex_num.installHooks(csg); carve::mesh::MeshSet<3> *r3 = csg.compute(base, r1, carve::csg::CSG::INTERSECTION, NULL, carve::csg::CSG::CLASSIFY_EDGE); carve::mesh::MeshSet<3> *r4 = csg.compute(r3, r2, carve::csg::CSG::UNION, NULL, carve::csg::CSG::CLASSIFY_EDGE); glNewList(scene->draw_list_base, GL_COMPILE); drawTexturedPolyhedron(r4, fv_tex, f_tex_num); glEndList(); glNewList(scene->draw_list_base+1, GL_COMPILE); drawWireframePolyhedron(r3); glEndList(); scene->draw_flags[0] = true; scene->draw_flags[1] = true; scene->run(); destroyTexture(tex_1); destroyTexture(tex_2); destroyTexture(tex_3); delete scene; return 0; }