1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_IRenderTarget.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_GFX_IRENDERTARGET_H_
19 #define NW_GFX_IRENDERTARGET_H_
20 
21 #include <nw/gfx/gfx_GfxObject.h>
22 #include <nw/ut/ut_RuntimeTypeInfo.h>
23 #include <nw/gfx/gfx_Common.h>
24 #include <nw/gfx/gfx_FrameBuffer.h>
25 #include <nw/gfx/res/gfx_ResTexture.h>
26 
27 #include <GLES2/gl2.h>
28 #include <GLES2/gl2ext.h>
29 #include <nn/gx/CTR/gx_CTR.h>
30 
31 namespace nw
32 {
33 namespace gfx
34 {
35 namespace res
36 {
37 class ResTexture;
38 }
39 
40 //---------------------------------------------------------------------------
41 //! @brief        バッファのフォーマットの定義です。
42 //---------------------------------------------------------------------------
43 enum RenderColorFormat
44 {
45     RENDER_COLOR_FORMAT_NONE,
46     RENDER_COLOR_FORMAT_RGBA8 = GL_RGBA8_OES,
47     RENDER_COLOR_FORMAT_RGB8 = GL_RGB8_OES,
48     RENDER_COLOR_FORMAT_RGBA4 = GL_RGBA4,
49     RENDER_COLOR_FORMAT_RGB5_A1 = GL_RGB5_A1,
50     RENDER_COLOR_FORMAT_RGB565 = GL_RGB565,
51     RENDER_COLOR_FORMAT_COUNT
52 };
53 
54 enum RenderDepthFormat
55 {
56     RENDER_DEPTH_FORMAT_NONE,
57     RENDER_DEPTH_FORMAT_16 = GL_DEPTH_COMPONENT16,
58     RENDER_DEPTH_FORMAT_24 = GL_DEPTH_COMPONENT24_OES,
59     RENDER_DEPTH_FORMAT_24_STENCIL8 = GL_DEPTH24_STENCIL8_EXT,
60     RENDER_DEPTH_FORMAT_COUNT
61 };
62 
63 namespace internal
64 {
65     enum
66     {
67         MEMORY_AREA_FCRAM_INTERNAL = NN_GX_MEM_FCRAM,
68         MEMORY_AREA_VRAMA_INTERNAL = NN_GX_MEM_VRAMA,
69         MEMORY_AREA_VRAMB_INTERNAL = NN_GX_MEM_VRAMB
70     };
71 }
72 
73 //---------------------------------------------------------------------------
74 //! @brief        グラフィックスメモリ領域を表す定義です。
75 //---------------------------------------------------------------------------
76 enum GraphicsMemoryArea
77 {
78     MEMORY_AREA_NONE,
79     MEMORY_AREA_FCRAM = internal::MEMORY_AREA_FCRAM_INTERNAL, //!< FCRAMの領域を表します。
80     MEMORY_AREA_VRAMA = internal::MEMORY_AREA_VRAMA_INTERNAL, //!< VRAMのAチャンネルの領域を表します。
81     MEMORY_AREA_VRAMB = internal::MEMORY_AREA_VRAMB_INTERNAL, //!< VRAMのBチャンネルの領域を表します。
82     GRAPHICS_MEMORY_AREA_COUNT                                //!< メモリ領域の種類の数を表します。
83 };
84 
85 //! シャドウの種別です。
86 enum ShadowKind
87 {
88     SHADOW_KIND_NONE,
89     SHADOW_KIND_TEXTURE,
90     SHADOW_KIND_CUBE
91 };
92 
93 //---------------------------------------------------------------------------
94 //! @brief        描画対象を表すインターフェースです。
95 //---------------------------------------------------------------------------
96 class IRenderTarget : public GfxObject
97 {
98 public:
99     NW_UT_RUNTIME_TYPEINFO;
100 
101     //----------------------------------------
102     //! @name 作成
103     //@{
104 
105     //! 描画対象の設定内容です。
106     struct Description
107     {
108         s32 width; //!< 描画対象の幅です。
109         s32 height; //!< 描画対象の高さです。
110         RenderColorFormat colorFormat; //!< 描画対象のカラーフォーマットです。
111         RenderDepthFormat depthFormat; //!< 描画対象の深度フォーマットです。
112         GraphicsMemoryArea colorArea;  //!< 描画対象のカラーバッファの配置場所です。
113         GraphicsMemoryArea depthArea;  //!< 描画対象のデプスバッファの配置場所です。
114         u32 colorAddress;              //!< 描画対象のカラーバッファのアドレスを直接指定します。
115         u32 depthAddress;              //!< 描画対象のデプスバッファのアドレスを直接指定します。
116         ShadowKind shadowKind;         //!< シャドウの種別です。
117 
118         //! コンストラクタです。
DescriptionDescription119         Description()
120         : width(400),
121           height(240),
122           colorFormat(RENDER_COLOR_FORMAT_RGBA8),
123           depthFormat(RENDER_DEPTH_FORMAT_24_STENCIL8),
124           colorArea(MEMORY_AREA_VRAMA),
125           depthArea(MEMORY_AREA_VRAMB),
126           colorAddress(NULL),
127           depthAddress(NULL),
128           shadowKind(SHADOW_KIND_NONE)
129         {}
130     };
131 
132     //! 描画対象を生成するためのクラスです。
133     class Builder
134     {
135     public:
136 
137         //! @brief        設定内容を設定します。
138         //!
139         //! @param[in]    description 設定内容です。
140         //!
Described(const Description & description)141         Builder& Described(const Description& description)
142         {
143             m_Description = description;
144             return *this;
145         }
146 
147         //! @brief        描画バッファのサイズを設定します。
148         //!
149         //! @param[in]    width 描画幅です。
150         //! @param[in]    height 描画高さです。
151         //!
BufferSize(s32 width,s32 height)152         Builder& BufferSize(s32 width, s32 height)
153         {
154             m_Description.width = width;
155             m_Description.height = height;
156             return *this;
157         }
158 
159         //! 描画バッファの幅を設定します。
Width(s32 width)160         Builder& Width(s32 width) { m_Description.width = width; return *this; }
161 
162         //! 描画バッファの高さを設定します。
Height(s32 height)163         Builder& Height(s32 height) { m_Description.height = height; return *this; }
164 
165         //! 描画バッファの色の形式を設定します。
ColorFormat(RenderColorFormat format)166         Builder& ColorFormat(RenderColorFormat format)
167         {
168             m_Description.colorFormat = format;
169             return *this;
170         }
171 
172         //! 描画バッファの深度の形式を設定します。
DepthFormat(RenderDepthFormat format)173         Builder& DepthFormat(RenderDepthFormat format)
174         {
175             m_Description.depthFormat = format;
176             return *this;
177         }
178 
179         //! @brief カラーバッファのメモリ配置場所を設定します。
180         //!
181         //! MEMORY_AREA_VRAMA か MEMORY_AREA_VRAMB を設定する必要があります。
ColorArea(GraphicsMemoryArea memory)182         Builder& ColorArea(GraphicsMemoryArea memory)
183         {
184             m_Description.colorArea = memory;
185             return *this;
186         }
187 
188         //! @brief デプスバッファのメモリ配置場所を設定します。
189         //!
190         //! MEMORY_AREA_VRAMA か MEMORY_AREA_VRAMB を設定する必要があります。
DepthArea(GraphicsMemoryArea memory)191         Builder& DepthArea(GraphicsMemoryArea memory)
192         {
193             m_Description.depthArea = memory;
194             return *this;
195         }
196 
197         //! @brief        カラーバッファのアドレスを直接設定します。
198         //!
199         //! この値を NULL 以外に設定した場合には、ColorArea の設定は無視します。
ColorAddress(u32 colorAddress)200         Builder& ColorAddress(u32 colorAddress)
201         {
202             m_Description.colorAddress = colorAddress;
203             return *this;
204         }
205 
206         //! @brief        デプスバッファのアドレスを直接設定します。
207         //!
208         //! この値を NULL 以外に設定した場合には、DepthArea の設定は無視します。
DepthAddress(u32 depthAddress)209         Builder& DepthAddress(u32 depthAddress)
210         {
211             m_Description.depthAddress = depthAddress;
212             return *this;
213         }
214 
215         //! @brief                  レンダーターゲットを生成します。
216         //!
217         //! @param[in] allocator    アロケータです。
218         //!
219         //! @return                 生成したレンダーターゲットを返します。
220         //!
221         IRenderTarget* Create(os::IAllocator* allocator);
222 
223     private:
224         Description m_Description;
225     };
226 
227     //! @brief オフスクリーンレンダリング用のレンダーターゲットを生成します。
228     //!
229     //! @param[in] allocator    アロケータです。
230     //! @param[in] resTexture   描画対象のテクスチャです。
231     //!
232     //! @return 生成したレンダーターゲットを返します。
233     static IRenderTarget* CreateOffScreenBuffer(os::IAllocator* allocator, ResTexture resTexture);
234 
235     //@}
236 
237     //----------------------------------------
238     //! @name 取得/設定
239     //@{
240 
241     //! 設定内容を取得します。
242     virtual const Description& GetDescription() const = 0;
243 
244     //! バッファオブジェクトを取得します。
245     virtual const FrameBufferObject& GetBufferObject() const = 0;
246 
247     //@}
248 
249 protected:
250     //----------------------------------------
251     //! @name コンストラクタ/デストラクタ
252     //@{
253 
254     //! コンストラクタです。
IRenderTarget(os::IAllocator * allocator)255     IRenderTarget(os::IAllocator* allocator) : GfxObject(allocator) {}
256 
257     //! デストラクタです。
~IRenderTarget()258     virtual ~IRenderTarget() {}
259 
260     //@}
261 };
262 
263 } // namespace gfx
264 } // namespace nw
265 
266 #endif // NW_GFX_IRENDERTARGET_H_
267