1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     dev_CallbackChain.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: $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef NW_DEV_CALLBACK_CHAIN_H_
19 #define NW_DEV_CALLBACK_CHAIN_H_
20 
21 #include <nw/types.h>
22 #include <nw/os.h>
23 
24 #if defined(NW_PLATFORM_CTR)
25 #include <nn/gx.h>
26 #endif
27 
28 
29 namespace nw {
30 namespace dev {
31 
32 #if defined(NW_DEV_ENABLED) && defined(NW_PLATFORM_CTR)
33 
34 //---------------------------------------------------------------------------
35 //! @brief        GPUコマンドのコールバックチェインです。
36 //---------------------------------------------------------------------------
37 class CallbackChain
38 {
39 public:
40     //! @brief コンストラクタです。
41     CallbackChain( nw::os::IAllocator* allocator );
42 
43     //! @brief デストラクタです。
44     ~CallbackChain();
45 
46     //! @brief インスタンスを破棄します。
47     void Destroy();
48 
49     //! @brief バインドされているコマンドリストにコールバックを設定します。
50     void SetCallback();
51 
52     //! @brief コールバックチェイン処理を開始します。
53     void Begin();
54 
55     //! @brief コールバックチェイン処理を終了します。
56     void End();
57 
58     //! @brief GPU処理コストをmsecで取得します。
GetCostTime()59     f32 GetCostTime() const { return m_Cost; }
60 
61 private:
62     //! @brief コールバックの呼び出しです。
63     void Invoke(GLint id);
64 
65     //! @brief 登録されるコールバック関数です。
66     static void CommandListCallback(GLint id);
67 
68     f32     m_Cost;
69     uint    m_MaxRequestCount;
70     uint    m_StartReqCount;
71     uint    m_EndReqCount;
72     uint    m_CurrentReqCount;
73     s64*    m_MicroSecArray;
74 
75     os::IAllocator*     m_Allocator;
76 
77     static CallbackChain*   s_CallbackChain;
78 };
79 
80 #else
81 
82 class CallbackChain
83 {
84 public:
85     //! @brief コンストラクタです。
86     CallbackChain( nw::os::IAllocator* allocator ){}
87 
88     //! @brief デストラクタです。
89     ~CallbackChain(){}
90 
91     //! @brief インスタンスを破棄します。
92     void Destroy(){}
93 
94     //! @brief バインドされているコマンドリストにコールバックを設定します。
95     void SetCallback();
96 
97     //! @brief コールバックチェイン処理を開始します。
98     void Begin(){}
99 
100     //! @brief コールバックチェイン処理を終了します。
101     void End(){}
102 
103     //! @brief 前フレームのGPU処理コストをmsecで取得します。
104     f32 GetCostTime() const { return 0.f; }
105 };
106 
107 
108 #endif // defined(NW_DEV_ENABLED) && defined(NW_PLATFORM_CTR)
109 
110 } // namespace nw::dev
111 } // namespace nw
112 
113 #endif // NW_DEV_CALLBACK_CHAIN_H_
114 
115