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