project64/Source/Project64-video/Util.h

105 lines
2.6 KiB
C
Raw Permalink Normal View History

2021-03-02 02:13:17 +00:00
// Project64 - A Nintendo 64 emulator
// http://www.pj64-emu.com/
// Copyright(C) 2001-2021 Project64
// Copyright(C) 2003-2009 Sergey 'Gonetz' Lipski
// Copyright(C) 2002 Dave2001
// GNU/GPLv2 licensed: https://gnu.org/licenses/gpl-2.0.htmlfs
2017-04-26 10:23:36 +00:00
#pragma once
2013-04-04 21:22:19 +00:00
#define NOT_TMU0 0x00
#define NOT_TMU1 0x01
#define NOT_TMU2 0x02
void util_init();
2013-04-04 21:22:19 +00:00
int cull_tri(gfxVERTEX **v);
void draw_tri(gfxVERTEX **v, uint16_t linew = 0);
void do_triangle_stuff(uint16_t linew = 0, int old_interpolate = TRUE);
void do_triangle_stuff_2(uint16_t linew = 0);
void apply_shade_mods(gfxVERTEX *v);
2013-04-04 21:22:19 +00:00
void update();
void update_scissor();
2013-04-04 21:22:19 +00:00
2017-04-26 10:23:36 +00:00
void set_message_combiner(void);
2013-04-04 21:22:19 +00:00
float ScaleZ(float z);
// positional and texel coordinate clipping
#define CCLIP(ux,lx,ut,lt,uc,lc) \
if (ux > lx || lx < uc || ux > lc) { rdp.tri_n += 2; return; } \
if (ux < uc) { \
float p = (uc-ux)/(lx-ux); \
ut = p*(lt-ut)+ut; \
ux = uc; \
} \
2013-04-04 21:22:19 +00:00
if (lx > lc) { \
float p = (lc-ux)/(lx-ux); \
lt = p*(lt-ut)+ut; \
lx = lc; \
}
2013-04-04 21:22:19 +00:00
#define CCLIP2(ux,lx,ut,lt,un,ln,uc,lc) \
if (ux > lx || lx < uc || ux > lc) { rdp.tri_n += 2; return; } \
if (ux < uc) { \
float p = (uc-ux)/(lx-ux); \
ut = p*(lt-ut)+ut; \
un = p*(ln-un)+un; \
ux = uc; \
} \
2013-04-04 21:22:19 +00:00
if (lx > lc) { \
float p = (lc-ux)/(lx-ux); \
lt = p*(lt-ut)+ut; \
ln = p*(ln-un)+un; \
lx = lc; \
}
2013-04-04 21:22:19 +00:00
#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
#include <stdlib.h>
#define bswap32(x) _byteswap_ulong(x)
#else
static inline uint32_t bswap32(uint32_t val)
{
return (((val & 0xff000000) >> 24) |
2017-04-26 10:23:36 +00:00
((val & 0x00ff0000) >> 8) |
((val & 0x0000ff00) << 8) |
((val & 0x000000ff) << 24));
}
#endif
#define ALOWORD(x) (*((uint16_t*)&(x))) // low word
static inline uint16_t __ROR__(uint16_t value, unsigned int count)
{
const unsigned int nbits = sizeof(uint16_t) * 8;
count %= nbits;
uint16_t low = (value << (nbits - count)) & 0xFFFF;
value >>= count;
value |= low;
return value;
}
template<class T> static inline T __ROR__(T value, unsigned int count)
{
const unsigned int nbits = sizeof(T) * 8;
count %= nbits;
T low = value << (nbits - count);
value >>= count;
value |= low;
return value;
}
// rotate left
template<class T> static T __ROL__(T value, unsigned int count)
{
const unsigned int nbits = sizeof(T) * 8;
count %= nbits;
T high = value >> (nbits - count);
value <<= count;
value |= high;
return value;
}