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