shit renderer
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <signal.h>
|
||||
#include <execinfo.h>
|
||||
#include <unistd.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
static void sigsegv_handler(int sig) {
|
||||
const char msg[] = "\n=== SIGNAL CAUGHT: ";
|
||||
write(STDERR_FILENO, msg, sizeof(msg)-1);
|
||||
@@ -868,6 +869,71 @@ pDevice->SetSamplerState(0,SamplerStateModes[i],SamplerStateA[i]);
|
||||
|
||||
RenderManager.Set_matrixDirty();
|
||||
#endif
|
||||
|
||||
// DEBUG: Dump framebuffer to file once after game has been running a while
|
||||
{
|
||||
static int _fbDumpFrame = 0;
|
||||
_fbDumpFrame++;
|
||||
if (_fbDumpFrame == 2000 || _fbDumpFrame == 4000) {
|
||||
// Test: is GL context current? Force red clear before read.
|
||||
void* curCtx = glfwGetCurrentContext();
|
||||
fprintf(stderr, "[FBDUMP] frame=%d glfwGetCurrentContext()=%p\n", _fbDumpFrame, curCtx);
|
||||
fflush(stderr);
|
||||
// Read the ACTUAL rendered framebuffer first
|
||||
int fbW, fbH;
|
||||
RenderManager.GetFramebufferSize(fbW, fbH);
|
||||
int sz = fbW * fbH * 3;
|
||||
unsigned char *pixels = (unsigned char*)malloc(sz);
|
||||
if (pixels) {
|
||||
::glReadPixels(0, 0, fbW, fbH, GL_RGB, GL_UNSIGNED_BYTE, pixels);
|
||||
GLenum err = glGetError();
|
||||
fprintf(stderr, "[FBDUMP] glReadPixels err=0x%x size=%dx%d\n", err, fbW, fbH);
|
||||
// Check bound framebuffer
|
||||
GLint boundFBO = -1;
|
||||
#ifndef GL_FRAMEBUFFER_BINDING
|
||||
#define GL_FRAMEBUFFER_BINDING 0x8CA6
|
||||
#endif
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &boundFBO);
|
||||
GLint drawBuf = 0;
|
||||
glGetIntegerv(GL_DRAW_BUFFER, &drawBuf);
|
||||
GLint readBuf = 0;
|
||||
glGetIntegerv(GL_READ_BUFFER, &readBuf);
|
||||
fprintf(stderr, "[FBDUMP] FBO=%d drawBuf=0x%x readBuf=0x%x\n", boundFBO, drawBuf, readBuf);
|
||||
fflush(stderr);
|
||||
char fname[128];
|
||||
snprintf(fname, sizeof(fname), "/tmp/fb_dump_%d.ppm", _fbDumpFrame);
|
||||
FILE *fp = fopen(fname, "wb");
|
||||
if (fp) {
|
||||
fprintf(fp, "P6\n%d %d\n255\n", fbW, fbH);
|
||||
for (int y = fbH - 1; y >= 0; y--) {
|
||||
fwrite(pixels + y * fbW * 3, 1, fbW * 3, fp);
|
||||
}
|
||||
fclose(fp);
|
||||
fprintf(stderr, "[RENDER] Dumped framebuffer %dx%d to %s\n", fbW, fbH, fname);
|
||||
fflush(stderr);
|
||||
}
|
||||
// Now force a red clear and dump again to verify GL context works
|
||||
::glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
::glClear(GL_COLOR_BUFFER_BIT);
|
||||
::glFinish();
|
||||
::glReadPixels(0, 0, fbW, fbH, GL_RGB, GL_UNSIGNED_BYTE, pixels);
|
||||
char fname2[128];
|
||||
snprintf(fname2, sizeof(fname2), "/tmp/fb_dump_%d_RED.ppm", _fbDumpFrame);
|
||||
FILE *fp2 = fopen(fname2, "wb");
|
||||
if (fp2) {
|
||||
fprintf(fp2, "P6\n%d %d\n255\n", fbW, fbH);
|
||||
for (int y = fbH - 1; y >= 0; y--) {
|
||||
fwrite(pixels + y * fbW * 3, 1, fbW * 3, fp2);
|
||||
}
|
||||
fclose(fp2);
|
||||
fprintf(stderr, "[RENDER] Dumped RED test %dx%d to %s\n", fbW, fbH, fname2);
|
||||
fflush(stderr);
|
||||
}
|
||||
free(pixels);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Present the frame.
|
||||
RenderManager.Present();
|
||||
|
||||
|
||||
@@ -995,13 +995,6 @@ int GameRenderer::getLightTexture(int iPad, Level *level)
|
||||
|
||||
void GameRenderer::render(float a, bool bFirst)
|
||||
{
|
||||
static int _dbgRenderCount = 0;
|
||||
_dbgRenderCount++;
|
||||
if (_dbgRenderCount <= 5 || (_dbgRenderCount % 300 == 0)) {
|
||||
fprintf(stderr, "[RENDER] GameRenderer::render frame=%d level=%p screen=%p width=%d height=%d\n",
|
||||
_dbgRenderCount, (void*)mc->level, (void*)mc->screen, mc->width, mc->height);
|
||||
fflush(stderr);
|
||||
}
|
||||
if( _updateLightTexture && bFirst) updateLightTexture(a);
|
||||
if (Display::isActive())
|
||||
{
|
||||
@@ -1087,6 +1080,7 @@ void GameRenderer::render(float a, bool bFirst)
|
||||
else
|
||||
{
|
||||
glViewport(0, 0, mc->width, mc->height);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
@@ -1261,17 +1255,6 @@ void GameRenderer::DisableUpdateThread()
|
||||
|
||||
void GameRenderer::renderLevel(float a, __int64 until)
|
||||
{
|
||||
static int _dbgRLCount = 0;
|
||||
_dbgRLCount++;
|
||||
if (_dbgRLCount <= 3 || (_dbgRLCount % 300 == 0)) {
|
||||
fprintf(stderr, "[RENDER] renderLevel frame=%d player=%p levelRenderer=%p\n",
|
||||
_dbgRLCount, (void*)mc->player.get(), (void*)mc->levelRenderer);
|
||||
if (mc->player) {
|
||||
fprintf(stderr, "[RENDER] playerPos=(%.1f, %.1f, %.1f)\n",
|
||||
mc->player->x, mc->player->y, mc->player->z);
|
||||
}
|
||||
fflush(stderr);
|
||||
}
|
||||
// if (updateLightTexture) updateLightTexture(); // 4J - TODO - Java 1.0.1 has this line enabled, should check why - don't want to put it in now in case it breaks split-screen
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
@@ -1311,6 +1294,23 @@ void GameRenderer::renderLevel(float a, __int64 until)
|
||||
|
||||
setupCamera(a, i);
|
||||
Camera::prepare(mc->player, mc->player->ThirdPersonView() == 2);
|
||||
// DEBUG: Log camera-relevant state
|
||||
static int _dbgCam = 0;
|
||||
_dbgCam++;
|
||||
if (_dbgCam <= 5 || (_dbgCam % 300 == 0)) {
|
||||
float mv[16]; ::glGetFloatv(GL_MODELVIEW_MATRIX, mv);
|
||||
float pj[16]; ::glGetFloatv(GL_PROJECTION_MATRIX, pj);
|
||||
float cc[4]; ::glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
|
||||
int vp[4]; ::glGetIntegerv(GL_VIEWPORT, vp);
|
||||
fprintf(stderr, "[RENDER] CAM frame=%d viewport=(%d,%d,%d,%d) clearColor=(%.2f,%.2f,%.2f) renderDist=%.0f\n",
|
||||
_dbgCam, vp[0], vp[1], vp[2], vp[3], cc[0], cc[1], cc[2], renderDistance);
|
||||
fprintf(stderr, "[RENDER] MV[12..14]=(%f,%f,%f) PJ[0,5,10]=(%f,%f,%f)\n",
|
||||
mv[12], mv[13], mv[14], pj[0], pj[5], pj[10]);
|
||||
fprintf(stderr, "[RENDER] cameraEntity pos=(%.2f,%.2f,%.2f) heightOff=%.2f\n",
|
||||
mc->cameraTargetPlayer->x, mc->cameraTargetPlayer->y, mc->cameraTargetPlayer->z,
|
||||
mc->cameraTargetPlayer->heightOffset);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
Frustum::getFrustum();
|
||||
if (mc->options->viewDistance < 2)
|
||||
|
||||
@@ -778,24 +778,34 @@ int LevelRenderer::renderChunks(int from, int to, int layer, double alpha)
|
||||
|
||||
bool first = true;
|
||||
int count = 0;
|
||||
int dbgNotVisible = 0, dbgNoIdx = 0, dbgEmpty = 0, dbgCalled = 0, dbgCallOk = 0;
|
||||
ClipChunk *pClipChunk = chunks[playerIndex].data;
|
||||
unsigned char emptyFlag = LevelRenderer::CHUNK_FLAG_EMPTY0 << layer;
|
||||
for( int i = 0; i < chunks[playerIndex].length; i++, pClipChunk++ )
|
||||
{
|
||||
if( !pClipChunk->visible ) continue; // This will be set if the chunk isn't visible, or isn't compiled, or has both empty flags set
|
||||
if( pClipChunk->globalIdx == -1 ) continue; // Not sure if we should ever encounter this... TODO check
|
||||
if( ( globalChunkFlags[pClipChunk->globalIdx] & emptyFlag ) == emptyFlag ) continue; // Check that this particular layer isn't empty
|
||||
if( !pClipChunk->visible ) { dbgNotVisible++; continue; }
|
||||
if( pClipChunk->globalIdx == -1 ) { dbgNoIdx++; continue; }
|
||||
if( ( globalChunkFlags[pClipChunk->globalIdx] & emptyFlag ) == emptyFlag ) { dbgEmpty++; continue; }
|
||||
|
||||
// List can be calculated directly from the chunk's global idex
|
||||
int list = pClipChunk->globalIdx * 2 + layer;
|
||||
list += chunkLists;
|
||||
|
||||
dbgCalled++;
|
||||
if(RenderManager.CBuffCall(list, first))
|
||||
{
|
||||
first = false;
|
||||
dbgCallOk++;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
static int _dbgRC = 0;
|
||||
_dbgRC++;
|
||||
if (_dbgRC <= 5 || (_dbgRC % 600 == 0)) {
|
||||
fprintf(stderr, "[RENDER] renderChunks frame=%d layer=%d total=%d notVis=%d noIdx=%d empty=%d called=%d callOk=%d xOff=%.1f yOff=%.1f zOff=%.1f chunkLists=%d\n",
|
||||
_dbgRC, layer, chunks[playerIndex].length, dbgNotVisible, dbgNoIdx, dbgEmpty, dbgCalled, dbgCallOk, xOff, yOff, zOff, chunkLists);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
#ifdef __PSVITA__
|
||||
// AP - alpha cut out is expensive on vita. Now we render all the alpha cut outs
|
||||
|
||||
Reference in New Issue
Block a user