Back to index

nux  3.0.0
IOpenGLSurface.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #ifndef IOPENGLSURFACE_H
00024 #define IOPENGLSURFACE_H
00025 
00026 namespace nux
00027 {
00028 
00029   class IOpenGLResource;
00030   class IOpenGLSurface: public IOpenGLResource
00031   {
00032     NUX_DECLARE_OBJECT_TYPE(IOpenGLSurface, IOpenGLResource);
00033   public:
00034     virtual int RefCount() const;
00035 
00036     int LockRect(
00037       SURFACE_LOCKED_RECT *pLockedRect,
00038       const SURFACE_RECT *pRect);
00039     int UnlockRect();
00040 
00041     BitmapFormat GetPixelFormat() const;
00042     int GetWidth() const;
00043     int GetHeight() const;
00044     int GetMipLevel() const;
00045     int GetSurfaceTarget() const;
00046     int GetDesc(SURFACE_DESC *pDesc);
00047 
00049     void CopyRenderTarget(int x, int y, int width, int height);
00050 
00052 
00059     unsigned char* GetSurfaceData(int &width, int &height, int &stride);
00060 
00061   private:
00062     virtual ~IOpenGLSurface();
00063 
00064     int InitializeLevel();
00065 
00066     // By Default, the surface refers to the face 0 of the texture and to the mip level 0 of that face.
00067     //    IOpenGLSurface(IOpenGLBaseTexture* DeviceBaseTexture, GLenum OpenGLID)
00068     //        : _STextureTarget(GL_TEXTURE_2D)
00069     //        , _SSurfaceTarget(GL_TEXTURE_2D)
00070     //        , _SMipLevel(0)
00071     //        , _BaseTexture(DeviceBaseTexture)
00072     //        , IOpenGLResource(RTSURFACE)
00073     //    {
00074     //        // IOpenGLSurface surfaces are created inside a IOpenGLTexture2D, IOpenGLCubeTexture and IOpenGLVolumeTexture.
00075     //        // They reside within those classes. The reference counting starts once a call to GetSurfaceLevel,
00076     //        // GetCubeMapSurface or GetVolumeLevel is made to the container object.
00077     //        _RefCount = 0;
00078     //        _OpenGLID = OpenGLID;
00079     //    }
00080     IOpenGLSurface(IOpenGLBaseTexture *DeviceBaseTexture
00081       , GLenum OpenGLID
00082       , GLenum TextureTarget
00083       , GLenum SurfaceTarget
00084       , int MipLevel
00085       , int Slice = 0 /*for volume textures*/
00086       , NUX_FILE_LINE_PROTO);
00087 
00088     // _STextureTarget may be
00089     //      GL_TEXTURE_2D
00090     //      GL_TEXTURE_RECTANGLE_ARB
00091     //      GL_TEXTURE_CUBE_MAP
00092     //      GL_TEXTURE_3D
00093     GLenum      _STextureTarget;
00094 
00095     // _SSurfaceTarget may be
00096     //      GL_TEXTURE_2D
00097     //      GL_TEXTURE_3D
00098     //      GL_TEXTURE_RECTANGLE_ARB
00099     //      GL_TEXTURE_CUBE_MAP_POSITIVE_X
00100     //      GL_TEXTURE_CUBE_MAP_NEGATIVE_X
00101     //      GL_TEXTURE_CUBE_MAP_POSITIVE_Y
00102     //      GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
00103     //      GL_TEXTURE_CUBE_MAP_POSITIVE_Z
00104     //      GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
00105     GLenum      _SSurfaceTarget;
00106     int        _SMipLevel;
00107     int        _SSlice;                     // for volume texture
00108 
00109     SURFACE_LOCKED_RECT  _LockedRect;
00110     SURFACE_RECT        _Rect;
00111     int            _CompressedDataSize;
00112 
00113     IOpenGLBaseTexture *_BaseTexture;
00114     bool            _Initialized;
00115 
00116     int _AllocatedUnpackBuffer;
00117     friend class IOpenGLTexture2D;
00118     friend class IOpenGLRectangleTexture;
00119     friend class IOpenGLCubeTexture;
00120     friend class IOpenGLVolumeTexture;
00121     friend class IOpenGLAnimatedTexture;
00122     friend class ObjectPtr<IOpenGLSurface>;
00123   };
00124 
00125 }
00126 
00127 #endif // IOPENGLSURFACE_H
00128