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: 27432 $
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
83 u32 locationFlag = texture.GetLocationFlag();
84 locationFlag &= ~(GL_COPY_FCRAM_DMP | GL_NO_COPY_FCRAM_DMP);
85
86 NW_ASSERT(
87 (locationFlag == MEMORY_AREA_VRAMA) ||
88 (locationFlag == MEMORY_AREA_VRAMB));
89 description.colorArea = static_cast<GraphicsMemoryArea>(locationFlag);
90
91 description.depthFormat = RENDER_DEPTH_FORMAT_NONE;
92 description.depthArea = MEMORY_AREA_NONE;
93
94 switch (texture.GetTypeInfo())
95 {
96 case ResImageTexture::TYPE_INFO:
97 {
98 description.shadowKind = SHADOW_KIND_NONE;
99 }
100 break;
101 case ResCubeTexture::TYPE_INFO:
102 {
103 description.shadowKind = SHADOW_KIND_NONE;
104 }
105 break;
106 case ResShadowTexture::TYPE_INFO:
107 {
108 description.shadowKind = SHADOW_KIND_TEXTURE;
109 }
110 break;
111 default:
112 {
113 NW_FATAL_ERROR("Unsupported texture type.\n");
114 }
115 break;
116 }
117
118 renderTarget = new(memory) OffScreenBuffer(allocator, description, texture);
119
120 return renderTarget;
121 }
122
123 } // namespace gfx
124 } // namespace nw
125
126