1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     demo_GraphicsMemoryAllocator.h
4 
5   Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Revision: 23208 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NW_DEMO_GRAPHICS_MEMORY_H_
17 #define NW_DEMO_GRAPHICS_MEMORY_H_
18 
19 #include <nw/types.h>
20 #include <GLES2/gl2.h>
21 #include <GLES2/gl2ext.h>
22 #include <nw/demo/demo_Memory.h>
23 #include <nn/fnd.h>
24 
25 
26 namespace nw
27 {
28 namespace demo
29 {
30 
31 //---------------------------------------------------------------------------
32 //! @brief        グラフィックス用のメモリを管理するクラスです。
33 //---------------------------------------------------------------------------
34 class GraphicsMemoryAllocator
35 {
36 public:
37     //---------------------------------------------------------------------------
38     //! @brief        グラフィックスメモリアロケータの初期化を行います。
39     //---------------------------------------------------------------------------
40     void    Initialize(os::IAllocator* allocator);
41 
42     //---------------------------------------------------------------------------
43     //! @brief        グラフィックスメモリアロケータの終了処理を行います。
44     //---------------------------------------------------------------------------
45     void    Finalize();
46 
47     //---------------------------------------------------------------------------
48     //! @brief        グラフィックスメモリの確保を行います。
49     //!
50     //! @param[in]    area    メモリを確保する領域です。
51     //! @param[in]    aim     メモリの使用用途です。
52     //! @param[in]    id      オブジェクトの名前です。
53     //! @param[in]    size    確保するサイズです。
54     //!
55     //! @return       確保したメモリのアドレスを返します。
56     //---------------------------------------------------------------------------
57     void*   Allocate(GLenum area, GLenum aim, GLuint id, GLsizei size);
58 
59     //---------------------------------------------------------------------------
60     //! @brief        グラフィックスメモリの解放を行います。
61     //!
62     //! @param[in]    area    メモリを解放する領域です。
63     //! @param[in]    aim     メモリの使用用途です。
64     //! @param[in]    id      オブジェクトの名前です。
65     //! @param[in]    addr    解放するアドレスです。
66     //---------------------------------------------------------------------------
67     void    Deallocate(GLenum area, GLenum aim, GLuint id, void* addr);
68 
69     //----------------------------------------
70     //! @name コンストラクタ/デストラクタ
71     //@{
72 
73     //! コンストラクタです。
GraphicsMemoryAllocator()74     GraphicsMemoryAllocator()
75      : m_Initialized( false ),
76        m_CurrentAddrVramA( NULL ),
77        m_CurrentAddrVramB( NULL ),
78        m_DeviceMemoryAllocator( NULL )
79        {}
80     //! デストラクタです。
~GraphicsMemoryAllocator()81     virtual ~GraphicsMemoryAllocator() { Finalize(); }
82     //@}
83 
84 private:
85     bool m_Initialized;
86 
87     uptr m_CurrentAddrVramA;
88     uptr m_CurrentAddrVramB;
89 
90     os::IAllocator* m_DeviceMemoryAllocator;
91 
MathRoundup(uptr x,int base)92     uptr MathRoundup(uptr x, int base)
93     {
94         return ((x) + ((base)-1)) & ~((base)-1);
95     }
96 };
97 
98 } // namespace demo
99 } // namespace nw
100 
101 #endif      // NW_DEMO_GRAPHICS_MEMORY_H_
102