1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: font_RectDrawerCommand.h 4 5 Copyright (C)2009-2012 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: 46347 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NN_FONT_CTR_FONT_RECT_DRAWER_COMMAND_H_ 17 #define NN_FONT_CTR_FONT_RECT_DRAWER_COMMAND_H_ 18 19 #include <nn/util/util_Float24.h> 20 21 // Accumulate on the command list. 22 #define NN_FONT_ADD_COMMANDS_PTR( ptr, command, size ) \ 23 std::memcpy( ptr, command, size ); \ 24 (ptr) += (size) >> 2 25 26 #define NN_FONT_ADD_SINGLE_COMMAND_PTR( ptr, header, data ) \ 27 *(ptr)++ = (data); \ 28 *(ptr)++ = (header) 29 30 #define NN_FONT_RECTDRAWER_ADD_COMMAND( command, size ) \ 31 std::memcpy( __cb_current_command_buffer, command, size ); \ 32 __cb_current_command_buffer += (size) >> 2 33 34 #define NN_FONT_RECTDRAWER_ADD_SINGLE_COMMAND( header, data ) \ 35 *__cb_current_command_buffer++ = (data); \ 36 *__cb_current_command_buffer++ = (header) 37 38 39 //--------------------------------------------------------------------------- 40 // 41 //--------------------------------------------------------------------------- 42 enum 43 { 44 NN_FONT_CMD_CULL_FACE_DISABLE, 45 NN_FONT_CMD_CULL_FACE_FRONT, 46 NN_FONT_CMD_CULL_FACE_BACK, 47 48 NN_FONT_CMD_CULL_FACE_MASK = 0x3 49 }; 50 51 52 namespace nn { 53 namespace font { 54 namespace CTR { 55 56 //--------------------------------------------------------------------------- 57 // 58 //--------------------------------------------------------------------------- 59 struct ColorBufferInfo 60 { 61 u16 width; // 62 u16 height; // 63 u8 depth; // 64 NN_PADDING3; 65 }; 66 67 } // namespace CTR 68 } // namespace font 69 } // namespace nn 70 71 //--------------------------------------------------------------------------- 72 // 73 //--------------------------------------------------------------------------- 74 #define NN_FONT_CMD_BEGIN_COMMAND_BLOCK \ 75 { \ 76 const u32 commands[] = { 77 78 //--------------------------------------------------------------------------- 79 // 80 //--------------------------------------------------------------------------- 81 #define NN_FONT_CMD_END_COMMAND_BLOCK \ 82 }; \ 83 NN_FONT_RECTDRAWER_ADD_COMMAND( commands, sizeof(commands) ); \ 84 } 85 86 //--------------------------------------------------------------------------- 87 // 88 // 89 // 90 // 91 // 92 // 93 // 94 // 95 // 96 //--------------------------------------------------------------------------- 97 #define NN_FONT_CMD_SET_VIEWPORT( x, y, width, height ) \ 98 nn::util::Float24::Float32ToBits24( (width) / 2.0f ), \ 99 PICA_CMD_HEADER_BURSTSEQ( PICA_REG_VIEWPORT_WIDTH1, 4 ), \ 100 nn::util::Float31::Float32ToBits31( 2.0f / (width) ) << 1, \ 101 nn::util::Float24::Float32ToBits24( (height) / 2.0f ), \ 102 nn::util::Float31::Float32ToBits31( 2.0f / (height) ) << 1, \ 103 0, /* Alignment adjustment */ \ 104 PICA_CMD_DATA_VIEWPORT_XY( static_cast<u16>(x), static_cast<u16>(y) ), \ 105 PICA_CMD_HEADER_SINGLE( PICA_REG_VIEWPORT_XY ) 106 107 //--------------------------------------------------------------------------- 108 // 109 // 110 // 111 //--------------------------------------------------------------------------- 112 #define NN_FONT_CMD_SET_CULL_FACE( mode ) PICA_CMD_SET_CULL_FACE( mode ) 113 114 115 #define NN_FONT_CMD_SCISSOR_VAL( s, c ) \ 116 static_cast<u16>( (s) >= (c) ? (c) - 1: ((s) < 0 ? 0: (s)) ) 117 118 //--------------------------------------------------------------------------- 119 // 120 // 121 // 122 // 123 // 124 // 125 // 126 // 127 // 128 // 129 // 130 // 131 //--------------------------------------------------------------------------- 132 #define NN_FONT_CMD_SET_SCISSOR( x, y, w, h, cbSz ) \ 133 PICA_CMD_DATA_SCISSOR( true ), \ 134 PICA_CMD_HEADER_BURSTSEQ( PICA_REG_SCISSOR, 3 ), \ 135 NN_FONT_CMD_SCISSOR_VAL( x, (cbSz).width ) \ 136 | NN_FONT_CMD_SCISSOR_VAL( y, (cbSz).height ) << 16, \ 137 NN_FONT_CMD_SCISSOR_VAL( (x) + (w) - 1, (cbSz).width ) \ 138 | NN_FONT_CMD_SCISSOR_VAL( (y) + (h) - 1, (cbSz).height ) << 16 139 140 //--------------------------------------------------------------------------- 141 // 142 // 143 // 144 // 145 // 146 // 147 //--------------------------------------------------------------------------- 148 #define NN_FONT_CMD_SET_DISABLE_SCISSOR( cbSz ) \ 149 PICA_CMD_DATA_SCISSOR( false ), \ 150 PICA_CMD_HEADER_BURSTSEQ( PICA_REG_SCISSOR, 3 ), \ 151 0 | 0 << 16, \ 152 ((cbSz).width - 1) | ((cbSz).height - 1) << 16 153 154 //--------------------------------------------------------------------------- 155 // 156 // 157 // 158 // 159 // 160 // 161 // 162 // 163 // 164 // 165 // 166 // 167 //--------------------------------------------------------------------------- 168 #define NN_FONT_CMD_SET_WBUFFER_DEPTHRANGE_POLYGONOFFSET( \ 169 wScale, near, far, units, cbSz ) \ 170 ((wScale) == 0.0f ? 1: 0) << 0, \ 171 PICA_CMD_HEADER_SINGLE( PICA_REG_FRAG_OP_WSCALE ), \ 172 nn::util::Float24::Float32ToBits24( \ 173 (wScale) != 0.0f ? -(wScale): (near) - (far) ), \ 174 PICA_CMD_HEADER_SINGLE( PICA_REG_FRAG_OP_WSCALE_DATA1 ), \ 175 nn::util::Float24::Float32ToBits24( \ 176 (near) \ 177 - ((near) - (far)) * static_cast<f32>(units) \ 178 / ((1 << ((cbSz).depth == PICA_DATA_DEPTH_COMPONENT16 ? 16: 24)) - 1) ), \ 179 PICA_CMD_HEADER_SINGLE( PICA_REG_FRAG_OP_WSCALE_DATA2 ) 180 181 //--------------------------------------------------------------------------- 182 // 183 // 184 // 185 // 186 // 187 // 188 //--------------------------------------------------------------------------- 189 #define NN_FONT_CMD_SET_ENABLE_EARLY_DEPTH_TEST( isEnabled ) \ 190 PICA_CMD_DATA_EARLY_DEPTH_TEST( isEnabled ), \ 191 PICA_CMD_HEADER_SINGLE_BE( PICA_REG_EARLY_DEPTH_TEST1, 0x1 ), \ 192 PICA_CMD_DATA_EARLY_DEPTH_TEST( isEnabled ), \ 193 PICA_CMD_HEADER_SINGLE( PICA_REG_EARLY_DEPTH_TEST2 ) 194 195 //--------------------------------------------------------------------------- 196 // 197 // 198 // 199 // 200 // 201 // 202 // 203 // 204 // 205 // 206 // 207 // 208 //--------------------------------------------------------------------------- 209 #define NN_FONT_CMD_SET_STENCIL_FUNC_MASK( func, ref, andBits, writableBits ) \ 210 PICA_CMD_DATA_STENCIL_TEST( true/*isEnabled*/, func, writableBits, ref, andBits ), \ 211 PICA_CMD_HEADER_SINGLE( PICA_REG_STENCIL_TEST ) 212 213 //--------------------------------------------------------------------------- 214 // 215 // 216 // 217 // 218 // 219 // 220 // 221 // 222 //--------------------------------------------------------------------------- 223 #define NN_FONT_CMD_SET_STENCIL_OP( sfail, zfail, zpass ) \ 224 PICA_CMD_DATA_STENCIL_OP( sfail, zfail, zpass ), \ 225 PICA_CMD_HEADER_SINGLE( PICA_REG_STENCIL_OP ) 226 227 //--------------------------------------------------------------------------- 228 // 229 // 230 // 231 // 232 //--------------------------------------------------------------------------- 233 #define NN_FONT_CMD_SET_DISABLE_STENCIL_TEST() \ 234 PICA_CMD_DATA_STENCIL_TEST( false/*isEnabled*/, 0, 0, 0, 0 ), \ 235 PICA_CMD_HEADER_SINGLE( PICA_REG_STENCIL_TEST ) 236 237 //--------------------------------------------------------------------------- 238 // 239 // 240 // 241 // 242 // 243 // 244 // 245 // 246 // 247 // 248 // 249 // 250 // 251 // 252 // 253 // 254 // 255 //--------------------------------------------------------------------------- 256 #define NN_FONT_CMD_SET_DEPTH_FUNC_COLOR_MASK( \ 257 isDepthTestEnabled, depthFunc, depthMask, red, green, blue, alpha ) \ 258 PICA_CMD_DATA_DEPTH_COLOR_MASK( isDepthTestEnabled, depthFunc, \ 259 red, green, blue, alpha, depthMask ), \ 260 PICA_CMD_HEADER_SINGLE( PICA_REG_DEPTH_COLOR_MASK ) 261 262 //--------------------------------------------------------------------------- 263 // 264 // 265 // 266 // 267 // 268 // 269 // 270 //--------------------------------------------------------------------------- 271 #define NN_FONT_CMD_SET_DEPTH_FUNC2( func ) \ 272 PICA_CMD_DATA_GAS_DELTAZ_DEPTH( 0 /*deltaZ*/, \ 273 (func) >= PICA_DATA_DEPTH_TEST_GREATER ? PICA_DATA_DEPTH_TEST2_GREATER: \ 274 ( (func) >= PICA_DATA_DEPTH_TEST_EQUAL ? PICA_DATA_DEPTH_TEST2_OTHER: (func) ) ), \ 275 PICA_CMD_HEADER_SINGLE_BE( PICA_REG_GAS_DELTAZ_DEPTH, 0x4 ) 276 277 //--------------------------------------------------------------------------- 278 // 279 // 280 // 281 // 282 // 283 // 284 // 285 // 286 //--------------------------------------------------------------------------- 287 #define NN_FONT_CMD_SET_FBACCESS( \ 288 colorRead, colorWrite, depthRead, depthWrite, stencilRead, stencilWrite) \ 289 (colorRead ) ? 0xF: 0, \ 290 PICA_CMD_HEADER_BURSTSEQ( PICA_REG_COLOR_BUFFER_READ, 4 ), \ 291 (colorWrite) ? 0xF: 0, \ 292 ((depthRead ) ? 1: 0) << 1 | ((stencilRead ) ? 1: 0) << 0, \ 293 ((depthWrite) ? 1: 0) << 1 | ((stencilWrite) ? 1: 0) << 0, \ 294 0 // Alignment adjustment 295 296 297 #endif // NN_FONT_CTR_FONT_RECT_DRAWER_COMMAND_H_ 298