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