Path: blob/master/libmupen64plus/mupen64plus-video-z64/src/rgl_debugger.cpp
2 views
/*1* z642*3* Copyright (C) 2007 ziggy4*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* (at your option) 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 License along16* with this program; if not, write to the Free Software Foundation, Inc.,17* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.18*19**/2021#include "rdp.h"22#include "rgl.h"2324static const char *saRGBText[] =25{26"PREV", "TEXEL0", "TEXEL1", "PRIM",27"SHADE", "ENV", "NOISE", "1",28"0", "0", "0", "0",29"0", "0", "0", "0"30};3132static const char *mRGBText[] =33{34"PREV", "TEXEL0", "TEXEL1", "PRIM",35"SHADE", "ENV", "SCALE", "PREV_ALPHA",36"TEXEL0_ALPHA", "TEXEL1_ALPHA", "PRIM_ALPHA", "SHADE_ALPHA",37"ENV_ALPHA", "LOD_FRACTION", "PRIM_LOD_FRAC", "K5",38"0", "0", "0", "0",39"0", "0", "0", "0",40"0", "0", "0", "0",41"0", "0", "0", "0"42};4344static const char *aRGBText[] =45{46"PREV", "TEXEL0", "TEXEL1", "PRIM",47"SHADE", "ENV", "1", "0",48};4950static const char *saAText[] =51{52"PREV", "TEXEL0", "TEXEL1", "PRIM",53"SHADE", "ENV", "1", "0",54};5556static const char *sbAText[] =57{58"PREV", "TEXEL0", "TEXEL1", "PRIM",59"SHADE", "ENV", "1", "0",60};6162static const char *mAText[] =63{64"LOD_FRACTION", "TEXEL0", "TEXEL1", "PRIM",65"SHADE", "ENV", "PRIM_LOD_FRAC", "0",66};6768static const char *aAText[] =69{70"PREV", "TEXEL0", "TEXEL1", "PRIM",71"SHADE", "ENV", "1", "0",72};7374const static char * bRGBText[] = { "PREV", "FRAG", "BLEND", "FOG" };75const static char * bAText[2][4] = { {"PREVA", "FOGA", "SHADEA", "0"},76{"(1.0-ALPHA)", "FRAGA", "1", "0"}};7778char * rglCombiner2String(rdpState_t & state)79{80rdpOtherModes_t om = state.otherModes;81int cycle = RDP_GETOM_CYCLE_TYPE(om);82static char res[256];83char * p = res;84if (cycle < 2) {85p += sprintf(86p,87"c = [ (%s - %s) * %s + %s | (%s - %s) * %s + %s ]\n",88saRGBText[RDP_GETCM_SUB_A_RGB0(state.combineModes)],89saRGBText[RDP_GETCM_SUB_B_RGB0(state.combineModes)],90mRGBText[RDP_GETCM_MUL_RGB0(state.combineModes)],91aRGBText[RDP_GETCM_ADD_RGB0(state.combineModes)],92saAText[RDP_GETCM_SUB_A_A0(state.combineModes)],93sbAText[RDP_GETCM_SUB_B_A0(state.combineModes)],94mAText[RDP_GETCM_MUL_A0(state.combineModes)],95aAText[RDP_GETCM_ADD_A0(state.combineModes)]);96}97if (cycle == 1) {98p += sprintf(99p,100"c = [ (%s - %s) * %s + %s | (%s - %s) * %s + %s ]\n",101saRGBText[RDP_GETCM_SUB_A_RGB1(state.combineModes)],102saRGBText[RDP_GETCM_SUB_B_RGB1(state.combineModes)],103mRGBText[RDP_GETCM_MUL_RGB1(state.combineModes)],104aRGBText[RDP_GETCM_ADD_RGB1(state.combineModes)],105saAText[RDP_GETCM_SUB_A_A1(state.combineModes)],106sbAText[RDP_GETCM_SUB_B_A1(state.combineModes)],107mAText[RDP_GETCM_MUL_A1(state.combineModes)],108aAText[RDP_GETCM_ADD_A1(state.combineModes)]);109}110if (cycle < 2) {111p += sprintf(112p,113"%s*%s + %s*%s\n"114,bAText[0][RDP_GETOM_BLEND_M1B_0(state.otherModes)],115bRGBText[RDP_GETOM_BLEND_M1A_0(state.otherModes)],116bAText[1][RDP_GETOM_BLEND_M2B_0(state.otherModes)],117bRGBText[RDP_GETOM_BLEND_M2A_0(state.otherModes)]118);119}120if (cycle == 1) {121p += sprintf(122p,123"%s*%s + %s*%s\n"124,bAText[0][RDP_GETOM_BLEND_M1B_1(state.otherModes)],125bRGBText[RDP_GETOM_BLEND_M1A_1(state.otherModes)],126bAText[1][RDP_GETOM_BLEND_M2B_1(state.otherModes)],127bRGBText[RDP_GETOM_BLEND_M2A_1(state.otherModes)]128);129}130return res;131}132133#ifdef RDP_DEBUG134135#include <SDL.h>136//#include <IL/il.h>137#include <assert.h>138139#include <FTGLTextureFont.h>140141#define FONT "LucidaTypewriterRegular.ttf"142#define SMALLFONT "LucidaTypewriterRegular.ttf"143//#define SMALLFONT "/usr/share/fonts/corefonts/arial.ttf"144#define FS 12145#define SMALLFS 12146147static FTFont * font;148static FTFont * smallfont;149static FTFont * curfont;150151static int fbindex;152static int chunkindex, stripindex;153static int mx, my;154static float scalex, scaley;155static rglShader_t * alphaShader;156157static int lines[0x10000], nblines;158static char dasm[512];159160void gglPrint(int x, int y, const char * text)161{162glPushAttrib(GL_ALL_ATTRIB_BITS);163glPushMatrix();164glTranslatef(x, y, 0);165166glEnable( GL_TEXTURE_2D);167glDisable( GL_DEPTH_TEST);168//glRasterPos2i( x , y);169curfont->Render(text);170171glPopMatrix();172glPopAttrib();173174//printf("%s\n", text);175}176177void gglPrintf(int x, int y, const char * s, ...)178{179char buf[1024];180va_list ap;181va_start(ap, s);182vsprintf(buf, s, ap);183va_end(ap);184gglPrint(x, y, buf);185}186187void rglDisplayTrace(int x, int y, int start, int lines)188{189glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );190rglUseShader(0);191curfont = smallfont;192start = ::lines[start];193while (lines-->0 && start <= rdpTracePos) {194glColor4f(0,0,0, 0.5);195glEnable(GL_BLEND);196glDisable(GL_TEXTURE_2D);197glBegin(GL_TRIANGLE_STRIP);198glVertex2f(x, y);199glVertex2f(x+2*screen_width*3/4, y);200glVertex2f(x, y-(SMALLFS+2));201glVertex2f(x+2*screen_width*3/4, y-(SMALLFS+2));202glEnd();203204glColor4f(1,1,0.5,1);205glDisable(GL_BLEND);206start += rdp_dasm(rdpTraceBuf, start, start+256, dasm)/4;207gglPrintf(x, y-(SMALLFS), "%4x %s", start, dasm);208y -= (SMALLFS+2);209}210curfont = font;211// glDisable(GL_BLEND);212}213214void rglDisplayColor(uint32_t color, int x , int y, const char * name, int sixteen = 0)215{216float r, g, b, a;217if (sixteen) {218r = RDP_GETC16_R(color)/ 31.0f;219g = RDP_GETC16_G(color)/ 31.0f;220b = RDP_GETC16_B(color)/ 31.0f;221a = RDP_GETC16_A(color)/ 1.0f;222} else {223r = RDP_GETC32_R(color)/255.0f;224g = RDP_GETC32_G(color)/255.0f;225b = RDP_GETC32_B(color)/255.0f;226a = RDP_GETC32_A(color)/255.0f;227}228y -= FS+2;229glColor4f(r, g, b, 1);230glDisable(GL_TEXTURE_2D);231glBegin(GL_TRIANGLE_STRIP);232glVertex2f(x, y);233glVertex2f(x+128, y);234glVertex2f(x, y-16);235glVertex2f(x+128, y-16);236glEnd();237238glEnable(GL_TEXTURE_2D);239glColor4f(1,1,1,1);240gglPrintf(x, y+2, "%5s %08x", name, color);241242}243244void rglDisplayChunkInfo(rglRenderChunk_t & chunk)245{246int x = 0, y = screen_height;247int i;248rdpState_t & state = chunk.rdpState;249rdpOtherModes_t om = state.otherModes;250rdpCombineModes_t cm = state.combineModes;251int cycle = RDP_GETOM_CYCLE_TYPE(om);252253rglDisplayColor(chunk.rdpState.primColor, x, y, "prim");254y -= 16+FS+10;255rglDisplayColor(chunk.rdpState.blendColor, x, y, "blend");256y -= 16+FS+10;257rglDisplayColor(chunk.rdpState.envColor, x, y, "env");258y -= 16+FS+10;259rglDisplayColor(chunk.rdpState.fogColor, x, y, "fog");260y -= 16+FS+10;261rglDisplayColor(chunk.rdpState.fillColor, x, y, "fill", 1);262y -= 16+FS+10;263264y += 5*(16+FS+10);265x += 128+20;266267glColor4f(1,1,1,1);268int oldy = y;269for (i=0; i<8; i++) {270int j;271int oldx = x;272if (!(chunk.flags & (1<<i))) continue;273rglTile_t & tile = chunk.tiles[i];274int w = tile.w, h = tile.h;275if (w > 64) w = 64;276if (h > 64) h = 64;277gglPrintf(x, y-h-FS, "#%d %dx%d %x", i, tile.w, tile.h, tile.hiresBuffer? 0 : tile.tex->crc);278gglPrintf(x, y-h-2*FS, "fmt %s-%d %d %d", rdpImageFormats[tile.format], tile.size, tile.line, tile.hiresBuffer? tile.hiresBuffer-rBuffers : -1);279gglPrintf(x, y-h-3*FS, "clip %dx%d %dx%d", tile.sl, tile.tl, tile.sh, tile.th);280gglPrintf(x, y-h-4*FS, "mask %dx%d shift %dx%d", tile.mask_s, tile.mask_t, tile.shift_s, tile.shift_t);281gglPrintf(x, y-h-5*FS, "%d %d %d %d pal %d", tile.cs, tile.ms, tile.ct, tile.ms, tile.palette);282glEnable(GL_TEXTURE_2D);283if (tile.hiresBuffer)284glBindTexture(GL_TEXTURE_2D, tile.hiresBuffer->texid);285else286glBindTexture(GL_TEXTURE_2D, tile.tex->id);287for (j=0; j<2; j++) {288glBegin(GL_TRIANGLE_STRIP);289glTexCoord2f(0, 0); glVertex2f(x, y);290glTexCoord2f(0, 1); glVertex2f(x, y-h);291glTexCoord2f(1, 0); glVertex2f(x+w, y);292glTexCoord2f(1, 1); glVertex2f(x+w, y-h);293glEnd();294rglUseShader(alphaShader);295x += w+2;296}297rglUseShader(0);298// if ((tile.w+2)*2 < 256)299// x += 256 - (tile.w+2)*2;300x = oldx;301y -= h + 5*FS + 5;302}303304y = oldy;305x = 128+210;306307y -= FS;308gglPrintf(x, y, "cycle %d persp %d detail %d sharpen %d tex_lod %d en_tlut %d tlut_type %d clipm %d",309RDP_GETOM_CYCLE_TYPE(om),310RDP_GETOM_PERSP_TEX_EN(om),311RDP_GETOM_DETAIL_TEX_EN(om),312RDP_GETOM_SHARPEN_TEX_EN(om),313RDP_GETOM_TEX_LOD_EN(om),314RDP_GETOM_EN_TLUT(om),315RDP_GETOM_TLUT_TYPE(om),316chunk.rdpState.clipMode);317318y -= FS;319gglPrintf(x, y, "sample_type %d mid %d lerp0 %d lerp1 %d convert1 %d key_en %d rgb_dith_sel %d",320RDP_GETOM_SAMPLE_TYPE(om),321RDP_GETOM_MID_TEXEL(om),322RDP_GETOM_BI_LERP0(om),323RDP_GETOM_BI_LERP1(om),324RDP_GETOM_CONVERT_ONE(om),325RDP_GETOM_KEY_EN(om),326RDP_GETOM_RGB_DITHER_SEL(om));327328y -= FS;329gglPrintf(x, y, "A_dith_sel %d force_blend %d A_cvg_sel %d cvgXA %d Zmode %d cvg_dest %d col_on %d",330RDP_GETOM_ALPHA_DITHER_SEL(om),331RDP_GETOM_FORCE_BLEND(om),332RDP_GETOM_ALPHA_CVG_SELECT(om),333RDP_GETOM_CVG_TIMES_ALPHA(om),334RDP_GETOM_Z_MODE(om),335RDP_GETOM_CVG_DEST(om),336RDP_GETOM_COLOR_ON_CVG(om));337338y -= FS;339gglPrintf(x, y, "img_read %d Zupdate %d Zcmp_sel %d antialias %d Zsource %d dith_A_en %d A_cmp %d",340RDP_GETOM_IMAGE_READ_EN(om),341RDP_GETOM_Z_UPDATE_EN(om),342RDP_GETOM_Z_COMPARE_EN(om),343RDP_GETOM_ANTIALIAS_EN(om),344RDP_GETOM_Z_SOURCE_SEL(om),345RDP_GETOM_DITHER_ALPHA_EN(om),346RDP_GETOM_ALPHA_COMPARE_EN(om));347348y -= 2*FS;349350if (cycle < 2) {351gglPrintf(x, y,352"c = [ (%s - %s) * %s + %s | (%s - %s) * %s + %s ];",353saRGBText[RDP_GETCM_SUB_A_RGB0(state.combineModes)],354saRGBText[RDP_GETCM_SUB_B_RGB0(state.combineModes)],355mRGBText[RDP_GETCM_MUL_RGB0(state.combineModes)],356aRGBText[RDP_GETCM_ADD_RGB0(state.combineModes)],357saAText[RDP_GETCM_SUB_A_A0(state.combineModes)],358sbAText[RDP_GETCM_SUB_B_A0(state.combineModes)],359mAText[RDP_GETCM_MUL_A0(state.combineModes)],360aAText[RDP_GETCM_ADD_A0(state.combineModes)]);361362y -= FS;363}364if (cycle == 1) {365//if (cycle < 2) {366gglPrintf(x, y,367"c = [ (%s - %s) * %s + %s | (%s - %s) * %s + %s ];",368saRGBText[RDP_GETCM_SUB_A_RGB1(state.combineModes)],369saRGBText[RDP_GETCM_SUB_B_RGB1(state.combineModes)],370mRGBText[RDP_GETCM_MUL_RGB1(state.combineModes)],371aRGBText[RDP_GETCM_ADD_RGB1(state.combineModes)],372saAText[RDP_GETCM_SUB_A_A1(state.combineModes)],373sbAText[RDP_GETCM_SUB_B_A1(state.combineModes)],374mAText[RDP_GETCM_MUL_A1(state.combineModes)],375aAText[RDP_GETCM_ADD_A1(state.combineModes)]);376377y -= FS;378}379if (cycle < 2) {380gglPrintf(x, y,381"%s*%s + %s*%s"382,bAText[0][RDP_GETOM_BLEND_M1B_0(state.otherModes)],383bRGBText[RDP_GETOM_BLEND_M1A_0(state.otherModes)],384bAText[1][RDP_GETOM_BLEND_M2B_0(state.otherModes)],385bRGBText[RDP_GETOM_BLEND_M2A_0(state.otherModes)]386);387388y -= FS;389}390if (cycle == 1) {391//if (cycle < 2) {392gglPrintf(x, y,393"%s*%s + %s*%s"394,bAText[0][RDP_GETOM_BLEND_M1B_1(state.otherModes)],395bRGBText[RDP_GETOM_BLEND_M1A_1(state.otherModes)],396bAText[1][RDP_GETOM_BLEND_M2B_1(state.otherModes)],397bRGBText[RDP_GETOM_BLEND_M2A_1(state.otherModes)]398);399400y -= FS;401}402403if (chunk.nbStrips) {404y -= FS;405rglStrip_t & strip = chunk.strips[chunkindex >= 0? stripindex:0];406407int i;408for (i=0; i<strip.nbVtxs; i++) {409rglVertex_t vtx = strip.vtxs[i];410int oldx;411gglPrintf(x, y, "%g %g %g %g", vtx.x, vtx.y, vtx.z, vtx.w);412x += 256;413if (strip.flags & RGL_STRIP_SHADE) {414gglPrintf(x, y, "%d %d %d %d", vtx.r, vtx.g, vtx.b, vtx.a);415x += 200;416}417if (strip.flags & (RGL_STRIP_TEX1|RGL_STRIP_TEX2)) {418gglPrintf(x, y, "%g %g", vtx.s, vtx.t);419x += 192;420}421y -= FS;422x = oldx;423}424}425426// LOG("missing om %x %x (%x %x)\n",427// chunk.rdpState.otherModes.w1&RDP_OM_MISSING1,428// chunk.rdpState.otherModes.w2&RDP_OM_MISSING2,429// RDP_OM_MISSING1,430// RDP_OM_MISSING2);431// LOG("missing cm %x %x\n",432// chunk.rdpState.combineModes.w1&~(RDP_COMBINE_MASK11|RDP_COMBINE_MASK21),433// chunk.rdpState.combineModes.w2&~(RDP_COMBINE_MASK12|RDP_COMBINE_MASK22));434}435436void rglDisplayFramebuffer(rglRenderBuffer_t & buffer, int alpha)437{438int i;439440if (alpha)441rglUseShader(alphaShader);442else443rglUseShader(rglCopyShader);444glBindTexture(GL_TEXTURE_2D, buffer.texid);445glEnable(GL_TEXTURE_2D);446glDisable(GL_DEPTH_TEST);447glDisable(GL_BLEND);448glColor4ub(255, 255, 255, 255);449glBegin(GL_TRIANGLE_STRIP);450glTexCoord2f(1, 1); glVertex2f(1, 0);451glTexCoord2f(0, 1); glVertex2f(0, 0);452glTexCoord2f(1, 0); glVertex2f(1, 1);453glTexCoord2f(0, 0); glVertex2f(0, 1);454glEnd();455}456457void rglDisplayFlat(rglRenderChunk_t & chunk)458{459int j;460rglRenderBuffer_t & buffer = *chunk.renderBuffer;461462glPushAttrib(GL_ALL_ATTRIB_BITS);463//glEnable(GL_SCISSOR_TEST);464rglUseShader(0);465glDisable(GL_TEXTURE_2D);466glDisable(GL_CULL_FACE);467468// glScissor((chunk.rdpState.clip.xh >>2)*buffer.realWidth/buffer.width,469// (chunk.rdpState.clip.yh >>2)*buffer.realHeight/buffer.height,470// (chunk.rdpState.clip.xl-chunk.rdpState.clip.xh >>2)*buffer.realWidth/buffer.width,471// (chunk.rdpState.clip.yl-chunk.rdpState.clip.yh >>2)*buffer.realHeight/buffer.height);472473474for (j=0; j<chunk.nbStrips; j++) {475rglStrip_t & strip = chunk.strips[j];476int k;477478if (chunkindex >= 0 && j == stripindex) {479glPushAttrib(GL_ALL_ATTRIB_BITS);480glColor4ub(255, 255, 128, 255);481}482glBegin(GL_TRIANGLE_STRIP);483for (k=0; k<strip.nbVtxs; k++) {484glVertex2f((strip.vtxs[k].x/(buffer.width)),4851-(strip.vtxs[k].y/(buffer.height)));486}487glEnd();488if (chunkindex >= 0 && j == stripindex)489glPopAttrib();490}491492glPopAttrib();493}494495int rglFindStrip(rglRenderChunk_t & chunk, float mx, float my)496{497int j;498rglRenderBuffer_t & buffer = *chunk.renderBuffer;499for (j=chunk.nbStrips-1; j>=0; j--) {500rglStrip_t & strip = chunk.strips[j];501int k;502struct { float x, y; } s[3];503504for (k=0; k<strip.nbVtxs; k++) {505s[0] = s[1];506s[1] = s[2];507s[2].x = strip.vtxs[k].x/(buffer.width);508s[2].y = 1 - strip.vtxs[k].y/(buffer.height);509if (k >= 2) {510float last = 0;511int i;512for (i=0; i<3; i++) {513float dx1 = s[(i+1)%3].x - s[i].x;514float dy1 = s[(i+1)%3].y - s[i].y;515float dx2 = mx - s[i].x;516float dy2 = my - s[i].y;517dx1 = dx1*dy2-dx2*dy1;518if (dx1 == 0) goto next;519if (last*dx1 < 0)520goto next;521last = dx1;522}523stripindex = j;524return j;525next:;526}527}528}529return -1;530}531532void rglDisplayFlat(rglRenderBuffer_t & buffer)533{534int i;535for (i=0; i<nbChunks; i++) {536rglRenderChunk_t & chunk = chunks[i];537if (chunk.renderBuffer != &buffer) continue;538rglDisplayFlat(chunk);539}540}541542int rglFindChunk(rglRenderBuffer_t & buffer, float mx, float my)543{544int i;545if (chunkindex <= 0)546i = nbChunks-1;547else548i = chunkindex-1;549for (; i>=0; i--) {550rglRenderChunk_t & chunk = chunks[i];551if (chunk.renderBuffer != &buffer) continue;552if (rglFindStrip(chunk, mx, my) >= 0)553return i;554}555return -1;556}557558void rglShowCursor(int state)559{560#ifdef WIN32561#else562SDL_ShowCursor(state);563#endif564}565566#ifndef WIN32567static int keys[512];568#define MOUSEBUT 511569#else570# define MOUSEBUT VK_LBUTTON571# define SDLK_ESCAPE VK_ESCAPE572# define SDLK_KP_PLUS VK_ADD573# define SDLK_KP_MINUS VK_SUBTRACT574# define SDLK_TAB VK_TAB575# define SDLK_UP VK_UP576# define SDLK_DOWN VK_DOWN577# define SDLK_PAGEUP VK_PRIOR578# define SDLK_PAGEDOWN VK_NEXT579#endif580581int rglCheckKey(int key)582{583#ifdef WIN32584return GetAsyncKeyState (key) & 1;585#else586if (key >= 'A' && key <= 'Z') key += 'a' - 'A';587int res = keys[key];588keys[key] = 0;589return res;590#endif591}592593void rglDebugger()594{595SDL_Event event;596int paused = 1;597int i, j;598int traceX = 1;599int tracepos = 0;600int tracepage = (screen_height*3/4)/(SMALLFS+2);601int oldchunkindex = -1;602603fbindex = 0;604chunkindex = -1;605606void rglInitDebugger();607rglInitDebugger();608609rglShowCursor(SDL_ENABLE);610611glActiveTextureARB(GL_TEXTURE1_ARB);612glDisable(GL_TEXTURE_2D);613glActiveTextureARB(GL_TEXTURE2_ARB);614glDisable(GL_TEXTURE_2D);615glActiveTextureARB(GL_TEXTURE0_ARB);616glDrawBuffer(GL_BACK);617618for (i=nblines=0; i<=rdpTracePos; i += rdp_dasm(rdpTraceBuf, i, i+256, dasm)/4, nblines++)619lines[nblines] = i;620621if (nbChunks > 1)622// skip chunk 0 as it's usually depth clear623fbindex = chunks[1].renderBuffer - rBuffers;624625while (paused) {626#ifndef WIN32627int res = SDL_WaitEvent(&event);628while (res) {629switch (event.type) {630case SDL_MOUSEBUTTONDOWN:631keys[MOUSEBUT] = 1;632break;633case SDL_MOUSEBUTTONUP:634keys[MOUSEBUT] = 0;635break;636case SDL_KEYDOWN:637if (event.key.keysym.sym < MOUSEBUT)638keys[event.key.keysym.sym] = 1;639break;640case SDL_KEYUP:641if (event.key.keysym.sym < MOUSEBUT)642keys[event.key.keysym.sym] = 0;643break;644}645res = SDL_PollEvent(&event);646}647#endif648rglRenderBuffer_t & buffer = rBuffers[fbindex];649scalex = buffer.realWidth; scaley = buffer.realHeight;650651if (rBuffers[fbindex].fbid) {652if (buffer.realWidth > scalex*3/4 ||653buffer.realHeight > scaley*3/4) {654scalex = scalex*3/4;655scaley = scaley*3/4;656}657}658659if (rglCheckKey(MOUSEBUT)) {660if (buffer.fbid) {661#ifdef WIN32662POINT pt;663GetCursorPos(&pt);664mx = pt.x;665my = pt.y;666#else667SDL_GetMouseState(&mx, &my);668#endif669int old = chunkindex;670if (old >= 0)671chunkindex++;672chunkindex = rglFindChunk(buffer, float(mx)/scalex, float(screen_height - my)/scaley);673if (old >= 0 && chunkindex == old) {674} else {675chunkindex = -1;676}677chunkindex = rglFindChunk(buffer, float(mx)/scalex, float(screen_height - my)/scaley);678if (chunkindex >= 0 && nbChunks)679printf("%s\n", chunks[chunkindex].shader->fsrc);680}681}682if (rglCheckKey('P') || rglCheckKey(SDLK_ESCAPE))683paused = 0;684if (rglCheckKey(SDLK_KP_PLUS)) {685if (fbindex < MAX_RENDER_BUFFERS-1/* &&686rBuffers[fbindex+1].fbid*/)687fbindex++;688chunkindex = -1;689}690if (rglCheckKey(SDLK_KP_MINUS)) {691if (fbindex > 0/* &&692rBuffers[fbindex-1].fbid*/)693fbindex--;694chunkindex = -1;695}696if (rglCheckKey(SDLK_TAB))697traceX = !traceX;698if (rglCheckKey(SDLK_UP))699tracepos--;700if (rglCheckKey(SDLK_DOWN))701tracepos++;702if (rglCheckKey(SDLK_PAGEUP))703tracepos -= tracepage/2;704if (rglCheckKey(SDLK_PAGEDOWN))705tracepos += tracepage/2;706if (tracepos < 0)707tracepos = 0;708if (tracepos > nblines-tracepage/2)709tracepos = nblines-tracepage/2;710711//rglRenderChunks();712713glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);714glDrawBuffer(GL_BACK);715glDisable(GL_SCISSOR_TEST);716glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);717glActiveTextureARB(GL_TEXTURE1_ARB);718glDisable(GL_TEXTURE_2D);719glActiveTextureARB(GL_TEXTURE0_ARB);720glDisable(GL_ALPHA_TEST);721722glClearColor(0, 0, 0, 0);723glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);724glClear(GL_COLOR_BUFFER_BIT);725726if (buffer.fbid) {727//glViewport(0, 0, scalex*screen_width/buffer.realWidth, scaley*screen_height/buffer.realHeight);728glViewport(0, 0, scalex, scaley);729rglDisplayFramebuffer(buffer, 0);730glViewport(scalex, 0, scalex, scaley);731rglDisplayFramebuffer(buffer, 1);732733glViewport(0, 0, scalex, scaley);734glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);735glEnable(GL_BLEND);736//glBlendFunc( GL_ONE, GL_ONE );737glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_DST_COLOR);738if (chunkindex < 0) {739//glColor4f(0.1, 0, 0.1, 0.5);740glColor4f(0.6, 0, 0.6, 0.5);741rglDisplayFlat(buffer);742} else {743glColor4f(0.6, 0, 0.6, 0.5);744rglDisplayFlat(chunks[chunkindex]);745}746}747748{749glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);750glDisable(GL_BLEND);751752753glMatrixMode( GL_PROJECTION);754glPushMatrix();755glLoadIdentity();756gluOrtho2D(0, screen_width, 0, screen_height);757glMatrixMode(GL_MODELVIEW);758glPushMatrix();759glLoadIdentity();760761glViewport(0, 0, screen_width, screen_height);762rglUseShader(0);763764glColor3f(1,0.5,0.5);765gglPrintf(0, 0, "Fb #%d at $%x --> %x (%dx%d fmt %s-%d) upto %d %s", fbindex,766buffer.addressStart, buffer.addressStop,767buffer.width, buffer.height,768(buffer.flags & RGL_RB_DEPTH)? "Z":rdpImageFormats[buffer.format], buffer.size,769buffer.chunkId,770(buffer.flags & RGL_RB_ERASED)? "ERASED":"");771772if (chunkindex >= 0) {773gglPrintf(0, FS, "Chunk #%d", chunkindex);774775rglDisplayChunkInfo(chunks[chunkindex]);776}777778if (oldchunkindex != chunkindex) {779oldchunkindex = chunkindex;780if (chunkindex >= 0)781for (i=0; i<nblines; i++)782if (lines[i] == chunks[chunkindex].tracePos)783tracepos = i;784}785rglDisplayTrace(traceX*scalex, screen_height*3/4, tracepos, tracepage);786787glMatrixMode( GL_PROJECTION);788glPopMatrix();789glMatrixMode(GL_MODELVIEW);790glPopMatrix();791}792793rglSwapBuffers();794}795796rglShowCursor(SDL_DISABLE);797}798799void rglCloseDebugger()800{801if (font) {802delete font;803font = 0;804}805if (smallfont) {806delete smallfont;807smallfont = 0;808}809if (alphaShader) {810rglDeleteShader(alphaShader);811alphaShader = 0;812}813}814815void rglInitDebugger()816{817if (!font) {818char s[1024];819extern char rgl_cwd[512];820sprintf(s, "%s/"FONT, rgl_cwd);821curfont = font = new FTGLTextureFont(s);822sprintf(s, "%s/"SMALLFONT, rgl_cwd);823smallfont = new FTGLTextureFont(s);824if (!font || !smallfont) {825LOGERROR("Couldn't load font '%s'\n", s);826return;827}828font->FaceSize(FS);829smallfont->FaceSize(SMALLFS);830}831832if (!alphaShader) {833alphaShader = rglCreateShader(834"void main() \n"835"{ \n"836" gl_Position = ftransform(); \n"837" gl_FrontColor = gl_Color; \n"838" gl_TexCoord[0] = gl_MultiTexCoord0; \n"839"} \n"840,841"uniform sampler2D texture0; \n"842" \n"843"void main() \n"844"{ \n"845" gl_FragColor = gl_Color * texture2D(texture0, vec2(gl_TexCoord[0])).a; \n"846"} \n"847);848}849}850851void rdpBacktrace()852{853int i=0;854while (i <= rdpTracePos) {855i += rdp_dasm(rdpTraceBuf, i, i+256, dasm)/4;856printf("%4x %s\n", i, dasm);857}858}859860#endif861862863