Skip to content

Commit

Permalink
implemented vsynch for d3d9 and glfw
Browse files Browse the repository at this point in the history
  • Loading branch information
aap committed May 2, 2020
1 parent 3704fe8 commit b3ad490
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions src/d3d/d3ddevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
6 changes: 5 additions & 1 deletion src/gl/gl3device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions src/raster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/rwengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/rwobjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ struct RasterLevels

struct Raster
{
enum { FLIPWAITVSYNCH = 1 };

PLUGINBASE
int32 platform;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tools/imguitest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Draw(float timeDelta)
ImGui::Render();

Scene.camera->endUpdate();
Scene.camera->showRaster();
Scene.camera->showRaster(0);
}


Expand Down
2 changes: 1 addition & 1 deletion tools/lights/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ Draw(float timeDelta)
ImGui::Render();

Scene.camera->endUpdate();
Scene.camera->showRaster();
Scene.camera->showRaster(0);
}


Expand Down
6 changes: 3 additions & 3 deletions tools/playground/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -408,7 +408,7 @@ extern void endSoftras(void);

camera->m_rwcam->endUpdate();

camera->m_rwcam->showRaster();
camera->m_rwcam->showRaster(0);
}


Expand Down

0 comments on commit b3ad490

Please sign in to comment.