14 #include "DepthBuffer.h"
19 //thank rice_video for this:
20 bool _IsRenderTexture()
22 bool foundSetScissor=false;
23 bool foundFillRect=false;
24 bool foundSetFillColor=false;
25 bool foundSetCImg=false;
26 bool foundTxtRect=false;
28 unsigned int newFillColor = 0;
29 unsigned int dwPC = RSP.PC[RSP.PCi]; // This points to the next instruction
31 for(int i=0; i<10; i++ )
33 unsigned int w0 = *(unsigned int *)(RDRAM + dwPC + i*8);
34 unsigned int w1 = *(unsigned int *)(RDRAM + dwPC + 4 + i*8);
36 if ((w0>>24) == G_SETSCISSOR)
38 height = ((w1>>0 )&0xFFF)/4;
39 foundSetScissor = true;
43 if ((w0>>24) == G_SETFILLCOLOR)
45 height = ((w1>>0 )&0xFFF)/4;
46 foundSetFillColor = true;
51 if ((w0>>24) == G_FILLRECT)
53 unsigned int x0 = ((w1>>12)&0xFFF)/4;
54 unsigned int y0 = ((w1>>0 )&0xFFF)/4;
55 unsigned int x1 = ((w0>>12)&0xFFF)/4;
56 unsigned int y1 = ((w0>>0 )&0xFFF)/4;
58 if (x0 == 0 && y0 == 0)
60 if( x1 == gDP.colorImage.width)
67 if(x1 == (unsigned int)(gDP.colorImage.width-1))
76 if ((w0>>24) == G_TEXRECT)
82 if ((w0>>24) == G_SETCIMG)
91 if (foundSetFillColor)
93 if (newFillColor != 0xFFFCFFFC)
94 return true; // this is a render_texture
99 if (gDP.fillColor.i == 0x00FFFFF7)
100 return true; // this is a render_texture
102 return false; // this is a normal ZImg
104 else if (foundSetFillColor && newFillColor == 0xFFFCFFFC && foundSetCImg )
112 if (!foundSetCImg) return true;
114 if (foundSetScissor ) return true;
121 void gDPSetOtherMode( u32 mode0, u32 mode1 )
123 gDP.otherMode.h = mode0;
124 gDP.otherMode.l = mode1;
125 gDP.changed |= CHANGED_RENDERMODE | CHANGED_CYCLETYPE | CHANGED_ALPHACOMPARE;
128 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetOtherMode( %s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s, %s | %s | %s%s%s%s%s | %s | %s%s%s );\n",
129 AlphaDitherText[gDP.otherMode.alphaDither],
130 ColorDitherText[gDP.otherMode.colorDither],
131 CombineKeyText[gDP.otherMode.combineKey],
132 TextureConvertText[gDP.otherMode.textureConvert],
133 TextureFilterText[gDP.otherMode.textureFilter],
134 TextureLUTText[gDP.otherMode.textureLUT],
135 TextureLODText[gDP.otherMode.textureLOD],
136 TextureDetailText[gDP.otherMode.textureDetail],
137 TexturePerspText[gDP.otherMode.texturePersp],
138 CycleTypeText[gDP.otherMode.cycleType],
139 PipelineModeText[gDP.otherMode.pipelineMode],
140 AlphaCompareText[gDP.otherMode.alphaCompare],
141 DepthSourceText[gDP.otherMode.depthSource],
142 gDP.otherMode.AAEnable ? "AA_EN | " : "",
143 gDP.otherMode.depthCompare ? "Z_CMP | " : "",
144 gDP.otherMode.depthUpdate ? "Z_UPD | " : "",
145 gDP.otherMode.imageRead ? "IM_RD | " : "",
146 CvgDestText[gDP.otherMode.cvgDest],
147 DepthModeText[gDP.otherMode.depthMode],
148 gDP.otherMode.cvgXAlpha ? "CVG_X_ALPHA | " : "",
149 gDP.otherMode.alphaCvgSel ? "ALPHA_CVG_SEL | " : "",
150 gDP.otherMode.forceBlender ? "FORCE_BL" : "" );
154 void gDPSetPrimDepth( u16 z, u16 dz )
158 //gDP.primDepth.z = (_FIXED2FLOAT( z, 15 ) - gSP.viewport.vtrans[2]) / gSP.viewport.vscale[2] ;
159 gDP.primDepth.z = (z - gSP.viewport.vtrans[2]) / gSP.viewport.vscale[2] ;
160 gDP.primDepth.deltaZ = dz;
161 gDP.changed |= CHANGED_PRIMITIVEZ;
164 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetPrimDepth( %f, %f );\n",
166 gDP.primDepth.deltaZ);
170 void gDPPipelineMode( u32 mode )
172 gDP.otherMode.pipelineMode = mode;
175 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPPipelineMode( %s );\n",
176 PipelineModeText[gDP.otherMode.pipelineMode] );
180 void gDPSetCycleType( u32 type )
182 gDP.otherMode.cycleType = type;
183 gDP.changed |= CHANGED_CYCLETYPE;
186 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetCycleType( %s );\n",
187 CycleTypeText[gDP.otherMode.cycleType] );
191 void gDPSetTexturePersp( u32 enable )
193 gDP.otherMode.texturePersp = enable;
196 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_TEXTURE, "gDPSetTexturePersp( %s );\n",
197 TexturePerspText[gDP.otherMode.texturePersp] );
201 void gDPSetTextureDetail( u32 type )
203 gDP.otherMode.textureDetail = type;
206 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_TEXTURE, "gDPSetTextureDetail( %s );\n",
207 TextureDetailText[gDP.otherMode.textureDetail] );
211 void gDPSetTextureLOD( u32 mode )
213 gDP.otherMode.textureLOD = mode;
216 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_TEXTURE, "gDPSetTextureLOD( %s );\n",
217 TextureLODText[gDP.otherMode.textureLOD] );
221 void gDPSetTextureLUT( u32 mode )
223 gDP.otherMode.textureLUT = mode;
226 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_TEXTURE, "gDPSetTextureLUT( %s );\n",
227 TextureLUTText[gDP.otherMode.textureLUT] );
231 void gDPSetTextureFilter( u32 type )
233 gDP.otherMode.textureFilter = type;
236 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_TEXTURE, "gDPSetTextureFilter( %s );\n",
237 TextureFilterText[gDP.otherMode.textureFilter] );
241 void gDPSetTextureConvert( u32 type )
243 gDP.otherMode.textureConvert = type;
246 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_TEXTURE, "gDPSetTextureConvert( %s );\n",
247 TextureConvertText[gDP.otherMode.textureConvert] );
251 void gDPSetCombineKey( u32 type )
253 gDP.otherMode.combineKey = type;
256 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_COMBINE, "gDPSetCombineKey( %s );\n",
257 CombineKeyText[gDP.otherMode.combineKey] );
261 void gDPSetColorDither( u32 type )
263 gDP.otherMode.colorDither = type;
266 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetColorDither( %s );\n",
267 ColorDitherText[gDP.otherMode.colorDither] );
271 void gDPSetAlphaDither( u32 type )
273 gDP.otherMode.alphaDither = type;
276 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetAlphaDither( %s );\n",
277 AlphaDitherText[gDP.otherMode.alphaDither] );
281 void gDPSetAlphaCompare( u32 mode )
283 gDP.otherMode.alphaCompare = mode;
284 gDP.changed |= CHANGED_ALPHACOMPARE;
287 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetAlphaCompare( %s );\n",
288 AlphaCompareText[gDP.otherMode.alphaCompare] );
292 void gDPSetDepthSource( u32 source )
294 gDP.otherMode.depthSource = source;
295 gDP.changed |= CHANGED_DEPTHSOURCE;
298 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetDepthSource( %s );\n",
299 DepthSourceText[gDP.otherMode.depthSource] );
303 void gDPSetRenderMode( u32 mode1, u32 mode2 )
305 gDP.otherMode.l &= 0x00000007;
306 gDP.otherMode.l |= mode1 | mode2;
307 gDP.changed |= CHANGED_RENDERMODE;
310 // THIS IS INCOMPLETE!!!
311 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetRenderMode( %s%s%s%s%s | %s | %s%s%s );\n",
312 gDP.otherMode.AAEnable ? "AA_EN | " : "",
313 gDP.otherMode.depthCompare ? "Z_CMP | " : "",
314 gDP.otherMode.depthUpdate ? "Z_UPD | " : "",
315 gDP.otherMode.imageRead ? "IM_RD | " : "",
316 CvgDestText[gDP.otherMode.cvgDest],
317 DepthModeText[gDP.otherMode.depthMode],
318 gDP.otherMode.cvgXAlpha ? "CVG_X_ALPHA | " : "",
319 gDP.otherMode.alphaCvgSel ? "ALPHA_CVG_SEL | " : "",
320 gDP.otherMode.forceBlender ? "FORCE_BL" : "" );
324 void gDPSetCombine( s32 muxs0, s32 muxs1 )
326 gDP.combine.muxs0 = muxs0;
327 gDP.combine.muxs1 = muxs1;
328 gDP.changed |= CHANGED_COMBINE;
331 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_COMBINE, "gDPSetCombine( %s, %s, %s, %s, %s, %s, %s, %s,\n",
332 saRGBText[gDP.combine.saRGB0],
333 sbRGBText[gDP.combine.sbRGB0],
334 mRGBText[gDP.combine.mRGB0],
335 aRGBText[gDP.combine.aRGB0],
336 saAText[gDP.combine.saA0],
337 sbAText[gDP.combine.sbA0],
338 mAText[gDP.combine.mA0],
339 aAText[gDP.combine.aA0] );
341 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_COMBINE, " %s, %s, %s, %s, %s, %s, %s, %s );\n",
342 saRGBText[gDP.combine.saRGB1],
343 sbRGBText[gDP.combine.sbRGB1],
344 mRGBText[gDP.combine.mRGB1],
345 aRGBText[gDP.combine.aRGB1],
346 saAText[gDP.combine.saA1],
347 sbAText[gDP.combine.sbA1],
348 mAText[gDP.combine.mA1],
349 aAText[gDP.combine.aA1] );
354 void gDPSetColorImage( u32 format, u32 size, u32 width, u32 address )
356 if (config.updateMode == SCREEN_UPDATE_AT_CI_CHANGE)
359 if (config.updateMode == SCREEN_UPDATE_AT_1ST_CI_CHANGE && OGL.screenUpdate)
362 u32 addr = RSP_SegmentToPhysical( address );
364 if (gDP.colorImage.address != addr)
366 gDP.colorImage.changed = FALSE;
367 if (width == VI.width)
368 gDP.colorImage.height = VI.height;
370 gDP.colorImage.height = 1;
373 gDP.colorImage.format = format;
374 gDP.colorImage.size = size;
375 gDP.colorImage.width = width;
376 gDP.colorImage.address = addr;
378 if (config.ignoreOffscreenRendering)
382 //colorimage byte size:
383 //color image height is not the best thing to base this on, its normally set
384 //later on in the code
386 if (gDP.colorImage.address == gDP.depthImageAddress)
388 OGL.renderingToTexture = false;
390 else if (size == G_IM_SIZ_16b && format == G_IM_FMT_RGBA)
395 case G_IM_SIZ_4b: s = (gDP.colorImage.width * gDP.colorImage.height) / 2; break;
396 case G_IM_SIZ_8b: s = (gDP.colorImage.width * gDP.colorImage.height); break;
397 case G_IM_SIZ_16b: s = (gDP.colorImage.width * gDP.colorImage.height) * 2; break;
398 case G_IM_SIZ_32b: s = (gDP.colorImage.width * gDP.colorImage.height) * 4; break;
400 u32 start = addr & 0x00FFFFFF;
401 u32 end = min(start + s, RDRAMSize);
402 for(i = 0; i < VI.displayNum; i++)
404 if (VI.display[i].start <= end && VI.display[i].start >= start) break;
405 if (start <= VI.display[i].end && start >= VI.display[i].start) break;
408 OGL.renderingToTexture = (i == VI.displayNum);
412 OGL.renderingToTexture = true;
416 if (OGL.renderingToTexture)
418 printf("start=%i end=%i\n", start, end);
420 for(int i=0; i< VI.displayNum; i++) printf("%i,%i:", VI.display[i].start, VI.display[i].end);
427 OGL.renderingToTexture = false;
432 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetColorImage( %s, %s, %i, 0x%08X );\n",
433 ImageFormatText[gDP.colorImage.format],
434 ImageSizeText[gDP.colorImage.size],
435 gDP.colorImage.width,
436 gDP.colorImage.address );
440 void gDPSetTextureImage( u32 format, u32 size, u32 width, u32 address )
442 gDP.textureImage.format = format;
443 gDP.textureImage.size = size;
444 gDP.textureImage.width = width;
445 gDP.textureImage.address = RSP_SegmentToPhysical( address );
446 gDP.textureImage.bpl = gDP.textureImage.width << gDP.textureImage.size >> 1;
449 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_TEXTURE, "gDPSetTextureImage( %s, %s, %i, 0x%08X );\n",
450 ImageFormatText[gDP.textureImage.format],
451 ImageSizeText[gDP.textureImage.size],
452 gDP.textureImage.width,
453 gDP.textureImage.address );
457 void gDPSetDepthImage( u32 address )
459 // if (address != gDP.depthImageAddress)
460 // OGL_ClearDepthBuffer();
462 u32 addr = RSP_SegmentToPhysical(address);
463 DepthBuffer_SetBuffer(addr);
465 if (depthBuffer.current->cleared)
466 OGL_ClearDepthBuffer();
468 gDP.depthImageAddress = addr;
471 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetDepthImage( 0x%08X );\n", gDP.depthImageAddress );
475 void gDPSetEnvColor( u32 r, u32 g, u32 b, u32 a )
477 gDP.envColor.r = r * 0.0039215689f;
478 gDP.envColor.g = g * 0.0039215689f;
479 gDP.envColor.b = b * 0.0039215689f;
480 gDP.envColor.a = a * 0.0039215689f;
482 gDP.changed |= CHANGED_ENV_COLOR;
485 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_COMBINE, "gDPSetEnvColor( %u, %u, %u, %u );\n",
490 void gDPSetBlendColor( u32 r, u32 g, u32 b, u32 a )
492 gDP.blendColor.r = r * 0.0039215689f;
493 gDP.blendColor.g = g * 0.0039215689f;
494 gDP.blendColor.b = b * 0.0039215689f;
495 gDP.blendColor.a = a * 0.0039215689f;
496 gDP.changed |= CHANGED_BLENDCOLOR;
499 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetBlendColor( %u, %u, %u, %u );\n",
504 void gDPSetFogColor( u32 r, u32 g, u32 b, u32 a )
506 gDP.fogColor.r = r * 0.0039215689f;
507 gDP.fogColor.g = g * 0.0039215689f;
508 gDP.fogColor.b = b * 0.0039215689f;
509 gDP.fogColor.a = a * 0.0039215689f;
511 gDP.changed |= CHANGED_FOGCOLOR;
514 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetFogColor( %u, %u, %u, %u );\n",
519 void gDPSetFillColor( u32 c )
523 gDP.fillColor.r = _SHIFTR( c, 11, 5 ) * 0.032258064f;
524 gDP.fillColor.g = _SHIFTR( c, 6, 5 ) * 0.032258064f;
525 gDP.fillColor.b = _SHIFTR( c, 1, 5 ) * 0.032258064f;
526 gDP.fillColor.a = _SHIFTR( c, 0, 1 );
528 gDP.fillColor.z = _SHIFTR( c, 2, 14 );
529 gDP.fillColor.dz = _SHIFTR( c, 0, 2 );
532 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetFillColor( 0x%08X );\n", c );
536 void gDPSetPrimColor( u32 m, u32 l, u32 r, u32 g, u32 b, u32 a )
539 gDP.primColor.l = l * 0.0039215689f;
540 gDP.primColor.r = r * 0.0039215689f;
541 gDP.primColor.g = g * 0.0039215689f;
542 gDP.primColor.b = b * 0.0039215689f;
543 gDP.primColor.a = a * 0.0039215689f;
545 gDP.changed |= CHANGED_PRIM_COLOR;
548 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_COMBINE, "gDPSetPrimColor( %u, %u, %u, %u, %u, %u );\n",
553 void gDPSetTile( u32 format, u32 size, u32 line, u32 tmem, u32 tile, u32 palette, u32 cmt, u32 cms, u32 maskt, u32 masks, u32 shiftt, u32 shifts )
555 if (((size == G_IM_SIZ_4b) || (size == G_IM_SIZ_8b)) && (format == G_IM_FMT_RGBA))
556 format = G_IM_FMT_CI;
558 gDP.tiles[tile].format = format;
559 gDP.tiles[tile].size = size;
560 gDP.tiles[tile].line = line;
561 gDP.tiles[tile].tmem = tmem;
562 gDP.tiles[tile].palette = palette;
563 gDP.tiles[tile].cmt = cmt;
564 gDP.tiles[tile].cms = cms;
565 gDP.tiles[tile].maskt = maskt;
566 gDP.tiles[tile].masks = masks;
567 gDP.tiles[tile].shiftt = shiftt;
568 gDP.tiles[tile].shifts = shifts;
570 if (!gDP.tiles[tile].masks) gDP.tiles[tile].clamps = 1;
571 if (!gDP.tiles[tile].maskt) gDP.tiles[tile].clampt = 1;
574 void gDPSetTileSize( u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt )
576 gDP.tiles[tile].uls = _SHIFTR( uls, 2, 10 );
577 gDP.tiles[tile].ult = _SHIFTR( ult, 2, 10 );
578 gDP.tiles[tile].lrs = _SHIFTR( lrs, 2, 10 );
579 gDP.tiles[tile].lrt = _SHIFTR( lrt, 2, 10 );
581 gDP.tiles[tile].fuls = _FIXED2FLOAT( uls, 2 );
582 gDP.tiles[tile].fult = _FIXED2FLOAT( ult, 2 );
583 gDP.tiles[tile].flrs = _FIXED2FLOAT( lrs, 2 );
584 gDP.tiles[tile].flrt = _FIXED2FLOAT( lrt, 2 );
586 gDP.changed |= CHANGED_TILE;
589 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_TEXTURE, "gDPSetTileSize( %u, %.2f, %.2f, %.2f, %.2f );\n",
591 gDP.tiles[tile].fuls,
592 gDP.tiles[tile].fult,
593 gDP.tiles[tile].flrs,
594 gDP.tiles[tile].flrt );
598 void gDPLoadTile( u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt )
600 void (*Interleave)( void *mem, u32 numDWords );
602 u32 address, height, bpl, line, y;
606 gDPSetTileSize( tile, uls, ult, lrs, lrt );
607 gDP.loadTile = &gDP.tiles[tile];
609 if (gDP.loadTile->line == 0)
612 address = gDP.textureImage.address + gDP.loadTile->ult * gDP.textureImage.bpl + (gDP.loadTile->uls << gDP.textureImage.size >> 1);
613 dest = &TMEM[gDP.loadTile->tmem];
614 bpl = (gDP.loadTile->lrs - gDP.loadTile->uls + 1) << gDP.loadTile->size >> 1;
615 height = gDP.loadTile->lrt - gDP.loadTile->ult + 1;
616 src = &RDRAM[address];
618 if (((address + height * bpl) > RDRAMSize) ||
619 (((gDP.loadTile->tmem << 3) + bpl * height) > 4096)) // Stay within TMEM
622 DebugMsg( DEBUG_HIGH | DEBUG_ERROR | DEBUG_TEXTURE, "// Attempting to load texture tile out of range\n" );
623 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_TEXTURE, "gDPLoadTile( %u, %i, %i, %i, %i );\n",
624 tile, gDP.loadTile->uls, gDP.loadTile->ult, gDP.loadTile->lrs, gDP.loadTile->lrt );
629 // Line given for 32-bit is half what it seems it should since they split the
630 // high and low words. I'm cheating by putting them together.
631 if (gDP.loadTile->size == G_IM_SIZ_32b)
633 line = gDP.loadTile->line << 1;
634 Interleave = QWordInterleave;
638 line = gDP.loadTile->line;
639 Interleave = DWordInterleave;
642 for (y = 0; y < height; y++)
644 UnswapCopy( src, dest, bpl );
645 if (y & 1) Interleave( dest, line );
647 src += gDP.textureImage.bpl;
651 gDP.textureMode = TEXTUREMODE_NORMAL;
652 gDP.loadType = LOADTYPE_TILE;
653 gDP.changed |= CHANGED_TMEM;
656 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_TEXTURE, "gDPLoadTile( %u, %i, %i, %i, %i );\n",
657 tile, gDP.loadTile->uls, gDP.loadTile->ult, gDP.loadTile->lrs, gDP.loadTile->lrt );
661 void gDPLoadBlock( u32 tile, u32 uls, u32 ult, u32 lrs, u32 dxt )
663 gDPSetTileSize( tile, uls, ult, lrs, dxt );
664 gDP.loadTile = &gDP.tiles[tile];
666 u32 bytes = (lrs + 1) << gDP.loadTile->size >> 1;
667 u32 address = gDP.textureImage.address + ult * gDP.textureImage.bpl + (uls << gDP.textureImage.size >> 1);
670 ((address + bytes) > RDRAMSize) ||
671 (((gDP.loadTile->tmem << 3) + bytes) > 4096))
674 DebugMsg( DEBUG_HIGH | DEBUG_ERROR | DEBUG_TEXTURE, "// Attempting to load texture block out of range\n" );
675 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_TEXTURE, "gDPLoadBlock( %u, %u, %u, %u, %u );\n",
676 tile, uls, ult, lrs, dxt );
678 // bytes = min( bytes, min( RDRAMSize - gDP.textureImage.address, 4096 - (gDP.loadTile->tmem << 3) ) );
682 u64* src = (u64*)&RDRAM[address];
683 u64* dest = &TMEM[gDP.loadTile->tmem];
687 u32 line = (2047 + dxt) / dxt;
689 u32 height = bytes / bpl;
691 if (gDP.loadTile->size == G_IM_SIZ_32b)
693 for (u32 y = 0; y < height; y++)
695 UnswapCopy( src, dest, bpl );
696 if (y & 1) QWordInterleave( dest, line );
703 for (u32 y = 0; y < height; y++)
705 UnswapCopy( src, dest, bpl );
706 if (y & 1) DWordInterleave( dest, line );
715 UnswapCopy( src, dest, bytes );
717 gDP.textureMode = TEXTUREMODE_NORMAL;
718 gDP.loadType = LOADTYPE_BLOCK;
719 gDP.changed |= CHANGED_TMEM;
722 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_TEXTURE, "gDPLoadBlock( %u, %u, %u, %u, %u );\n",
723 tile, uls, ult, lrs, dxt );
727 void gDPLoadTLUT( u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt )
729 gDPSetTileSize( tile, uls, ult, lrs, lrt );
731 u16 count = (gDP.tiles[tile].lrs - gDP.tiles[tile].uls + 1) * (gDP.tiles[tile].lrt - gDP.tiles[tile].ult + 1);
732 u32 address = gDP.textureImage.address + gDP.tiles[tile].ult * gDP.textureImage.bpl + (gDP.tiles[tile].uls << gDP.textureImage.size >> 1);
734 u16 *dest = (u16*)&TMEM[gDP.tiles[tile].tmem];
735 u16 *src = (u16*)&RDRAM[address];
737 u16 pal = (gDP.tiles[tile].tmem - 256) >> 4;
742 for (u16 j = 0; (j < 16) && (i < count); j++, i++)
744 u16 color = swapword( src[i^1] );
754 gDP.paletteCRC16[pal] = CRC_CalculatePalette( 0xFFFFFFFF, &TMEM[256 + (pal << 4)], 16 );
758 gDP.paletteCRC256 = CRC_Calculate( 0xFFFFFFFF, gDP.paletteCRC16, 64 );
760 gDP.changed |= CHANGED_TMEM;
763 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_TEXTURE, "gDPLoadTLUT( %u, %i, %i, %i, %i );\n",
764 tile, gDP.tiles[tile].uls, gDP.tiles[tile].ult, gDP.tiles[tile].lrs, gDP.tiles[tile].lrt );
768 void gDPSetScissor( u32 mode, f32 ulx, f32 uly, f32 lrx, f32 lry )
770 gDP.scissor.mode = mode;
771 gDP.scissor.ulx = ulx;
772 gDP.scissor.uly = uly;
773 gDP.scissor.lrx = lrx;
774 gDP.scissor.lry = lry;
775 gDP.changed |= CHANGED_SCISSOR;
778 DebugMsg( DEBUG_HIGH | DEBUG_IGNORED, "gDPSetScissor( %s, %.2f, %.2f, %.2f, %.2f );\n",
779 ScissorModeText[gDP.scissor.mode],
787 void gDPFillRectangle( s32 ulx, s32 uly, s32 lrx, s32 lry )
789 DepthBuffer *buffer = DepthBuffer_FindBuffer( gDP.colorImage.address );
792 buffer->cleared = TRUE;
794 if (gDP.depthImageAddress == gDP.colorImage.address)
796 OGL_ClearDepthBuffer();
800 if (gDP.otherMode.cycleType == G_CYC_FILL)
805 if ((ulx == 0) && (uly == 0) && ((unsigned int)lrx == VI.width) && ((unsigned int)lry == VI.height))
807 OGL_ClearColorBuffer( &gDP.fillColor.r );
812 //shouldn't this be primitive color?
813 //OGL_DrawRect( ulx, uly, lrx, lry, (gDP.otherMode.cycleType == G_CYC_FILL) ? &gDP.fillColor.r : &gDP.blendColor.r );
814 //OGL_DrawRect( ulx, uly, lrx, lry, (gDP.otherMode.cycleType == G_CYC_FILL) ? &gDP.fillColor.r : &gDP.primColor.r);
816 float black[] = {0,0,0,0};
817 OGL_DrawRect( ulx, uly, lrx, lry, (gDP.otherMode.cycleType == G_CYC_FILL) ? &gDP.fillColor.r : black);
819 if (depthBuffer.current) depthBuffer.current->cleared = FALSE;
820 gDP.colorImage.changed = TRUE;
821 gDP.colorImage.height = max( gDP.colorImage.height, (unsigned int)lry );
824 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPFillRectangle( %i, %i, %i, %i );\n",
825 ulx, uly, lrx, lry );
829 void gDPSetConvert( s32 k0, s32 k1, s32 k2, s32 k3, s32 k4, s32 k5 )
831 gDP.convert.k0 = k0 * 0.0039215689f;
832 gDP.convert.k1 = k1 * 0.0039215689f;
833 gDP.convert.k2 = k2 * 0.0039215689f;
834 gDP.convert.k3 = k3 * 0.0039215689f;
835 gDP.convert.k4 = k4 * 0.0039215689f;
836 gDP.convert.k5 = k5 * 0.0039215689f;
837 gDP.changed |= CHANGED_CONVERT;
840 void gDPSetKeyR( u32 cR, u32 sR, u32 wR )
842 gDP.key.center.r = cR * 0.0039215689f;;
843 gDP.key.scale.r = sR * 0.0039215689f;;
844 gDP.key.width.r = wR * 0.0039215689f;;
847 void gDPSetKeyGB(u32 cG, u32 sG, u32 wG, u32 cB, u32 sB, u32 wB )
849 gDP.key.center.g = cG * 0.0039215689f;;
850 gDP.key.scale.g = sG * 0.0039215689f;;
851 gDP.key.width.g = wG * 0.0039215689f;;
852 gDP.key.center.b = cB * 0.0039215689f;;
853 gDP.key.scale.b = sB * 0.0039215689f;;
854 gDP.key.width.b = wB * 0.0039215689f;;
857 void gDPTextureRectangle( f32 ulx, f32 uly, f32 lrx, f32 lry, s32 tile, f32 s, f32 t, f32 dsdx, f32 dtdy )
859 if (gDP.colorImage.address == gDP.depthImageAddress)
864 if (gDP.otherMode.cycleType == G_CYC_COPY)
871 gSP.textureTile[0] = &gDP.tiles[tile];
872 gSP.textureTile[1] = &gDP.tiles[(tile < 7) ? (tile + 1) : tile];
877 if (RSP.cmd == G_TEXRECTFLIP)
879 lrs = s + (lry - uly - 1) * dtdy;
880 lrt = t + (lrx - ulx - 1) * dsdx;
884 lrs = s + (lrx - ulx - 1) * dsdx;
885 lrt = t + (lry - uly - 1) * dtdy;
888 if (gDP.textureMode == TEXTUREMODE_NORMAL)
889 gDP.textureMode = TEXTUREMODE_TEXRECT;
891 gDP.texRect.width = (unsigned int)(max( lrs, s ) + dsdx);
892 gDP.texRect.height = (unsigned int)(max( lrt, t ) + dtdy);
897 tmp = ulx; ulx = lrx; lrx = tmp;
898 tmp = s; s = lrs; lrs = tmp;
902 tmp = uly; uly = lry; lry = tmp;
903 tmp = t; t = lrt; lrt = tmp;
906 OGL_DrawTexturedRect( ulx, uly, lrx, lry, s, t, lrs, lrt, (RSP.cmd == G_TEXRECTFLIP));
908 gSP.textureTile[0] = &gDP.tiles[gSP.texture.tile];
909 gSP.textureTile[1] = &gDP.tiles[(gSP.texture.tile < 7) ? (gSP.texture.tile + 1) : gSP.texture.tile];
911 if (depthBuffer.current) depthBuffer.current->cleared = FALSE;
912 gDP.colorImage.changed = TRUE;
913 gDP.colorImage.height = (unsigned int)(max( gDP.colorImage.height, gDP.scissor.lry ));
916 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPTextureRectangle( %f, %f, %f, %f, %i, %f, %f, %f, %f );\n",
917 ulx, uly, lrx, lry, tile, s, t, dsdx, dtdy );
921 void gDPTextureRectangleFlip( f32 ulx, f32 uly, f32 lrx, f32 lry, s32 tile, f32 s, f32 t, f32 dsdx, f32 dtdy )
923 //gDPTextureRectangle( ulx, uly, lrx, lry, tile, s + (lrx - ulx) * dsdx, t + (lry - uly) * dtdy, -dsdx, -dtdy );
925 gDPTextureRectangle( ulx, uly, lrx, lry, tile, s, t, dsdx, dtdy );
927 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPTextureRectangleFlip( %f, %f, %f, %f, %i, %f, %f, %f, %f);\n",
928 ulx, uly, lrx, lry, tile, s, t, dsdx, dtdy );
934 *REG.MI_INTR |= MI_INTR_DP;
939 DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPFullSync();\n" );
946 DebugMsg( DEBUG_HIGH | DEBUG_IGNORED | DEBUG_TEXTURE, "gDPTileSync();\n" );
953 DebugMsg( DEBUG_HIGH | DEBUG_IGNORED, "gDPPipeSync();\n" );
960 DebugMsg( DEBUG_HIGH | DEBUG_IGNORED, "gDPLoadSync();\n" );
967 DebugMsg( DEBUG_HIGH | DEBUG_IGNORED, "gDPNoOp();\n" );