1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: gfx_IRenderTarget.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: 24994 $
14 *---------------------------------------------------------------------------*/
15
16 #include "precompiled.h"
17
18 #include <nw/gfx/gfx_IRenderTarget.h>
19
20 #include <nw/gfx/gfx_OnScreenBuffer.h>
21 #include <nw/gfx/gfx_OffScreenBuffer.h>
22
23 namespace nw
24 {
25 namespace gfx
26 {
27
28 NW_UT_RUNTIME_TYPEINFO_ROOT_DEFINITION(IRenderTarget);
29
30 //----------------------------------------
31 IRenderTarget*
Create(os::IAllocator * allocator)32 IRenderTarget::Builder::Create(os::IAllocator* allocator)
33 {
34 NW_NULL_ASSERT(allocator);
35 IRenderTarget* renderTarget = NULL;
36
37 const int renderTargetAlignment = 32;
38 void* memory = allocator->Alloc(sizeof(OnScreenBuffer), renderTargetAlignment);
39 NW_NULL_ASSERT(memory);
40
41 renderTarget = new(memory) OnScreenBuffer(allocator, m_Description);
42
43 return renderTarget;
44 }
45
46 //----------------------------------------
47 IRenderTarget*
CreateOffScreenBuffer(os::IAllocator * allocator,ResTexture resTexture)48 IRenderTarget::CreateOffScreenBuffer(os::IAllocator* allocator, ResTexture resTexture)
49 {
50 NW_NULL_ASSERT(allocator);
51 IRenderTarget* renderTarget = NULL;
52
53 const int renderTargetAlignment = 32;
54 void* memory = allocator->Alloc(sizeof(OffScreenBuffer), renderTargetAlignment);
55 NW_NULL_ASSERT(memory);
56
57 ResPixelBasedTexture texture = ResStaticCast<ResPixelBasedTexture>(resTexture.Dereference());
58
59 const RenderColorFormat formatTable[] =
60 {
61 RENDER_COLOR_FORMAT_RGBA8,
62 RENDER_COLOR_FORMAT_RGB8,
63 RENDER_COLOR_FORMAT_RGB5_A1,
64 RENDER_COLOR_FORMAT_RGB565,
65 RENDER_COLOR_FORMAT_RGBA4,
66 RENDER_COLOR_FORMAT_NONE,
67 RENDER_COLOR_FORMAT_NONE,
68 RENDER_COLOR_FORMAT_NONE,
69 RENDER_COLOR_FORMAT_NONE,
70 RENDER_COLOR_FORMAT_NONE,
71 RENDER_COLOR_FORMAT_NONE,
72 RENDER_COLOR_FORMAT_NONE,
73 RENDER_COLOR_FORMAT_NONE,
74 RENDER_COLOR_FORMAT_NONE
75 };
76
77 Description description;
78 description.width = texture.GetWidth();
79 description.height = texture.GetHeight();
80 description.colorFormat = formatTable[texture.GetFormatHW()];
81 NW_ASSERT(description.colorFormat != RENDER_COLOR_FORMAT_NONE);
82 description.colorArea = (GraphicsMemoryArea)(texture.GetLocationFlag() & (MEMORY_AREA_FCRAM | MEMORY_AREA_VRAMA | MEMORY_AREA_VRAMB));
83
84 description.depthFormat = RENDER_DEPTH_FORMAT_NONE;
85 description.depthArea = MEMORY_AREA_NONE;
86
87 switch (texture.GetTypeInfo())
88 {
89 case ResImageTexture::TYPE_INFO:
90 {
91 description.shadowKind = SHADOW_KIND_NONE;
92 }
93 break;
94 case ResCubeTexture::TYPE_INFO:
95 {
96 description.shadowKind = SHADOW_KIND_NONE;
97 }
98 break;
99 case ResShadowTexture::TYPE_INFO:
100 {
101 description.shadowKind = SHADOW_KIND_TEXTURE;
102 }
103 break;
104 default:
105 {
106 NW_FATAL_ERROR("Unsupported texture type.\n");
107 }
108 break;
109 }
110
111 renderTarget = new(memory) OffScreenBuffer(allocator, description, texture);
112
113 return renderTarget;
114 }
115
116 } // namespace gfx
117 } // namespace nw
118
119