Add an abstract Renderer::setViewport method and implemented it for Renderer9.

TRAC #22116 Signed-off-by: Shannon Woods Signed-off-by: Daniel Koch git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1453 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent b743e1d7
......@@ -37,6 +37,11 @@ namespace egl
class Display;
}
namespace gl
{
class ProgramBinary;
}
namespace rx
{
class TextureStorage2D;
......@@ -81,6 +86,9 @@ class Renderer
virtual void setScissorRectangle(const gl::Rectangle& scissor, unsigned int renderTargetWidth,
unsigned int renderTargetHeight) = 0;
virtual bool setViewport(const gl::Rectangle& viewport, float zNear, float zFar,
unsigned int renderTargetWidth, unsigned int renderTargetHeight,
gl::ProgramBinary *currentProgram, bool forceSetUniforms) = 0;
virtual void applyRenderTarget(gl::Framebuffer *frameBuffer) = 0;
......
......@@ -374,6 +374,15 @@ void Renderer11::setScissorRectangle(const gl::Rectangle& scissor, unsigned int
mForceSetScissor = false;
}
bool Renderer11::setViewport(const gl::Rectangle& viewport, float zNear, float zFar,
unsigned int renderTargetWidth, unsigned int renderTargetHeight,
gl::ProgramBinary *currentProgram, bool forceSetUniforms)
{
// TODO
UNIMPLEMENTED();
return true;
}
void Renderer11::applyRenderTarget(gl::Framebuffer *frameBuffer)
{
// TODO
......
......@@ -57,6 +57,9 @@ class Renderer11 : public Renderer
virtual void setScissorRectangle(const gl::Rectangle& scissor, unsigned int renderTargetWidth,
unsigned int renderTargetHeight);
virtual bool setViewport(const gl::Rectangle& viewport, float zNear, float zFar,
unsigned int renderTargetWidth, unsigned int renderTargetHeight,
gl::ProgramBinary *currentProgram, bool forceSetUniforms);
virtual void applyRenderTarget(gl::Framebuffer *frameBuffer);
......
......@@ -11,6 +11,8 @@
#include "libGLESv2/utilities.h"
#include "libGLESv2/mathutil.h"
#include "libGLESv2/Framebuffer.h"
#include "libGLESv2/Program.h"
#include "libGLESv2/ProgramBinary.h"
#include "libGLESv2/renderer/Renderer9.h"
#include "libGLESv2/renderer/renderer9_utils.h"
#include "libGLESv2/renderer/SwapChain9.h"
......@@ -86,6 +88,7 @@ Renderer9::Renderer9(egl::Display *display, HDC hDc, bool softwareDevice) : Rend
mForceSetRasterState = true;
mForceSetBlendState = true;
mForceSetScissor = true;
mForceSetViewport = true;
}
Renderer9::~Renderer9()
......@@ -869,9 +872,67 @@ void Renderer9::setScissorRectangle(const gl::Rectangle& scissor, unsigned int r
mForceSetScissor = false;
}
bool Renderer9::setViewport(const gl::Rectangle& viewport, float zNear, float zFar,
unsigned int renderTargetWidth, unsigned int renderTargetHeight,
gl::ProgramBinary *currentProgram, bool forceSetUniforms)
{
bool viewportChanged = mForceSetViewport || memcmp(&viewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 ||
zNear != mCurNear || zFar != mCurFar;
D3DVIEWPORT9 dxViewport;
dxViewport.X = gl::clamp(viewport.x, 0, static_cast<int>(renderTargetWidth));
dxViewport.Y = gl::clamp(viewport.y, 0, static_cast<int>(renderTargetHeight));
dxViewport.Width = gl::clamp(viewport.width, 0, static_cast<int>(renderTargetWidth) - static_cast<int>(dxViewport.X));
dxViewport.Height = gl::clamp(viewport.height, 0, static_cast<int>(renderTargetHeight) - static_cast<int>(dxViewport.Y));
dxViewport.MinZ = zNear;
dxViewport.MaxZ = zFar;
if (dxViewport.Width <= 0 || dxViewport.Height <= 0)
{
return false; // Nothing to render
}
if (viewportChanged)
{
mDevice->SetViewport(&dxViewport);
mCurViewport = viewport;
mCurNear = zNear;
mCurFar = zFar;
}
if (currentProgram && (viewportChanged || forceSetUniforms))
{
GLint halfPixelSize = currentProgram->getDxHalfPixelSizeLocation();
GLfloat xy[2] = { 1.0f / dxViewport.Width, -1.0f / dxViewport.Height };
currentProgram->setUniform2fv(halfPixelSize, 1, xy);
// These values are used for computing gl_FragCoord in Program::linkVaryings().
GLint coord = currentProgram->getDxCoordLocation();
GLfloat whxy[4] = { viewport.width * 0.5f,
viewport.height * 0.5f,
viewport.x + (viewport.width * 0.5f),
viewport.y + (viewport.height * 0.5f) };
currentProgram->setUniform4fv(coord, 1, whxy);
GLint depth = currentProgram->getDxDepthLocation();
GLfloat dz[2] = { (zFar - zNear) * 0.5f, (zNear + zFar) * 0.5f };
currentProgram->setUniform2fv(depth, 1, dz);
GLint depthRange = currentProgram->getDxDepthRangeLocation();
GLfloat nearFarDiff[3] = { zNear, zFar, zFar - zNear };
currentProgram->setUniform3fv(depthRange, 1, nearFarDiff);
}
mForceSetViewport = false;
return true;
}
void Renderer9::applyRenderTarget(gl::Framebuffer *frameBuffer)
{
// TODO: only set these when the rendertarget actually changes
mForceSetScissor = true;
mForceSetViewport = true;
// TODO
}
......
......@@ -65,8 +65,6 @@ class Renderer9 : public Renderer
// state setup
void applyShaders();
void applyConstants();
void applyRenderTargets();
void applyState();
#endif
virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler);
virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture);
......@@ -79,6 +77,9 @@ class Renderer9 : public Renderer
virtual void setScissorRectangle(const gl::Rectangle& scissor, unsigned int renderTargetWidth,
unsigned int renderTargetHeight);
virtual bool setViewport(const gl::Rectangle& viewport, float zNear, float zFar,
unsigned int renderTargetWidth, unsigned int renderTargetHeight,
gl::ProgramBinary *currentProgram, bool forceSetUniforms);
virtual void applyRenderTarget(gl::Framebuffer *frameBuffer);
......@@ -205,6 +206,11 @@ class Renderer9 : public Renderer
unsigned int mCurRenderTargetWidth;
unsigned int mCurRenderTargetHeight;
bool mForceSetViewport;
gl::Rectangle mCurViewport;
float mCurNear;
float mCurFar;
bool mForceSetBlendState;
gl::BlendState mCurBlendState;
gl::Color mCurBlendColor;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment