diff --git a/src/camera.cpp b/src/camera.cpp index 4bfc0cf..07d1c9f 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -356,9 +356,9 @@ Camera::clear(RGBA *col, uint32 mode) } void -Camera::showRaster(void) +Camera::showRaster(uint32 flags) { - engine->device.showRaster(this->frameBuffer); + this->frameBuffer->show(flags); } void diff --git a/src/d3d/d3ddevice.cpp b/src/d3d/d3ddevice.cpp index 21ae6e2..8fde625 100644 --- a/src/d3d/d3ddevice.cpp +++ b/src/d3d/d3ddevice.cpp @@ -1034,9 +1034,15 @@ clearCamera(Camera *cam, RGBA *col, uint32 mode) } static void -showRaster(Raster *raster) +showRaster(Raster *raster, uint32 flag) { - // TODO: do this properly! + UINT interval = flag & Raster::FLIPWAITVSYNCH ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; + if(d3d9Globals.present.PresentationInterval != interval){ + d3d9Globals.present.PresentationInterval = interval; + releaseVideoMemory(); + d3d::d3ddevice->Reset(&d3d9Globals.present); + restoreVideoMemory(); + } // not used but we want cameras to have rasters assert(raster); @@ -1294,8 +1300,8 @@ startD3D(void) d3d9Globals.present.AutoDepthStencilFormat = zformat; d3d9Globals.present.Flags = 0; d3d9Globals.present.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; - d3d9Globals.present.PresentationInterval = D3DPRESENT_INTERVAL_ONE; -// d3d9Globals.present.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; +// d3d9Globals.present.PresentationInterval = D3DPRESENT_INTERVAL_ONE; + d3d9Globals.present.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; assert(d3d::d3ddevice == nil); diff --git a/src/engine.cpp b/src/engine.cpp index eaa7f58..d99c602 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -405,7 +405,7 @@ namespace null { void beginUpdate(Camera*) { } void endUpdate(Camera*) { } void clearCamera(Camera*,RGBA*,uint32) { } -void showRaster(Raster*) { } +void showRaster(Raster*,uint32) { } void setRenderState(int32, void*) { } void *getRenderState(int32) { return 0; } diff --git a/src/gl/gl3device.cpp b/src/gl/gl3device.cpp index 8370ed7..c209aff 100644 --- a/src/gl/gl3device.cpp +++ b/src/gl/gl3device.cpp @@ -761,12 +761,16 @@ clearCamera(Camera *cam, RGBA *col, uint32 mode) } static void -showRaster(Raster *raster) +showRaster(Raster *raster, uint32 flags) { // TODO: do this properly! #ifdef LIBRW_SDL2 SDL_GL_SwapWindow(glGlobals.window); #else + if(flags & Raster::FLIPWAITVSYNCH) + glfwSwapInterval(1); + else + glfwSwapInterval(0); glfwSwapBuffers(glGlobals.window); #endif } diff --git a/src/raster.cpp b/src/raster.cpp index 3b2390d..d9bc806 100644 --- a/src/raster.cpp +++ b/src/raster.cpp @@ -182,6 +182,12 @@ Raster::toImage(void) return engine->driver[this->platform]->rasterToImage(this); } +void +Raster::show(uint32 flags) +{ + engine->device.showRaster(this, flags); +} + Raster* Raster::pushContext(Raster *raster) { diff --git a/src/rwengine.h b/src/rwengine.h index a32db04..50b0703 100644 --- a/src/rwengine.h +++ b/src/rwengine.h @@ -45,7 +45,7 @@ struct Device void (*beginUpdate)(Camera*); void (*endUpdate)(Camera*); void (*clearCamera)(Camera*, RGBA *col, uint32 mode); - void (*showRaster)(Raster *raster); + void (*showRaster)(Raster *raster, uint32 flags); bool32 (*rasterRenderFast)(Raster *raster, int32 x, int32 y); void (*setRenderState)(int32 state, void *value); void *(*getRenderState)(int32 state); diff --git a/src/rwobjects.h b/src/rwobjects.h index fe7e7dd..a7532ed 100644 --- a/src/rwobjects.h +++ b/src/rwobjects.h @@ -179,6 +179,8 @@ struct RasterLevels struct Raster { + enum { FLIPWAITVSYNCH = 1 }; + PLUGINBASE int32 platform; @@ -219,6 +221,8 @@ struct Raster static int32 calculateNumLevels(int32 width, int32 height); static bool formatHasAlpha(int32 format); + void show(uint32 flags); + static Raster *pushContext(Raster *raster); static Raster *popContext(void); static Raster *getCurrentContext(void); @@ -698,7 +702,7 @@ struct Camera void beginUpdate(void) { this->beginUpdateCB(this); } void endUpdate(void) { this->endUpdateCB(this); } void clear(RGBA *col, uint32 mode); - void showRaster(void); + void showRaster(uint32 flags); void setNearPlane(float32); void setFarPlane(float32); void setViewWindow(const V2d *window); diff --git a/tools/imguitest/main.cpp b/tools/imguitest/main.cpp index fb80e08..6806d2d 100644 --- a/tools/imguitest/main.cpp +++ b/tools/imguitest/main.cpp @@ -112,7 +112,7 @@ Draw(float timeDelta) ImGui::Render(); Scene.camera->endUpdate(); - Scene.camera->showRaster(); + Scene.camera->showRaster(0); } diff --git a/tools/lights/main.cpp b/tools/lights/main.cpp index 2fb2bea..5d2bab1 100644 --- a/tools/lights/main.cpp +++ b/tools/lights/main.cpp @@ -303,7 +303,7 @@ Draw(float timeDelta) ImGui::Render(); Scene.camera->endUpdate(); - Scene.camera->showRaster(); + Scene.camera->showRaster(0); } diff --git a/tools/playground/main.cpp b/tools/playground/main.cpp index d86d2ab..655e6b4 100644 --- a/tools/playground/main.cpp +++ b/tools/playground/main.cpp @@ -338,8 +338,8 @@ im3dtest(void) verts[i].setV(vs[i].v); } -// rw::SetRenderStatePtr(rw::TEXTURERASTER, tex->raster); - rw::SetRenderStatePtr(rw::TEXTURERASTER, testfont->raster); + rw::SetRenderStatePtr(rw::TEXTURERASTER, tex->raster); +// rw::SetRenderStatePtr(rw::TEXTURERASTER, testfont->raster); // rw::SetRenderStatePtr(rw::TEXTURERASTER, frontbuffer->raster); rw::SetRenderState(rw::TEXTUREADDRESS, rw::Texture::WRAP); rw::SetRenderState(rw::TEXTUREFILTER, rw::Texture::NEAREST); @@ -408,7 +408,7 @@ extern void endSoftras(void); camera->m_rwcam->endUpdate(); - camera->m_rwcam->showRaster(); + camera->m_rwcam->showRaster(0); }