aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/GPU3D_Soft.cpp36
-rw-r--r--src/Platform.h1
-rw-r--r--src/wx/Platform.cpp5
3 files changed, 30 insertions, 12 deletions
diff --git a/src/GPU3D_Soft.cpp b/src/GPU3D_Soft.cpp
index b781de8..d306a53 100644
--- a/src/GPU3D_Soft.cpp
+++ b/src/GPU3D_Soft.cpp
@@ -43,6 +43,7 @@ u8 StencilBuffer[256*2];
void* RenderThread;
bool RenderThreadRunning;
+bool RenderThreadRendering;
void* Sema_RenderStart;
void* Sema_RenderDone;
void* Sema_ScanlineCount;
@@ -57,12 +58,24 @@ bool Init()
Sema_ScanlineCount = Platform::Semaphore_Create();
RenderThreadRunning = false;
+ RenderThreadRendering = false;
return true;
}
void DeInit()
{
+ if (RenderThreadRunning)
+ {
+ RenderThreadRunning = false;
+ Platform::Semaphore_Post(Sema_RenderStart);
+ Platform::Thread_Wait(RenderThread);
+ Platform::Thread_Free(RenderThread);
+ }
+
+ Platform::Semaphore_Free(Sema_RenderStart);
+ Platform::Semaphore_Free(Sema_RenderDone);
+ Platform::Semaphore_Free(Sema_ScanlineCount);
}
void Reset()
@@ -78,6 +91,12 @@ void Reset()
RenderThread = Platform::Thread_Create(RenderThreadFunc);
}
+ if (RenderThreadRendering)
+ Platform::Semaphore_Wait(Sema_RenderDone);
+
+ Platform::Semaphore_Reset(Sema_RenderStart);
+ Platform::Semaphore_Reset(Sema_ScanlineCount);
+
Platform::Semaphore_Post(Sema_RenderStart);
}
@@ -1136,7 +1155,7 @@ void ClearBuffers()
}
}
}
-int derp=0;int linebuf=0;
+
void RenderPolygons(bool threaded, Polygon* polygons, int npolys)
{
// sort polygons
@@ -1160,7 +1179,7 @@ void RenderPolygons(bool threaded, Polygon* polygons, int npolys)
RenderScanline(y, npolys);
if (threaded)
- Platform::Semaphore_Post(Sema_ScanlineCount);derp=y;linebuf++;
+ Platform::Semaphore_Post(Sema_ScanlineCount);
}
}
@@ -1173,40 +1192,33 @@ void RenderFrame(Vertex* vertices, Polygon* polygons, int npolys)
{
//ClearBuffers();
//RenderPolygons(false, polygons, npolys);
- //Platform::Semaphore_Wait(Sema_ScanlineCount);
- //Platform::Semaphore_Wait(Sema_RenderDone);
- if (linebuf!=0) printf("last frame was bad! %d\n", linebuf);
+
Platform::Semaphore_Post(Sema_RenderStart);
- //printf("start frame %d\n", derp);
}
void RenderThreadFunc()
{
- //Platform::Semaphore_Post(Sema_ScanlineCount);
-
for (;;)
{
Platform::Semaphore_Wait(Sema_RenderStart);
if (!RenderThreadRunning) return;
+ RenderThreadRendering = true;
ClearBuffers();
RenderPolygons(true, RenderPolygonRAM, RenderNumPolygons);
- //Platform::Semaphore_Post(Sema_ScanlineCount);
Platform::Semaphore_Post(Sema_RenderDone);
+ RenderThreadRendering = false;
}
}
void RequestLine(int line)
{
Platform::Semaphore_Wait(Sema_ScanlineCount);
- linebuf--;
}
u32* GetLine(int line)
{
- //Platform::Semaphore_Wait(Sema_ScanlineCount);
-if (line > derp || linebuf<0) printf("bad! %d %d, %d\n", line, derp, linebuf);
return &ColorBuffer[line * 256];
}
diff --git a/src/Platform.h b/src/Platform.h
index 5eee7e5..4fefd33 100644
--- a/src/Platform.h
+++ b/src/Platform.h
@@ -30,6 +30,7 @@ void Thread_Wait(void* thread);
void* Semaphore_Create();
void Semaphore_Free(void* sema);
+void Semaphore_Reset(void* sema);
void Semaphore_Wait(void* sema);
void Semaphore_Post(void* sema);
diff --git a/src/wx/Platform.cpp b/src/wx/Platform.cpp
index 1fb4373..b925e24 100644
--- a/src/wx/Platform.cpp
+++ b/src/wx/Platform.cpp
@@ -109,6 +109,11 @@ void Semaphore_Free(void* sema)
delete (wxSemaphore*)sema;
}
+void Semaphore_Reset(void* sema)
+{
+ while (((wxSemaphore*)sema)->TryWait() == wxSEMA_NO_ERROR);
+}
+
void Semaphore_Wait(void* sema)
{
((wxSemaphore*)sema)->Wait();