1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     dev_Utility.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: 22599 $
14  *---------------------------------------------------------------------------*/
15 
16 #include <nw/dev/dev_Utility.h>
17 
18 #if defined(NW_DEV_ENABLED)
19 
20 #include <nw/ut/ut_Inlines.h>
21 
22 #if defined(NW_PLATFORM_CTR)
23   #include <nn/svc/svc_StubDbg.h>
24 #else
25   #include <windows.h>
26 #endif
27 
28 //--------------------------------------------------------------------------
29 void
NW_DEV_LOG(const char * fmt,...)30 NW_DEV_LOG( const char* fmt, ... )
31 {
32     const int BUFFER_SIZE = 260;
33     char buffer[ BUFFER_SIZE ];
34 
35     std::va_list vargs;
36     va_start(vargs, fmt);
37 
38     int len = nw::ut::vsnprintf(buffer, BUFFER_SIZE, BUFFER_SIZE - 1, fmt, vargs);
39 
40     va_end(vargs);
41 
42 #if defined(NW_PLATFORM_CTR)
43     nn::svc::OutputDebugString( buffer, len );
44 #else
45     OutputDebugStringA( buffer );
46 #endif
47 }
48 
49 namespace nw
50 {
51 namespace dev
52 {
53 
54 //--------------------------------------------------------------------------
55 int
FormatToByte(GLint format)56 FormatToByte(GLint format)
57 {
58     int byte = 0;
59 
60     switch (format)
61     {
62         case GL_RGBA8_OES:
63         {
64             byte = 4;
65         }
66         break;
67         case GL_RGB8_OES:
68         {
69             byte = 3;
70         }
71         break;
72         case GL_RGBA4:
73         {
74             byte = 2;
75         }
76         break;
77         case GL_RGB5_A1:
78         {
79             byte = 2;
80         }
81         break;
82         case GL_RGB565:
83         {
84             byte = 2;
85         }
86         break;
87         default:
88         {
89             NW_ASSERTMSG(false, "Invalid Color Format.");
90         }
91         break;
92     }
93 
94     return byte;
95 }
96 
97 //--------------------------------------------------------------------------
98 int
CalcMemorySize(GLint format,int width,int height)99 CalcMemorySize(GLint format, int width, int height)
100 {
101     int pixelSize = FormatToByte(format);
102 
103     return width * height * pixelSize;
104 }
105 
106 } // namespace nw::dev
107 } // namespace nw
108 
109 #endif
110