Example #1
0
 void DarwinGlTexture::iUpdateTextureSurface( const GlTextureUpdateType& utype )
 {
     if ( utype == GlTextureUpdateType::PixelBuffer )
     {
         SoftwarePixelBuffer softpixu = getPixelBuffer();
         
         if ( softpixu.isInvalid() )
         {
             return;
         }
         
         SoftwarePixelBufferHolder softpix = softpixu.lock();
         
         if ( iGlTexture )
         {
             bind();
             
             // Here we assume the Texture has already been created and the Surface is correct.
             // We just call glTexSubImage depending on the TextureType.
             
             GLenum target = GlTextureTargetFromTextureType(getType());
             GLint level = 0;
             GLint xoffset = 0;                                              // Unsupported
             GLint yoffset = 0;                                              // Unsupported
             GLint zoffset = 0;                                              // Unsupported
             GLsizei width = getSurface().width;
             GLsizei height = getSurface().height;
             GLsizei depth = 0;                                              // Unsupported
             GLenum format = GlTextureComponents(softpix->getPixelFormat());
             GLenum type = GlTextureFormat(softpix->getPixelFormat());
             const GLvoid* pixels = (const GLvoid*) softpix->getData();
             
             TextureType textype = getType();
             
             if ( textype == TextureType::OneDimension )
             {
                 glTexSubImage1D(target, level, xoffset, width, format, type, pixels);
             }
             
             if ( textype == TextureType::TwoDimension )
             {
                 glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
             }
             
             if ( textype == TextureType::ThreeDimension )
             {
                 glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
             }
             
             if ( textype == TextureType::CubeMap )
             {
                 // Here we have 6 different textures. But we will not do it for now.
                 // UNSUPPORTED
             }
             
         }
         
         else
         {
             // If 'iGlTexture' is invalid , we must create the Texture object.
             // We must also check for TextureType , and Surface .
             
             if ( getType() == TextureType::Null )
                 return;
             Surface surf = getSurface();
             if ( surf.width <= 0 || surf.height <= 0 )
                 return;
             
             glGenTextures(1, &iGlTexture);
             bind();
             
             GLenum target = GlTextureTargetFromTextureType(getType());
             GLint level = 0;
             GLsizei width = getSurface().width;
             GLsizei height = getSurface().height;
             GLsizei depth = 0;                                              // Unsupported
             GLenum format = GlTextureComponents(softpix->getPixelFormat());
             GLenum type = GlTextureFormat(softpix->getPixelFormat());
             const GLvoid* pixels = (const GLvoid*) softpix->getData();
             
             TextureType textype = getType();
             
             if ( textype == TextureType::OneDimension )
             {
                 glTexImage1D(target, level, GL_RGBA, width, 0, format, type, pixels);
             }
             
             if ( textype == TextureType::TwoDimension )
             {
                 glTexImage2D(target, level, GL_RGBA, width, height, 0, format, type, pixels);
             }
             
             if ( textype == TextureType::ThreeDimension )
             {
                 glTexImage3D(target, level, GL_RGBA, width, height, depth, 0, format, type, pixels);
             }
             
             if ( textype == TextureType::CubeMap )
             {
                 // Here we have 6 different textures. But we will not do it for now.
                 // UNSUPPORTED
             }
         }
     }
     
     if ( utype == GlTextureUpdateType::Surface )
     {
         // If we are updating the Surface , but the GlTexture is valid , we should destroy it and
         // make a new one. Normally , you should not use Texture::setSurface if data is already set.
         
         if ( iGlTexture )
         {
             // Destroy the Texture , and launch the Update with SoftwarePixelBuffer .
             glDeleteTextures(1, &iGlTexture);
             iGlTexture = 0;
         }
         
         SoftwarePixelBuffer pixbufu = getPixelBuffer();
         
         if ( pixbufu.isInvalid() )
         {
             // Create a new empty pixel buffer .
             SoftwarePixelBufferHolder pixbuf = SoftwarePixelBufferHolder ( new SoftwarePixelBufferPrivate(getName()+"/0softbuf") );
             pixbuf->setPixelFormat(HardwarePixelFormat::RGBAFloat);
             pixbuf->setData(nullptr, getSurface().width * getSurface().height * sizeof(float));
             setPixelBuffer(pixbuf);
         }
         
         else
         {
             iUpdateTextureSurface(GlTextureUpdateType::PixelBuffer);
         }
     }
     
     if ( utype == GlTextureUpdateType::Type )
     {
         // If TextureType has changed , we should reload the Texture.
         if ( iGlTexture )
         {
             glDeleteTextures(1, &iGlTexture);
             iGlTexture = 0;
         }
         
         iUpdateTextureSurface(GlTextureUpdateType::PixelBuffer);
     }
 }
void QGLBlitter::setBufferDimensions(const unsigned int width, const unsigned int height) {
    buffer.reset(width * height);

    subWidget->setBufferDimensions(width, height);
    setPixelBuffer(buffer, PixelBuffer::RGB32, width);
}