diff --git a/src/d3d/d3ddevice.cpp b/src/d3d/d3ddevice.cpp index 28be314..9de4909 100644 --- a/src/d3d/d3ddevice.cpp +++ b/src/d3d/d3ddevice.cpp @@ -1459,7 +1459,7 @@ startD3D(void) d3d9Globals.present.BackBufferHeight = height; d3d9Globals.present.BackBufferFormat = format; d3d9Globals.present.BackBufferCount = 1; - d3d9Globals.present.MultiSampleType = D3DMULTISAMPLE_NONE; + d3d9Globals.present.MultiSampleType = (D3DMULTISAMPLE_TYPE)d3d9Globals.msLevel; d3d9Globals.present.MultiSampleQuality = 0; d3d9Globals.present.SwapEffect = D3DSWAPEFFECT_DISCARD; d3d9Globals.present.hDeviceWindow = d3d9Globals.window; @@ -1797,6 +1797,26 @@ deviceSystem(DeviceReq req, void *arg, int32 n) rwmode->depth = findFormatDepth(d3d9Globals.modes[n].mode.Format); rwmode->flags = d3d9Globals.modes[n].flags; return 1; + case DEVICEGETMAXMULTISAMPLINGLEVELS: + { + assert(d3d9Globals.d3d9 != nil); + uint32 level; + DWORD quality; + for (level = D3DMULTISAMPLE_16_SAMPLES; level > D3DMULTISAMPLE_NONMASKABLE; level--) { + if (SUCCEEDED(d3d9Globals.d3d9->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3d9Globals.startMode.mode.Format, + !(d3d9Globals.startMode.flags & VIDEOMODEEXCLUSIVE), (D3DMULTISAMPLE_TYPE)level, + &quality))) + return level; + } + } + return 1; + case DEVICEGETMULTISAMPLINGLEVELS: + if (d3d9Globals.msLevel == 0) + return 1; + return d3d9Globals.msLevel; + case DEVICESETMULTISAMPLINGLEVELS: + d3d9Globals.msLevel = (uint32)n; + return 1; } return 1; } diff --git a/src/d3d/rwd3dimpl.h b/src/d3d/rwd3dimpl.h index caa6fc1..82f8a13 100644 --- a/src/d3d/rwd3dimpl.h +++ b/src/d3d/rwd3dimpl.h @@ -35,6 +35,8 @@ struct D3d9Globals int numModes; int currentMode; DisplayMode startMode; + + uint32 msLevel; D3DPRESENT_PARAMETERS present; diff --git a/src/engine.cpp b/src/engine.cpp index a2322c3..58e3e1c 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -414,6 +414,25 @@ Engine::getVideoModeInfo(VideoMode *info, int32 mode) } +uint32 +Engine::getMaxMultiSamplingLevels(void) +{ + return engine->device.system(DEVICEGETMAXMULTISAMPLINGLEVELS, nil, 0); +} + +uint32 +Engine::getMultiSamplingLevels(void) +{ + return engine->device.system(DEVICEGETMULTISAMPLINGLEVELS, nil, 0); +} + +bool32 +Engine::setMultiSamplingLevels(uint32 levels) +{ + return engine->device.system(DEVICESETMULTISAMPLINGLEVELS, nil, levels); +} + + namespace null { void beginUpdate(Camera*) { } diff --git a/src/gl/gl3device.cpp b/src/gl/gl3device.cpp index b38e75b..cea37e5 100644 --- a/src/gl/gl3device.cpp +++ b/src/gl/gl3device.cpp @@ -57,6 +57,7 @@ struct GlGlobals // for opening the window int winWidth, winHeight; const char *winTitle; + uint32 numSamples; } glGlobals; Gl3Caps gl3Caps; @@ -1427,7 +1428,6 @@ openGLFW(EngineOpenParams *openparams) RWERROR((ERR_GENERAL, "glfwInit() failed")); return 0; } - glfwWindowHint(GLFW_SAMPLES, 0); glGlobals.monitor = glfwGetMonitors(&glGlobals.numMonitors)[0]; @@ -1474,6 +1474,7 @@ startGLFW(void) glfwWindowHint(GLFW_GREEN_BITS, mode->mode.greenBits); glfwWindowHint(GLFW_BLUE_BITS, mode->mode.blueBits); glfwWindowHint(GLFW_REFRESH_RATE, mode->mode.refreshRate); + glfwWindowHint(GLFW_SAMPLES, glGlobals.numSamples); int i; for(i = 0; profiles[i].gl; i++){ @@ -1739,6 +1740,21 @@ deviceSystemGLFW(DeviceReq req, void *arg, int32 n) rwmode->flags = glGlobals.modes[n].flags; return 1; + case DEVICEGETMAXMULTISAMPLINGLEVELS: + { + GLint maxSamples; + glGetIntegerv(GL_MAX_SAMPLES, &maxSamples); + if (maxSamples == 0) + return 1; + return maxSamples; + } + case DEVICEGETMULTISAMPLINGLEVELS: + if (glGlobals.numSamples == 0) + return 1; + return glGlobals.numSamples; + case DEVICESETMULTISAMPLINGLEVELS: + glGlobals.numSamples = (uint32)n; + return 1; default: assert(0 && "not implemented"); return 0; diff --git a/src/rwengine.h b/src/rwengine.h index 0f54395..f49ae4e 100644 --- a/src/rwengine.h +++ b/src/rwengine.h @@ -27,7 +27,13 @@ enum DeviceReq DEVICEGETNUMVIDEOMODES, DEVICEGETCURRENTVIDEOMODE, DEVICESETVIDEOMODE, - DEVICEGETVIDEOMODEINFO + DEVICEGETVIDEOMODEINFO, + + // Multisampling + DEVICEGETMAXMULTISAMPLINGLEVELS, + DEVICEGETMULTISAMPLINGLEVELS, + DEVICESETMULTISAMPLINGLEVELS, + }; typedef int DeviceSystem(DeviceReq req, void *arg, int32 n); @@ -176,6 +182,9 @@ struct Engine static bool32 setVideoMode(int32 mode); static VideoMode *getVideoModeInfo(VideoMode *info, int32 mode); + static uint32 getMaxMultiSamplingLevels(void); + static uint32 getMultiSamplingLevels(void); + static bool32 setMultiSamplingLevels(uint32 levels); static PluginList s_plglist; static int32 registerPlugin(int32 size, uint32 id,