예제 #1
0
/////////////////////////////////////////////////////////////
/// Met à jour les pixels de la texture
///
/// \param Rect : Rectangle à mettre à jour dans la texture
///
////////////////////////////////////////////////////////////
void GLTexture::Update(const CRectangle& Rect)
{
    CA_ASSERT(CRectangle(0, 0, m_Size.x, m_Size.y).Intersects(Rect) != INT_OUT, "GLTexture::Update() : rectangle out of bounds");

	 GLCheck(glBindTexture(GL_TEXTURE_2D, m_Texture));

    GLEnum::TPixelFmt TexFmt = GLEnum::Get(m_Format);
    GLEnum::TPixelFmt ImgFmt = GLEnum::Get(m_Data.GetFormat());

    if (FormatCompressed(m_Data.GetFormat()))
    {
#if CA_PLATFORM_DESKTOP

        // Format de pixel compressé - on utilise une extension pour uploader les pixels
        unsigned long DataSize = Rect.Width() * Rect.Height() * GetBytesPerPixel(m_Data.GetFormat());
        if (Rect.Width() == m_Size.x && Rect.Height() == m_Size.y)
        {
            // Le rectangle source couvre la totalité de l'image : on envoie directement les données
            GLRenderer::glCompressedTexSubImage2DARB(GL_TEXTURE_2D, 0, Rect.Left(), Rect.Top(), Rect.Width(), Rect.Height(), ImgFmt.Format, DataSize, m_Data.GetData());
        }
        else
        {
            // Le rectangle source ne couvre qu'une partie de l'image : on envoie une sous-image de l'image en mémoire
            CImage SubData = m_Data.SubImage(Rect);
            GLRenderer::glCompressedTexSubImage2DARB(GL_TEXTURE_2D, 0, Rect.Left(), Rect.Top(), Rect.Width(), Rect.Height(), ImgFmt.Format, DataSize, SubData.GetData());
        }

#else

		throw NEW_AO CNotImplementedException("GLTexture::Update() : compressed format is not supported\n");

#endif // CA_PLATFORM_DESKTOP

    }
    else
    {
		GLint pixelStore = 0;

		switch (m_Data.GetFormat())
		{
		case PixelFormat::L_8:		///< Luminosity 8 bits (1 byte)
			pixelStore = 1;
			break;

		case PixelFormat::AL_88:		///< Alpha and luminosity 16 bits (2 bytes)
		case PixelFormat::ARGB_1555:	///< RGB 16 bits 1555 (2 bytes)
		case PixelFormat::ARGB_4444:	///< RGB 16 bits 4444 (2 bytes)
		case PixelFormat::PVRTC2:		///< PVR texture compression. Each pixel is 2 bits.
			pixelStore = 2;
			break;

		case PixelFormat::RGB_888:	///< RGB 24 bits 888 (3 bytes)
		case PixelFormat::RGB_DXT1:   ///< S3 DXT1 texture compression (RGB)
			//
		case PixelFormat::ARGB_8888:	///< ARGB 32 bits 8888 (4 bytes)
		case PixelFormat::PVRTC4:	  ///< PVR texture compression. Each pixel is 4 bits.
		case PixelFormat::RGBA_DXT1:  ///< S3 DXT1 texture compression (RGBA)
		case PixelFormat::RGBA_DXT3:  ///< S3 DXT3 texture compression (RGBA)
		case PixelFormat::RGBA_DXT5:  ///< S3 DXT5 texture compression (RGBA)
			pixelStore = 4;
			break;
		}

		GLCheck(glPixelStorei(GL_PACK_ALIGNMENT, pixelStore));

        if (!m_HasMipmaps || m_AutoMipmaps)
        {
            // Pas de mipmap ou génération hardware : on ne met à jour que le premier niveau
            if ((Rect.Width() == m_Size.x) && (Rect.Height() == m_Size.y))
            {
				GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0,
					0, 0, Rect.Width(), Rect.Height(), ImgFmt.Format, ImgFmt.Type, m_Data.GetData()));
            }
            else
            {
                CImage SubData = m_Data.SubImage(Rect);
				GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0,
					Rect.Left(), Rect.Top(), Rect.Width(), Rect.Height(), ImgFmt.Format, ImgFmt.Type, SubData.GetData()));
            }
        }
        else
        {

#if CA_PLATFORM_DESKTOP
            // Plusieurs niveaux de mipmapping et génération software : on met à jour tous les niveaux
            GLCheck(gluBuild2DMipmaps(GL_TEXTURE_2D, TexFmt.Internal, m_Size.x, m_Size.y, ImgFmt.Format, ImgFmt.Type, m_Data.GetData()));

#else
			if ((Rect.Width() == m_Size.x) && (Rect.Height() == m_Size.y))
			{
				GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0,
					0, 0, Rect.Width(), Rect.Height(), ImgFmt.Format, ImgFmt.Type, m_Data.GetData()));
			}
			else
			{
				CImage SubData = m_Data.SubImage(Rect);
				GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0,
					Rect.Left(), Rect.Top(), Rect.Width(), Rect.Height(), ImgFmt.Format, ImgFmt.Type, SubData.GetData()));
			}

#endif // CA_PLATFORM_DESKTOP

			GLCheck(glGenerateMipmap(GL_TEXTURE_2D));

        }
    }

    GLCheck(glBindTexture(GL_TEXTURE_2D, 0));
}
예제 #2
0
파일: TradeImpl.cpp 프로젝트: ifzz/FDK
void* CTradeImpl::GetTradeCaptureReports(void* /*handle*/, const Nullable<CDateTime>& /*from*/, const Nullable<CDateTime>& /*to*/, const size_t /*timeoutInMilliseconds*/)
{
	throw CNotImplementedException();
}