Skip to content

Commit

Permalink
finally fixed monitor rotation for monitor capture on windows 8 (thou…
Browse files Browse the repository at this point in the history
…gh it still baffles me beyond reason why anyone would use monitor capture at all with a portrait desktop)
  • Loading branch information
jp9000 committed Aug 4, 2013
1 parent 651ba78 commit 6d1a39f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions OBSApi/GraphicsSystem.h
Expand Up @@ -513,6 +513,7 @@ class BASE_EXPORT GraphicsSystem

public:
virtual void CopyTexture(Texture *texDest, Texture *texSrc)=0;
virtual void DrawSpriteExRotate(Texture *texture, DWORD color, float x, float y, float x2, float y2, float u, float v, float u2, float v2, float degrees)=0;
};


Expand Down
32 changes: 32 additions & 0 deletions Source/D3D10System.cpp
Expand Up @@ -63,6 +63,16 @@ void GetDisplayDevices(DeviceOutputs &deviceList)
MonitorInfo &monitorInfo = *deviceData.monitors.CreateNew();
monitorInfo.hMonitor = outputDesc.Monitor;
mcpy(&monitorInfo.rect, &outputDesc.DesktopCoordinates, sizeof(RECT));
switch (outputDesc.Rotation) {
case DXGI_MODE_ROTATION_ROTATE90:
monitorInfo.rotationDegrees = 90.0f;
break;
case DXGI_MODE_ROTATION_ROTATE180:
monitorInfo.rotationDegrees = 180.0f;
break;
case DXGI_MODE_ROTATION_ROTATE270:
monitorInfo.rotationDegrees = 270.0f;
}
}
}

Expand Down Expand Up @@ -790,6 +800,11 @@ void D3D10System::SetCropping(float left, float top, float right, float bottom)
}

void D3D10System::DrawSpriteEx(Texture *texture, DWORD color, float x, float y, float x2, float y2, float u, float v, float u2, float v2)
{
DrawSpriteExRotate(texture, color, x, y, x2, y2, u, v, u2, v2, 0.0f);
}

void D3D10System::DrawSpriteExRotate(Texture *texture, DWORD color, float x, float y, float x2, float y2, float u, float v, float u2, float v2, float degrees)
{
if(!curPixelShader)
return;
Expand Down Expand Up @@ -859,6 +874,23 @@ void D3D10System::DrawSpriteEx(Texture *texture, DWORD color, float x, float y,
coords[2].Set(u2, v);
coords[3].Set(u2, v2);

if (!CloseFloat(degrees, 0.0f)) {
Matrix rotMatrix;
rotMatrix.SetIdentity();
rotMatrix.Rotate(AxisAngle(0.0f, 0.0f, 1.0f, -RAD(degrees)));

Vect2 minVal = Vect2(0.0f, 0.0f);
for (int i = 0; i < 4; i++) {
Vect val = Vect(coords[i]);
val.TransformVector(rotMatrix);
coords[i] = val;
minVal.ClampMax(coords[i]);
}

for (int i = 0; i < 4; i++)
coords[i] -= minVal;
}

spriteVertexBuffer->FlushBuffers();

LoadVertexBuffer(spriteVertexBuffer);
Expand Down
3 changes: 2 additions & 1 deletion Source/D3D10System.h
Expand Up @@ -457,7 +457,8 @@ class D3D10System : public GraphicsSystem
virtual void DrawBox(const Vect2 &upperLeft, const Vect2 &size);
virtual void SetCropping(float left, float top, float right, float bottom);

virtual void CopyTexture(Texture *texDest, Texture *texSrc);
virtual void CopyTexture(Texture *texDest, Texture *texSrc);
virtual void DrawSpriteExRotate(Texture *texture, DWORD color, float x, float y, float x2, float y2, float u, float v, float u2, float v2, float degrees);
};

inline ID3D10Device* GetD3D() {return static_cast<ID3D10Device*>(GS->GetDevice());}
12 changes: 10 additions & 2 deletions Source/DesktopImageSource.cpp
Expand Up @@ -50,6 +50,8 @@ class DesktopImageSource : public ImageSource
UINT opacity;
int gamma;

float rotateDegrees;

//-------------------------
// stuff for compatibility mode
bool bCompatibilityMode;
Expand Down Expand Up @@ -480,10 +482,10 @@ class DesktopImageSource : public ImageSource
ulCoord.x, ulCoord.y,
lrCoord.x, lrCoord.y);
else
DrawSpriteEx(lastRendered, (opacity255<<24) | 0xFFFFFF,
GS->DrawSpriteExRotate(lastRendered, (opacity255<<24) | 0xFFFFFF,
pos.x, pos.y, pos.x+size.x, pos.y+size.y,
ulCoord.x, ulCoord.y,
lrCoord.x, lrCoord.y);
lrCoord.x, lrCoord.y, rotateDegrees);

if(bUsePointFiltering) delete(sampler);

Expand Down Expand Up @@ -600,8 +602,13 @@ class DesktopImageSource : public ImageSource
const MonitorInfo &monitorInfo = App->GetMonitor(monitor);
mcpy(&monitorData, &monitorInfo, sizeof(monitorInfo));

rotateDegrees = 0.0f;

if(captureType == 0 && OSGetVersion() >= 8)
{
LONG monitorWidth = monitorInfo.rect.right-monitorInfo.rect.left;
LONG monitorHeight = monitorInfo.rect.bottom-monitorInfo.rect.top;

DeviceOutputs outputs;
GetDisplayDevices(outputs);

Expand All @@ -613,6 +620,7 @@ class DesktopImageSource : public ImageSource
if(outputs.devices[0].monitors[j].hMonitor == info.hMonitor)
{
deviceOutputID = j;
rotateDegrees = outputs.devices[0].monitors[j].rotationDegrees;
bWindows8MonitorCapture = true;
}
}
Expand Down
1 change: 1 addition & 0 deletions Source/OBS.h
Expand Up @@ -198,6 +198,7 @@ struct MonitorInfo

HMONITOR hMonitor;
RECT rect;
float rotationDegrees;
};

struct DeviceOutputData
Expand Down

0 comments on commit 6d1a39f

Please sign in to comment.