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