Path: blob/master/libmupen64plus/mupen64plus-video-glide64mk2/src/Glide64/Util.h
2 views
/*1* Glide64 - Glide video plugin for Nintendo 64 emulators.2* Copyright (c) 2002 Dave20013* Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the Free Software17* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA18*/1920//****************************************************************21//22// Glide64 - Glide Plugin for Nintendo 64 emulators23// Project started on December 29th, 200124//25// Authors:26// Dave2001, original author, founded the project in 2001, left it in 200227// Gugaman, joined the project in 2002, left it in 200228// Sergey 'Gonetz' Lipski, joined the project in 2002, main author since fall of 200229// Hiroshi 'KoolSmoky' Morii, joined the project in 200730//31//****************************************************************32//33// To modify Glide64:34// * Write your name and (optional)email, commented by your work, so I know who did it, and so that you can find which parts you modified when it comes time to send it to me.35// * Do NOT send me the whole project or file that you modified. Take out your modified code sections, and tell me where to put them. If people sent the whole thing, I would have many different versions, but no idea how to combine them all.36//37//****************************************************************3839#ifndef Util_H40#define Util_H4142#define NOT_TMU0 0x0043#define NOT_TMU1 0x0144#define NOT_TMU2 0x024546void util_init ();47void render_tri (wxUint16 linew = 0);4849int cull_tri (VERTEX **v);50void draw_tri (VERTEX **v, wxUint16 linew = 0);51void do_triangle_stuff (wxUint16 linew = 0, int old_interpolate = TRUE);52void do_triangle_stuff_2 (wxUint16 linew = 0);53void add_tri (VERTEX *v, int n, int type);54void apply_shade_mods (VERTEX *v);5556void update ();57void update_scissor ();5859void set_message_combiner ();6061float ScaleZ(float z);6263// positional and texel coordinate clipping64#define CCLIP(ux,lx,ut,lt,uc,lc) \65if (ux > lx || lx < uc || ux > lc) { rdp.tri_n += 2; return; } \66if (ux < uc) { \67float p = (uc-ux)/(lx-ux); \68ut = p*(lt-ut)+ut; \69ux = uc; \70} \71if (lx > lc) { \72float p = (lc-ux)/(lx-ux); \73lt = p*(lt-ut)+ut; \74lx = lc; \75}7677#define CCLIP2(ux,lx,ut,lt,un,ln,uc,lc) \78if (ux > lx || lx < uc || ux > lc) { rdp.tri_n += 2; return; } \79if (ux < uc) { \80float p = (uc-ux)/(lx-ux); \81ut = p*(lt-ut)+ut; \82un = p*(ln-un)+un; \83ux = uc; \84} \85if (lx > lc) { \86float p = (lc-ux)/(lx-ux); \87lt = p*(lt-ut)+ut; \88ln = p*(ln-un)+un; \89lx = lc; \90}9192#if defined(__GNUC__)93#define bswap32(x) __builtin_bswap32(x)94#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))95#include <stdlib.h>96#define bswap32(x) _byteswap_ulong(x)97#else98static inline uint32_t bswap32(uint32_t val)99{100return (((val & 0xff000000) >> 24) |101((val & 0x00ff0000) >> 8) |102((val & 0x0000ff00) << 8) |103((val & 0x000000ff) << 24));104}105#endif106107#define ALOWORD(x) (*((uint16_t*)&(x))) // low word108109template<class T> static inline T __ROR__(T value, unsigned int count)110{111const unsigned int nbits = sizeof(T) * 8;112count %= nbits;113114T low = value << (nbits - count);115value >>= count;116value |= low;117return value;118}119120// rotate left121template<class T> static T __ROL__(T value, unsigned int count)122{123const unsigned int nbits = sizeof(T) * 8;124count %= nbits;125126T high = value >> (nbits - count);127value <<= count;128value |= high;129return value;130}131132#endif // ifndef Util_H133134135