SHARE
TWEET

pvr_cxt.h

a guest Apr 25th, 2019 25 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifndef PVR_CXT_GUARD
  2. #define PVR_CXT_GUARD
  3.  
  4. static inline unsigned int replace_bits(unsigned int src, unsigned int value, unsigned int start, unsigned int width)
  5. {
  6.     //int mask = (~(-1 << start)) << width;
  7.     int mask = -1 << start;
  8.     mask = mask ^ (mask << width);
  9.     value <<= start;
  10.    
  11.     //GCC generally combines multiple calls better with this, even though
  12.     //it takes one more operation
  13.     return (src & ~mask) | (value & mask);
  14.     //return ((src ^ value) & mask) ^ src;
  15. }
  16.  
  17. static inline unsigned int replace_bit(unsigned int src, unsigned int value, unsigned int start)
  18. {
  19.     return replace_bits(src, !!value, start, 1);
  20. }
  21.  
  22. typedef struct {
  23.     uint32  mode2;
  24.     uint32  tex;
  25. } pvr_context_submodes;
  26.  
  27. // Unified context
  28. typedef struct {
  29.     uint32  cmd;
  30.     uint32  mode1;
  31.     union {
  32.     struct {    //basic intensity
  33.         pvr_context_submodes m;
  34.         float a,r,g,b;
  35.     } bf;
  36.     struct {    //basic packed/sprite/float
  37.         pvr_context_submodes m;
  38.         uint32 color;
  39.         uint32 offset;
  40.         uint32 pad0, pad1;
  41.     } bp;
  42.     pvr_context_submodes mod[2];    //full modifier
  43.     };
  44. } pvr_context;
  45.  
  46. // Long intensity modifier context
  47. typedef struct {
  48.     pvr_context cxt;
  49.     float   a0, r0, g0, b0;
  50.     float   a1, r1, g1, b1;
  51. } pvr_context_ml;
  52.  
  53. //parameter types
  54. //Either 0 (false) or 1 (true)
  55. typedef int pc_boolean;
  56.  
  57. typedef enum {
  58.     PC_CMD_POLYGON = 4,
  59.     PC_CMD_MODIFIER = 4,
  60.     PC_CMD_SPRITE = 5,
  61. } pc_command;
  62.  
  63. typedef enum {
  64.     PC_NEVER,
  65.     PC_LESS,
  66.     PC_EQUAL,
  67.     PC_LEQUAL,
  68.     PC_GREATER,
  69.     PC_NOTEQUAL,
  70.     PC_GEQUAL,
  71.     PC_ALWAYS,
  72. } pc_depth_compare;
  73.  
  74. typedef enum {
  75.     PC_STRIP1,
  76.     PC_STRIP2,
  77.     PC_STRIP4,
  78.     PC_STRIP6,
  79. } pc_strip_length;
  80.  
  81. typedef enum {
  82.     PC_NO_CLIP,
  83.     PC_INSIDE_CLIP,
  84.     PC_OUTSIDE_CLIP,
  85. } pc_clip_mode;
  86.  
  87. typedef enum {
  88.     PC_PACKED,
  89.     PC_FLOAT,
  90.     PC_INTENSITY,
  91.     PC_CONSTANT
  92. } pc_color_format;
  93.  
  94. typedef enum {
  95.     PC_OPAQUE_POLY,
  96.     PC_OPAQUE_MOD,
  97.     PC_BLEND_POLY,
  98.     PC_BLEND_MOD,
  99.     PC_PUNCHTHROUGH,
  100. } pc_list_type;
  101.  
  102. typedef enum {
  103.     PC_CULL_DISABLE,
  104.     PC_CULL_SMALL,
  105.     PC_CULL_CCW,
  106.     PC_CULL_CW,
  107.     PC_CULL_ANTICW = PC_CULL_CCW,
  108. } pc_culling;
  109.  
  110. typedef enum {
  111.     PC_ZERO,
  112.     PC_ONE,
  113.     PC_OTHER_COLOR,
  114.     PC_INV_OTHER_COLOR,
  115.     PC_SRC_ALPHA,
  116.     PC_INV_SRC_ALPHA,
  117.     PC_DST_ALPHA,
  118.     PC_INV_DST_ALPHA,
  119. } pc_blend_mode;
  120.  
  121. typedef enum {
  122.     PC_POLYGON,
  123.     PC_ACCUMULATE_SRC,
  124. } pc_color_source;
  125.  
  126. typedef enum {
  127.     PC_FRAME_BUFFER,
  128.     PC_ACCUMULATE_DST,
  129. } pc_color_destination;
  130.  
  131. typedef enum {
  132.     PC_UV_NONE,
  133.     PC_UV_X,
  134.     PC_UV_Y,
  135.     PC_UV_XY,
  136. } pc_uv_control;
  137.  
  138. typedef enum {
  139.     PC_FOG_TABLE,
  140.     PC_FOG_VERTEX,
  141.     PC_FOG_DISABLE,
  142.     PC_FOG_TABLE2,
  143. } pc_fog_mode;
  144.  
  145. typedef enum {
  146.     PC_POINT,
  147.     PC_BILINEAR,
  148.     PC_TRILINEAR_1ST,
  149.     PC_TRILINEAR_2ND,
  150. } pc_texture_filter;
  151.  
  152. typedef enum {
  153.     PC_MIPMAP_BIAS_0_25 = 1,
  154.     PC_MIPMAP_BIAS_0_50,
  155.     PC_MIPMAP_BIAS_0_75,
  156.     PC_MIPMAP_BIAS_1_00,
  157.     PC_MIPMAP_BIAS_1_25,
  158.     PC_MIPMAP_BIAS_1_50,
  159.     PC_MIPMAP_BIAS_1_75,
  160.     PC_MIPMAP_BIAS_2_00,
  161.     PC_MIPMAP_BIAS_2_25,
  162.     PC_MIPMAP_BIAS_2_50,
  163.     PC_MIPMAP_BIAS_2_75,
  164.     PC_MIPMAP_BIAS_3_00,
  165.     PC_MIPMAP_BIAS_3_25,
  166.     PC_MIPMAP_BIAS_3_50,
  167.     PC_MIPMAP_BIAS_3_75,
  168. } pc_mipmap_bias;
  169.  
  170. typedef enum {
  171.     PC_TEXENV_REPLACE,
  172.     PC_TEXENV_MODULATE_REPLACE_ALPHA,
  173.     PC_TEXENV_DECAL,
  174.     PC_TEXENV_MODULATE,
  175. } pc_texture_environment;
  176.  
  177. typedef enum {
  178.     PC_SIZE_8,
  179.     PC_SIZE_16,
  180.     PC_SIZE_32,
  181.     PC_SIZE_64,
  182.     PC_SIZE_128,
  183.     PC_SIZE_256,
  184.     PC_SIZE_512,
  185.     PC_SIZE_1024,
  186. } pc_texture_size;
  187.  
  188. static inline int pc_size_to_log2(pc_texture_size size) {
  189.     return ((int)size)+3;
  190. }
  191.  
  192. static inline int pc_unconvert_size(pc_texture_size size) {
  193.     return 1 << pc_size_to_log2(size);
  194. }
  195.  
  196. static inline pc_texture_size pc_convert_size(int size) {
  197.     if (size >= 1024)
  198.         return PC_SIZE_1024;
  199.     else if (size >= 512)
  200.         return PC_SIZE_512;
  201.     else if (size >= 256)
  202.         return PC_SIZE_256;
  203.     else if (size >= 128)
  204.         return PC_SIZE_128;
  205.     else if (size >= 64)
  206.         return PC_SIZE_64;
  207.     else if (size >= 32)
  208.         return PC_SIZE_32;
  209.     else if (size >= 16)
  210.         return PC_SIZE_16;
  211.     else
  212.         return PC_SIZE_8;
  213.    
  214. }
  215.  
  216. typedef enum {
  217.     PC_ARGB1555,
  218.     PC_RGB565,
  219.     PC_ARGB4444,
  220.     PC_YUV,
  221.     PC_NORMAL,
  222.     PC_PALETTE_8B,
  223.     PC_PALETTE_4B,
  224. } pc_texture_format;
  225.  
  226. typedef enum {
  227.     PC_OUTSIDE,
  228.     PC_INSIDE,
  229. } pc_modifier_selection;
  230.  
  231. //get no-modifier specific settings
  232. static inline pvr_context_submodes * pc_no_mod(pvr_context *src)
  233. {
  234.     return &src->bf.m;
  235. }
  236.  
  237. //get sprite specific setting
  238. static inline pvr_context_submodes * pc_spr_mode(pvr_context *src)
  239. {
  240.     return &src->bp.m;
  241. }
  242.  
  243. //get modifier specific settings by index
  244. static inline pvr_context_submodes * pc_idx_mod(pvr_context *src, pc_modifier_selection mode)
  245. {
  246.     return &src->mod[mode];
  247. }
  248.  
  249. //get outside (default) modifier specific settings
  250. static inline pvr_context_submodes * pc_out_mod(pvr_context *src)
  251. {
  252.     return pc_idx_mod(src, PC_OUTSIDE);
  253. }
  254.  
  255. //get inside modifier specific settings
  256. static inline pvr_context_submodes * pc_in_mod(pvr_context *src)
  257. {
  258.     return pc_idx_mod(src, PC_INSIDE);
  259. }
  260.  
  261. //Sets command type
  262. static inline void pc_set_command(pvr_context *dst, pc_command cmd) {
  263.     dst->cmd = replace_bits(dst->cmd, cmd, 29, 3);
  264. }
  265.  
  266. //Sets list type of command
  267. static inline void pc_set_list(pvr_context *dst, pc_list_type list) {
  268.     dst->cmd = replace_bits(dst->cmd, list, 24, 3);
  269. }
  270.  
  271. //Listed in MAME source as "groupen", but MAME doesn't use it in any way
  272. static inline void pc_set_group_enable(pvr_context *dst, pc_boolean enable) {
  273.     dst->cmd = replace_bit(dst->cmd, enable, 23);
  274. }
  275.  
  276. //Sets maximum strip length generated by TA
  277. static inline void pc_set_max_strip_length(pvr_context *dst, pc_strip_length length) {
  278.     dst->cmd = replace_bits(dst->cmd, length, 18, 2);
  279. }
  280.  
  281. //Sets clipping/scissor mode
  282. static inline void pc_set_clip_mode(pvr_context *dst, pc_clip_mode mode) {
  283.     dst->cmd = replace_bits(dst->cmd, mode, 16, 2);
  284. }
  285.  
  286. //Set if affected by modifier volumes
  287. static inline void pc_set_modified(pvr_context *dst, pc_boolean enable) {
  288.     dst->cmd = replace_bit(dst->cmd, enable, 7);
  289. }
  290.  
  291. //Set to enable full modifier volumes, or set to disabled to enable cheap modifier volumes
  292. static inline void pc_set_modifier_full(pvr_context *dst, pc_boolean enable) {
  293.     dst->cmd = replace_bit(dst->cmd, enable, 6);
  294. }
  295.  
  296. //Sets color format of TA
  297. static inline void pc_set_color_format(pvr_context *dst, pc_color_format format) {
  298.     dst->cmd = replace_bits(dst->cmd, format, 4, 3);
  299. }
  300.  
  301. //Enables texturing
  302. static inline void pc_set_textured(pvr_context *dst, pc_boolean textured) {
  303.     dst->cmd = replace_bit(dst->cmd, textured, 3);
  304. }
  305.  
  306. //Enable specular/offset color
  307. static inline void pc_set_specular(pvr_context *dst, pc_boolean specular) {
  308.     dst->cmd = replace_bit(dst->cmd, specular, 2);
  309. }
  310.  
  311. //Enable gouraud shading
  312. static inline void pc_set_gouraud(pvr_context *dst, pc_boolean gouraud) {
  313.     dst->cmd = replace_bit(dst->cmd, gouraud, 1);
  314. }
  315.  
  316. //Enable 16-bit UV coords
  317. static inline void pc_set_small_uv(pvr_context *dst, pc_boolean small) {
  318.     dst->cmd = replace_bit(dst->cmd, small, 0);
  319. }
  320.  
  321. //Sets depth compare mode
  322. static inline void pc_set_depth_compare(pvr_context *dst, pc_depth_compare comparison) {
  323.     dst->mode1 = replace_bits(dst->mode1, comparison, 29, 3);
  324. }
  325.  
  326. //Sets backface culling
  327. static inline void pc_set_cull_mode(pvr_context *dst, pc_culling cull) {
  328.     dst->mode1 = replace_bits(dst->mode1, cull, 27, 2);
  329. }
  330.  
  331. //Enables depth writes
  332. static inline void pc_set_depth_write_disable(pvr_context *dst, pc_boolean disable) {
  333.     dst->mode1 = replace_bit(dst->mode1, disable, 26);
  334. }
  335.  
  336. //Enables improved mipmap level calcuation (slightly sharper textures) at a cost of reduced fillrate
  337. static inline void pc_set_exact_mipmap(pvr_context *dst, pc_boolean dcalc) {
  338.     dst->mode1 = replace_bit(dst->mode1, dcalc, 20);
  339. }
  340.  
  341.  
  342.  
  343. //Sets source blend function
  344. static inline void pc_set_src_blend_mode_mod(pvr_context_submodes *dst, pc_blend_mode bsrc) {
  345.     dst->mode2 = replace_bits(dst->mode2, bsrc, 29, 3);
  346. }
  347. static inline void pc_set_src_blend_mode_in(pvr_context *dst, pc_blend_mode bsrc) {
  348.     pc_set_src_blend_mode_mod(pc_in_mod(dst), bsrc);
  349. }
  350. static inline void pc_set_src_blend_mode(pvr_context *dst, pc_blend_mode bsrc) {
  351.     pc_set_src_blend_mode_mod(pc_no_mod(dst), bsrc);
  352. }
  353.  
  354. //Sets destination blend function
  355. static inline void pc_set_dst_blend_mode_mod(pvr_context_submodes *dst, pc_blend_mode bdst) {
  356.     dst->mode2 = replace_bits(dst->mode2, bdst, 26, 3);
  357. }
  358. static inline void pc_set_dst_blend_mode_in(pvr_context *dst, pc_blend_mode bdst) {
  359.     pc_set_dst_blend_mode_mod(pc_in_mod(dst), bdst);
  360. }
  361. static inline void pc_set_dst_blend_mode(pvr_context *dst, pc_blend_mode bdst) {
  362.     pc_set_dst_blend_mode_mod(pc_no_mod(dst), bdst);
  363. }
  364.  
  365. //Sets both source and destination blend functions
  366. static inline void pc_set_blend_modes_mod(pvr_context_submodes *dst, pc_blend_mode bsrc, pc_blend_mode bdst) {
  367.     pc_set_src_blend_mode_mod(dst,bsrc);
  368.     pc_set_dst_blend_mode_mod(dst,bdst);
  369. }
  370. static inline void pc_set_blend_modes_in(pvr_context *dst, pc_blend_mode bsrc, pc_blend_mode bdst) {
  371.     pc_set_src_blend_mode_in(dst,bsrc);
  372.     pc_set_dst_blend_mode_in(dst,bdst);
  373. }
  374. static inline void pc_set_blend_modes(pvr_context *dst, pc_blend_mode bsrc, pc_blend_mode bdst) {
  375.     pc_set_src_blend_mode(dst,bsrc);
  376.     pc_set_dst_blend_mode(dst,bdst);
  377. }
  378.  
  379. //Sets source color source (regular polygon source color or multitexture accumulation buffer value)
  380. static inline void pc_set_color_source_mod(pvr_context_submodes *dst, pc_color_source csrc) {
  381.     dst->mode2 = replace_bit(dst->mode2, csrc, 25);
  382. }
  383. static inline void pc_set_color_source_in(pvr_context *dst, pc_color_source csrc) {
  384.     pc_set_color_source_mod(pc_in_mod(dst), csrc);
  385. }
  386. static inline void pc_set_color_source(pvr_context *dst, pc_color_source csrc) {
  387.     pc_set_color_source_mod(pc_no_mod(dst), csrc);
  388. }
  389.  
  390. //Sets pixel destination (frame buffer or multitexture accumulation buffer)
  391. static inline void pc_set_color_destination_mod(pvr_context_submodes *dst, pc_color_destination cdst) {
  392.     dst->mode2 = replace_bit(dst->mode2, cdst, 24);
  393. }
  394. static inline void pc_set_color_destination_in(pvr_context *dst, pc_color_destination cdst) {
  395.     pc_set_color_destination_mod(pc_in_mod(dst), cdst);
  396. }
  397. static inline void pc_set_color_destination(pvr_context *dst, pc_color_destination cdst) {
  398.     pc_set_color_destination_mod(pc_no_mod(dst), cdst);
  399. }
  400.  
  401. //Sets fog mode
  402. static inline void pc_set_fog_mode_mod(pvr_context_submodes *dst, pc_fog_mode fog) {
  403.     dst->mode2 = replace_bits(dst->mode2, fog, 22, 2);
  404. }
  405. static inline void pc_set_fog_mode_in(pvr_context *dst, pc_fog_mode fog) {
  406.     pc_set_fog_mode_mod(pc_in_mod(dst), fog);
  407. }
  408. static inline void pc_set_fog_mode(pvr_context *dst, pc_fog_mode fog) {
  409.     pc_set_fog_mode_mod(pc_no_mod(dst), fog);
  410. }
  411.  
  412. //Sets color calcuation clamp enable
  413. static inline void pc_set_color_clamp_mod(pvr_context_submodes *dst, pc_boolean clamp) {
  414.     dst->mode2 = replace_bit(dst->mode2, clamp, 21);
  415. }
  416. static inline void pc_set_color_clamp_in(pvr_context *dst, pc_boolean clamp) {
  417.     pc_set_color_clamp_mod(pc_in_mod(dst), clamp);
  418. }
  419. static inline void pc_set_color_clamp(pvr_context *dst, pc_boolean clamp) {
  420.     pc_set_color_clamp_mod(pc_no_mod(dst), clamp);
  421. }
  422.  
  423. //Enables vertex alpha value (replaces vertex alpha with 1.0 if disabled)
  424. static inline void pc_set_enable_alpha_mod(pvr_context_submodes *dst, pc_boolean on) {
  425.     dst->mode2 = replace_bit(dst->mode2, on, 20);
  426. }
  427. static inline void pc_set_enable_alpha_in(pvr_context *dst, pc_boolean on) {
  428.     pc_set_enable_alpha_mod(pc_in_mod(dst), on);
  429. }
  430. static inline void pc_set_enable_alpha(pvr_context *dst, pc_boolean on) {
  431.     pc_set_enable_alpha_mod(pc_no_mod(dst), on);
  432. }
  433.  
  434. //Disables texture alpha (replaces texture alpha with 1.0 when "off" is set to 1)
  435. static inline void pc_set_disable_texture_alpha_mod(pvr_context_submodes *dst, pc_boolean off) {
  436.     dst->mode2 = replace_bit(dst->mode2, off, 19);
  437. }
  438. static inline void pc_set_disable_texture_alpha_in(pvr_context *dst, pc_boolean off) {
  439.     pc_set_disable_texture_alpha_mod(pc_in_mod(dst), off);
  440. }
  441. static inline void pc_set_disable_texture_alpha(pvr_context *dst, pc_boolean off) {
  442.     pc_set_disable_texture_alpha_mod(pc_no_mod(dst), off);
  443. }
  444.  
  445. //Sets UV flip mode
  446. static inline void pc_set_uv_flip_mod(pvr_context_submodes *dst, pc_uv_control flippage) {
  447.     dst->mode2 = replace_bits(dst->mode2, flippage, 17, 2);
  448. }
  449. static inline void pc_set_uv_flip_in(pvr_context *dst, pc_uv_control flippage) {
  450.     pc_set_uv_flip_mod(pc_in_mod(dst), flippage);
  451. }
  452. static inline void pc_set_uv_flip(pvr_context *dst, pc_uv_control flippage) {
  453.     pc_set_uv_flip_mod(pc_no_mod(dst), flippage);
  454. }
  455.  
  456. //Sets UV edge clamp
  457. static inline void pc_set_uv_clamp_mod(pvr_context_submodes *dst, pc_uv_control clamppage) {
  458.     dst->mode2 = replace_bits(dst->mode2, clamppage, 15, 2);
  459. }
  460. static inline void pc_set_uv_clamp_in(pvr_context *dst, pc_uv_control clamppage) {
  461.     pc_set_uv_clamp_mod(pc_in_mod(dst), clamppage);
  462. }
  463. static inline void pc_set_uv_clamp(pvr_context *dst, pc_uv_control clamppage) {
  464.     pc_set_uv_clamp_mod(pc_no_mod(dst), clamppage);
  465. }
  466.  
  467. //Sets texture filter mode
  468. static inline void pc_set_filter_mod(pvr_context_submodes *dst, pc_texture_filter filter) {
  469.     dst->mode2 = replace_bits(dst->mode2, filter, 13, 2);
  470. }
  471. static inline void pc_set_filter_in(pvr_context *dst, pc_texture_filter filter) {
  472.     pc_set_filter_mod(pc_in_mod(dst), filter);
  473. }
  474. static inline void pc_set_filter(pvr_context *dst, pc_texture_filter filter) {
  475.     pc_set_filter_mod(pc_no_mod(dst), filter);
  476. }
  477.  
  478. //Enable anisotropic filter
  479. static inline void pc_set_anisotropic_mod(pvr_context_submodes *dst, pc_boolean aniso) {
  480.     dst->mode2 = replace_bit(dst->mode2, aniso, 12);
  481. }
  482. static inline void pc_set_anisotropic_in(pvr_context *dst, pc_boolean aniso) {
  483.     pc_set_anisotropic_mod(pc_in_mod(dst), aniso);
  484. }
  485. static inline void pc_set_anisotropic(pvr_context *dst, pc_boolean aniso) {
  486.     pc_set_anisotropic_mod(pc_no_mod(dst), aniso);
  487. }
  488.  
  489. //Sets mipmap bias, to prefer sharper or blurrier mipmap levels
  490. static inline void pc_set_mipmap_bias_mod(pvr_context_submodes *dst, pc_mipmap_bias bias) {
  491.     dst->mode2 = replace_bits(dst->mode2, bias, 8, 4);
  492. }
  493. static inline void pc_set_mipmap_bias_in(pvr_context *dst, pc_mipmap_bias bias) {
  494.     pc_set_mipmap_bias_mod(pc_in_mod(dst), bias);
  495. }
  496. static inline void pc_set_mipmap_bias(pvr_context *dst, pc_mipmap_bias bias) {
  497.     pc_set_mipmap_bias_mod(pc_no_mod(dst), bias);
  498. }
  499.  
  500. //Sets opengl texture environment (texenv)
  501. static inline void pc_set_texenv_mod(pvr_context_submodes *dst, pc_texture_environment env) {
  502.     dst->mode2 = replace_bits(dst->mode2, env, 6, 2);
  503. }
  504. static inline void pc_set_texenv_in(pvr_context *dst, pc_texture_environment env) {
  505.     pc_set_texenv_mod(pc_in_mod(dst), env);
  506. }
  507. static inline void pc_set_texenv(pvr_context *dst, pc_texture_environment env) {
  508.     pc_set_texenv_mod(pc_no_mod(dst), env);
  509. }
  510.  
  511. //Sets texture width
  512. static inline void pc_set_u_size_mod(pvr_context_submodes *dst, pc_texture_size size) {
  513.     dst->mode2 = replace_bits(dst->mode2,size, 3, 3);
  514. }
  515. static inline void pc_set_u_size_in(pvr_context *dst, pc_texture_size size) {
  516.     pc_set_u_size_mod(pc_in_mod(dst), size);
  517. }
  518. static inline void pc_set_u_size(pvr_context *dst, pc_texture_size size) {
  519.     pc_set_u_size_mod(pc_no_mod(dst), size);
  520. }
  521.  
  522. //Sets texture height
  523. static inline void pc_set_v_size_mod(pvr_context_submodes *dst, pc_texture_size size) {
  524.     dst->mode2 = replace_bits(dst->mode2,size, 0, 3);
  525. }
  526. static inline void pc_set_v_size_in(pvr_context *dst, pc_texture_size size) {
  527.     pc_set_v_size_mod(pc_in_mod(dst), size);
  528. }
  529. static inline void pc_set_v_size(pvr_context *dst, pc_texture_size size) {
  530.     pc_set_v_size_mod(pc_no_mod(dst), size);
  531. }
  532.  
  533. //Sets texture width and height
  534. static inline void pc_set_uv_size_mod(pvr_context_submodes *dst, pc_texture_size u,pc_texture_size v) {
  535.     pc_set_u_size_mod(dst,u);
  536.     pc_set_v_size_mod(dst,v);
  537. }
  538. static inline void pc_set_uv_size_in(pvr_context *dst, pc_texture_size u,pc_texture_size v) {
  539.     pc_set_uv_size_mod(pc_in_mod(dst), u, v);
  540. }
  541. static inline void pc_set_uv_size(pvr_context *dst, pc_texture_size u,pc_texture_size v) {
  542.     pc_set_uv_size_mod(pc_no_mod(dst), u, v);
  543. }
  544.  
  545. //Enables mipmapped texture
  546. static inline void pc_set_mipmapped_mod(pvr_context_submodes *dst, pc_boolean mipped) {
  547.     dst->tex = replace_bit(dst->tex, mipped, 31);
  548. }
  549. static inline void pc_set_mipmapped_in(pvr_context *dst, pc_boolean mipped) {
  550.     pc_set_mipmapped_mod(pc_in_mod(dst), mipped);
  551. }
  552. static inline void pc_set_mipmapped(pvr_context *dst, pc_boolean mipped) {
  553.     pc_set_mipmapped_mod(pc_no_mod(dst), mipped);
  554. }
  555.  
  556. //Enables VQ compression
  557. static inline void pc_set_compressed_mod(pvr_context_submodes *dst, pc_boolean vq) {
  558.     dst->tex = replace_bit(dst->tex, vq, 30);
  559. }
  560. static inline void pc_set_compressed_in(pvr_context *dst, pc_boolean vq) {
  561.     pc_set_compressed_mod(pc_in_mod(dst), vq);
  562. }
  563. static inline void pc_set_compressed(pvr_context *dst, pc_boolean vq) {
  564.     pc_set_compressed_mod(pc_no_mod(dst), vq);
  565. }
  566.  
  567. //Sets texture format
  568. static inline void pc_set_texture_format_mod(pvr_context_submodes *dst, pc_texture_format format) {
  569.     dst->tex = replace_bits(dst->tex, format, 27, 3);
  570. }
  571. static inline void pc_set_texture_format_in(pvr_context *dst, pc_texture_format format) {
  572.     pc_set_texture_format_mod(pc_in_mod(dst), format);
  573. }
  574. static inline void pc_set_texture_format(pvr_context *dst, pc_texture_format format) {
  575.     pc_set_texture_format_mod(pc_no_mod(dst), format);
  576. }
  577.  
  578. //Sets twiddled style texture
  579. static inline void pc_set_twiddled_mod(pvr_context_submodes *dst, pc_boolean twiddledee) {
  580.     dst->tex = replace_bit(dst->tex, !twiddledee, 26);
  581. }
  582. static inline void pc_set_twiddled_in(pvr_context *dst, pc_boolean twiddledumb) {
  583.     pc_set_twiddled_mod(pc_in_mod(dst), twiddledumb);
  584. }
  585. static inline void pc_set_twiddled(pvr_context *dst, pc_boolean twiddledumb) {
  586.     pc_set_twiddled_mod(pc_no_mod(dst), twiddledumb);
  587. }
  588.  
  589. //Sets strided (non-pow-2 width) texture
  590. static inline void pc_set_strided_mod(pvr_context_submodes *dst, pc_boolean strider) {
  591.     dst->tex = replace_bit(dst->tex, strider, 25);
  592. }
  593. static inline void pc_set_strided_in(pvr_context *dst, pc_boolean strider) {
  594.     pc_set_strided_mod(pc_in_mod(dst), strider);
  595. }
  596. static inline void pc_set_strided(pvr_context *dst, pc_boolean strider) {
  597.     pc_set_strided_mod(pc_no_mod(dst), strider);
  598. }
  599.  
  600. //Sets the palette for a 4-bit texture
  601. static inline void pc_set_palette_4bit_mod(pvr_context_submodes *dst, pc_boolean pal) {
  602.     dst->tex = replace_bits(dst->tex, pal, 21, 6);
  603. }
  604. static inline void pc_set_palette_4bit_in(pvr_context *dst, pc_boolean pal) {
  605.     pc_set_palette_4bit_mod(pc_in_mod(dst), pal);
  606. }
  607. static inline void pc_set_palette_4bit(pvr_context *dst, pc_boolean pal) {
  608.     pc_set_palette_4bit_mod(pc_no_mod(dst), pal);
  609. }
  610.  
  611. //Sets the palette for an 8-bit texture
  612. static inline void pc_set_palette_8bit_mod(pvr_context_submodes *dst, pc_boolean pal) {
  613.     dst->tex = replace_bits(dst->tex, pal<<4, 21, 2);
  614. }
  615. static inline void pc_set_palette_8bit_in(pvr_context *dst, pc_boolean pal) {
  616.     pc_set_palette_8bit_mod(pc_in_mod(dst),  pal);
  617. }
  618. static inline void pc_set_palette_8bit(pvr_context *dst, pc_boolean pal) {
  619.     pc_set_palette_8bit_mod(pc_no_mod(dst),  pal);
  620. }
  621.  
  622. //Sets address of texture
  623. static inline void pc_set_texture_address_mod(pvr_context_submodes *dst, pvr_ptr_t tex) {
  624.     dst->tex = replace_bits(dst->tex, ((unsigned int)tex) >> 3, 0, 21);
  625. }
  626. static inline void pc_set_texture_address_in(pvr_context *dst, pvr_ptr_t tex) {
  627.     pc_set_texture_address_mod(pc_in_mod(dst), tex);
  628. }
  629. static inline void pc_set_texture_address(pvr_context *dst, pvr_ptr_t tex) {
  630.     pc_set_texture_address_mod(pc_no_mod(dst), tex);
  631. }
  632.  
  633. //Returns pvr_ptr_t to texture
  634. static inline pvr_ptr_t pc_get_texture_address_mod(pvr_context_submodes *dst) {
  635.     return (pvr_ptr_t)((dst->tex & 0xffffffff) << 3);
  636. }
  637. static inline pvr_ptr_t pc_get_texture_address_in(pvr_context *dst) {
  638.     return pc_get_texture_address_mod(pc_in_mod(dst));
  639. }
  640. static inline pvr_ptr_t pc_get_texture_address(pvr_context *dst) {
  641.     return pc_get_texture_address_mod(pc_no_mod(dst));
  642. }
  643.  
  644. //Sets everything required for a non-stride non-palettized texture at once for a given mode (does not actually enable texturing)
  645. static inline void pc_set_mode_texture_mod(pvr_context_submodes *dst, pvr_ptr_t tex, pc_texture_size u, pc_texture_size v,
  646.     pc_texture_format format, pc_boolean twiddle, pc_boolean mipmap, pc_boolean vq)
  647. {
  648.     pc_set_strided_mod(dst, 0);
  649.     pc_set_texture_address_mod(dst,tex);
  650.     pc_set_uv_size_mod(dst,u,v);
  651.     pc_set_texture_format_mod(dst,format);
  652.     pc_set_twiddled_mod(dst,twiddle);
  653.     pc_set_mipmapped_mod(dst,mipmap);
  654.     pc_set_compressed_mod(dst,vq);
  655.     pc_set_mipmap_bias_mod(dst, PC_MIPMAP_BIAS_1_00);
  656. }
  657. static inline void pc_set_mode_texture_in(pvr_context *dst, pvr_ptr_t tex, pc_texture_size u, pc_texture_size v,
  658.     pc_texture_format format, pc_boolean twiddle, pc_boolean mipmap, pc_boolean vq)
  659. {
  660.     pc_set_mode_texture_mod(pc_in_mod(dst), tex, u, v, format, twiddle, mipmap, vq);
  661. }
  662. static inline void pc_set_mode_texture(pvr_context *dst, pvr_ptr_t tex, pc_texture_size u, pc_texture_size v,
  663.     pc_texture_format format, pc_boolean twiddle, pc_boolean mipmap, pc_boolean vq)
  664. {
  665.     pc_set_mode_texture_mod(pc_no_mod(dst), tex, u, v, format, twiddle, mipmap, vq);
  666. }
  667.  
  668. //Sets everything required for a non-stride texture at once for a given mode and enables texturing
  669. static inline void pc_set_texture(pvr_context *dst, pvr_ptr_t tex, pc_texture_size u, pc_texture_size v,
  670.     pc_texture_format format, pc_boolean twiddle, pc_boolean mipmap, pc_boolean vq)
  671. {
  672.     pc_set_textured(dst, 1);
  673.     pc_set_mode_texture(dst, tex, u, v, format, twiddle, mipmap, vq);
  674. }
  675.  
  676. static inline void pc_set_sprite_color_packed(pvr_context *dst, int color) {
  677.     dst->bp.color = color;
  678. }
  679. static inline void pc_set_sprite_color(pvr_context *dst, float a, float r, float g, float b) {
  680.     dst->bp.color = PVR_PACK_COLOR(a,r,g,b);
  681. }
  682. static inline void pc_set_sprite_offset_packed(pvr_context *dst, unsigned int argb) {
  683.     dst->bp.offset = argb;
  684. }
  685. static inline void pc_set_sprite_offset(pvr_context *dst, float a, float r, float g, float b) {
  686.     dst->bp.offset = PVR_PACK_COLOR(a,r,g,b);
  687. }
  688.  
  689. //untextured gouraud shaded opaque polyons with floating point color
  690. static inline void pc_set_default_polygon(pvr_context *dst)
  691. {
  692.     dst->cmd = 0;
  693.     dst->mode1 = 0;
  694.     pc_no_mod(dst)->mode2 = 0;
  695.     pc_no_mod(dst)->tex = 0;
  696.    
  697.     pc_set_command(dst, PC_CMD_POLYGON);
  698.     pc_set_list(dst, PC_OPAQUE_POLY);
  699.     pc_set_gouraud(dst, 1);
  700.     pc_set_max_strip_length(dst, PC_STRIP6);
  701.     pc_set_color_format(dst, PC_FLOAT);
  702.     pc_set_depth_compare(dst, PC_GEQUAL);
  703.     pc_set_cull_mode(dst, PC_CULL_SMALL);
  704.     pc_set_enable_alpha(dst, 1);
  705.     pc_set_blend_modes(dst, PC_ONE, PC_ZERO);
  706.     pc_set_color_clamp(dst, 1);
  707.     pc_set_fog_mode(dst, PC_FOG_DISABLE);
  708.     pc_set_texenv(dst, PC_TEXENV_MODULATE);
  709.    
  710.     dst->bf.a = dst->bf.r = dst->bf.g = dst->bf.b = 1;
  711. }
  712.  
  713. //transparent untextured sprite
  714. static inline void pc_set_default_sprite(pvr_context *dst) {
  715.     dst->cmd = 0;
  716.     dst->mode1 = 0;
  717.     pc_no_mod(dst)->mode2 = 0;
  718.     pc_no_mod(dst)->tex = 0;
  719.    
  720.     pc_set_command(dst, PC_CMD_SPRITE);
  721.     pc_set_list(dst, PC_BLEND_POLY);
  722.     pc_set_gouraud(dst, 1);
  723.     pc_set_max_strip_length(dst, PC_STRIP1);
  724.     pc_set_color_format(dst, PC_PACKED);
  725.     pc_set_depth_compare(dst, PC_GEQUAL);
  726.     pc_set_cull_mode(dst, PC_CULL_SMALL);
  727.     pc_set_enable_alpha(dst, 1);
  728.     pc_set_blend_modes(dst, PC_SRC_ALPHA, PC_INV_SRC_ALPHA);
  729.     pc_set_color_clamp(dst, 1);
  730.     pc_set_fog_mode(dst, PC_FOG_DISABLE);
  731.     pc_set_texenv(dst, PC_TEXENV_MODULATE);
  732.    
  733.     pc_set_sprite_color_packed(dst, 0xffffffff);
  734.    
  735. }
  736.  
  737. static inline void pc_copy(const pvr_context *src, volatile pvr_context *dst) {
  738.     dst->cmd = src->cmd;
  739.     dst->mode1 = src->mode1;
  740.     dst->bp.m.mode2 = src->bp.m.mode2;
  741.     dst->bp.m.tex = src->bp.m.tex;
  742.     dst->bp.color = src->bp.color;
  743.     dst->bp.offset = src->bp.offset;
  744.     dst->bp.pad0 = src->bp.pad0;
  745.     dst->bp.pad1 = src->bp.pad1;
  746. }
  747.  
  748. #endif
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top