00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "KeosOGLTexture.h"
00022 #include "KeosOGLEnum.h"
00023 #include "KeosOGLRenderSystem.h"
00024 #include "KeosPixelUtils.h"
00025 #include "KeosRectangle.h"
00026
00027 namespace Keos
00028 {
00029
00030
00031
00032
00033
00034 COGLTexture::COGLTexture(const TVector2I& Size, TPixelFormat Format, bool bHasMipmaps, bool bAutoMipmaps, uint nTexture) :
00035 ITextureBase(Size, Format, bHasMipmaps, bAutoMipmaps),
00036 m_nTexture (nTexture)
00037 {}
00038
00039
00040 COGLTexture::~COGLTexture()
00041 {
00042 if (m_nTexture)
00043 glDeleteTextures(1, &m_nTexture);
00044 }
00045
00046
00047 uint COGLTexture::GetOGLTexture() const
00048 {
00049 return m_nTexture;
00050 }
00051
00052
00053 void COGLTexture::Update(const CRectangle& Rect)
00054 {
00055 Assert(CRectangle(0, 0, m_Size.x, m_Size.y).Intersects(Rect) == INT_IN);
00056
00057
00058 COGLEnum::TPixelFmt TexFmt = COGLEnum::Get(m_Format);
00059 COGLEnum::TPixelFmt ImgFmt = COGLEnum::Get(m_Data.GetFormat());
00060
00061
00062 glBindTexture(GL_TEXTURE_2D, m_nTexture);
00063
00064
00065 if (FormatCompressed(m_Data.GetFormat()))
00066 {
00067
00068 ulong DataSize = Rect.Width() * Rect.Height() * GetBytesPerPixel(m_Data.GetFormat());
00069 if (Rect.Width() == m_Size.x && Rect.Height() == m_Size.y)
00070 {
00071 COGLRenderSystem::glCompressedTexSubImage2DARB(GL_TEXTURE_2D, 0, Rect.Left(), Rect.Top(), Rect.Width(), Rect.Height(), ImgFmt.Format, DataSize, m_Data.GetData());
00072 }
00073 else
00074 {
00075 CImage SubData = m_Data.SubImage(Rect);
00076 COGLRenderSystem::glCompressedTexSubImage2DARB(GL_TEXTURE_2D, 0, Rect.Left(), Rect.Top(), Rect.Width(), Rect.Height(), ImgFmt.Format, DataSize, SubData.GetData());
00077 }
00078 }
00079 else
00080 {
00081 if (!m_bHasMipmaps || m_bAutoMipmaps)
00082 {
00083 if ((Rect.Width() == m_Size.x) && (Rect.Height() == m_Size.y))
00084 {
00085 glTexSubImage2D(GL_TEXTURE_2D, 0, Rect.Left(), Rect.Top(), Rect.Width(), Rect.Height(), ImgFmt.Format, ImgFmt.Type, m_Data.GetData());
00086 }
00087 else
00088 {
00089 CImage SubData = m_Data.SubImage(Rect);
00090 glTexSubImage2D(GL_TEXTURE_2D, 0, Rect.Left(), Rect.Top(), Rect.Width(), Rect.Height(), ImgFmt.Format, ImgFmt.Type, SubData.GetData());
00091 }
00092 }
00093 else
00094 {
00095 gluBuild2DMipmaps(GL_TEXTURE_2D, TexFmt.Internal, m_Size.x, m_Size.y, ImgFmt.Format, ImgFmt.Type, m_Data.GetData());
00096 }
00097 }
00098
00099
00100 glBindTexture(GL_TEXTURE_2D, 0);
00101 }
00102
00103 }