1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: gfx_OffScreenBuffer.cpp
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: 26052 $
14 *---------------------------------------------------------------------------*/
15
16 #include "precompiled.h"
17
18 #include <nw/gfx/gfx_OffScreenBuffer.h>
19
20 #include <nw/os/os_Memory.h>
21
22 #include <nn/gx.h>
23
24 namespace nw
25 {
26 namespace gfx
27 {
28 NW_UT_RUNTIME_TYPEINFO_DEFINITION(OffScreenBuffer, IRenderTarget);
29
30 //----------------------------------------
OffScreenBuffer(os::IAllocator * pAllocator,const Description & description,ResPixelBasedTexture resTexture)31 OffScreenBuffer::OffScreenBuffer(os::IAllocator* pAllocator, const Description& description, ResPixelBasedTexture resTexture)
32 : IRenderTarget(pAllocator),
33 m_ActivateCommand(NULL),
34 m_Description(description),
35 m_Texture(resTexture)
36 {
37 ResPixelBasedTexture resPixelBasedTexture = ResStaticCast<ResPixelBasedTexture>(resTexture);
38
39 NW_ASSERT(resPixelBasedTexture.GetTextureObject() != 0);
40
41 m_BackBufferObject.SetHeight( resTexture.GetHeight() );
42 m_BackBufferObject.SetWidth( resTexture.GetWidth() );
43
44 GLuint format;
45
46 switch ( resTexture.GetFormatHW() )
47 {
48 case ResPixelBasedTexture::FORMAT_HW_RGBA8: format = GL_RGBA8_OES; break;
49 case ResPixelBasedTexture::FORMAT_HW_RGBA5551: format = GL_RGB5_A1; break;
50 case ResPixelBasedTexture::FORMAT_HW_RGBA4: format = GL_RGBA4; break;
51 case ResPixelBasedTexture::FORMAT_HW_RGB565: format = GL_RGB565; break;
52 default:
53 NW_FATAL_ERROR("illegal texture format for OffScreenBuffer");
54 }
55
56 m_BackBufferObject.SetColorFormat( format );
57 m_BackBufferObject.SetDepthFormat( 0 );
58
59 switch (resTexture.GetTypeInfo())
60 {
61 case ResImageTexture::TYPE_INFO:
62 {
63 u32 address = ResStaticCast<ResImageTexture>(resTexture).GetImage().GetImageAddress();
64 m_BackBufferObject.SetColorAddress( address );
65 }
66 break;
67 case ResCubeTexture::TYPE_INFO:
68 {
69 ResCubeTexture::CubeFace face = ResCubeTexture::CUBE_FACE_POSITIVE_X;
70 u32 address = ResStaticCast<ResCubeTexture>(resTexture).GetImage( face ).GetImageAddress();
71
72 m_BackBufferObject.SetColorAddress( address );
73 }
74 break;
75 case ResShadowTexture::TYPE_INFO:
76 {
77 u32 address = ResStaticCast<ResShadowTexture>(resTexture).GetImage().GetImageAddress();
78 m_BackBufferObject.SetColorAddress( address );
79 }
80 break;
81 default:
82 {
83 NW_FATAL_ERROR("Unsupported texture type.\n");
84 }
85 break;
86 }
87 }
88
89 //----------------------------------------
~OffScreenBuffer()90 OffScreenBuffer::~OffScreenBuffer()
91 {
92 }
93
94 } // namespace gfx
95 } // namespace nw
96