Implement gl_PointCoord on SM3 hardware

TRAC #11594 Signed-off-by: Andrew Lewycky Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@355 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent b75e523a
......@@ -362,6 +362,9 @@ Surface *Display::createWindowSurface(HWND window, EGLConfig config)
}
}
// Permanent non-default states
mDevice->SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE);
Surface *surface = NULL;
if (swapChain)
......
......@@ -232,12 +232,12 @@ bool Blit::setShader(ShaderId source, const char *profile,
bool Blit::setVertexShader(ShaderId shader)
{
return setShader<IDirect3DVertexShader9>(shader, mContext->getVertexShaderProfile(), &IDirect3DDevice9::CreateVertexShader, &IDirect3DDevice9::SetVertexShader);
return setShader<IDirect3DVertexShader9>(shader, mContext->supportsShaderModel3() ? "vs_3_0" : "vs_2_0", &IDirect3DDevice9::CreateVertexShader, &IDirect3DDevice9::SetVertexShader);
}
bool Blit::setPixelShader(ShaderId shader)
{
return setShader<IDirect3DPixelShader9>(shader, mContext->getPixelShaderProfile(), &IDirect3DDevice9::CreatePixelShader, &IDirect3DDevice9::SetPixelShader);
return setShader<IDirect3DPixelShader9>(shader, mContext->supportsShaderModel3() ? "ps_3_0" : "ps_2_0", &IDirect3DDevice9::CreatePixelShader, &IDirect3DDevice9::SetPixelShader);
}
RECT Blit::getSurfaceRect(IDirect3DSurface9 *surface) const
......
......@@ -269,16 +269,7 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
depthStencil->Release();
}
if (mDeviceCaps.PixelShaderVersion == D3DPS_VERSION(3, 0))
{
mPsProfile = "ps_3_0";
mVsProfile = "vs_3_0";
}
else // egl::Display guarantees support for at least 2.0
{
mPsProfile = "ps_2_0";
mVsProfile = "vs_2_0";
}
mSupportsShaderModel3 = mDeviceCaps.PixelShaderVersion == D3DPS_VERSION(3, 0);
markAllStateDirty();
}
......@@ -1283,7 +1274,7 @@ bool Context::getFloatv(GLenum pname, GLfloat *params)
break;
case GL_ALIASED_POINT_SIZE_RANGE:
params[0] = gl::ALIASED_POINT_SIZE_RANGE_MIN;
params[1] = gl::ALIASED_POINT_SIZE_RANGE_MAX;
params[1] = supportsShaderModel3() ? gl::ALIASED_POINT_SIZE_RANGE_MAX_SM3 : gl::ALIASED_POINT_SIZE_RANGE_MAX_SM2;
break;
case GL_DEPTH_RANGE:
params[0] = mState.zNear;
......@@ -2742,14 +2733,9 @@ GLenum Context::getError()
return GL_NO_ERROR;
}
const char *Context::getPixelShaderProfile()
{
return mPsProfile;
}
const char *Context::getVertexShaderProfile()
bool Context::supportsShaderModel3() const
{
return mVsProfile;
return mSupportsShaderModel3;
}
void Context::detachBuffer(GLuint buffer)
......
......@@ -67,7 +67,8 @@ enum
const float ALIASED_LINE_WIDTH_RANGE_MIN = 1.0f;
const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f;
const float ALIASED_POINT_SIZE_RANGE_MIN = 1.0f;
const float ALIASED_POINT_SIZE_RANGE_MAX = 1.0f;
const float ALIASED_POINT_SIZE_RANGE_MAX_SM2 = 1.0f;
const float ALIASED_POINT_SIZE_RANGE_MAX_SM3 = 64.0f;
enum SamplerType
{
......@@ -373,9 +374,7 @@ class Context
GLenum getError();
const char *getPixelShaderProfile();
const char *getVertexShaderProfile();
bool supportsShaderModel3() const;
const char *getExtensionString() const;
Blit *getBlitter() { return mBlit; }
......@@ -451,8 +450,7 @@ class Context
unsigned int mAppliedRenderTargetSerial;
unsigned int mAppliedDepthbufferSerial;
const char *mPsProfile;
const char *mVsProfile;
bool mSupportsShaderModel3;
// state caching flags
bool mClearStateDirty;
......
......@@ -1195,6 +1195,10 @@ bool Program::linkVaryings()
}
}
Context *context = getContext();
bool sm3 = context->supportsShaderModel3();
std::string varyingSemantic = (sm3 ? "COLOR" : "TEXCOORD");
mVertexHLSL += "struct VS_INPUT\n"
"{\n";
......@@ -1228,12 +1232,17 @@ bool Program::linkVaryings()
{
int registerSize = packing[r][3] ? 4 : (packing[r][2] ? 3 : (packing[r][1] ? 2 : 1));
mVertexHLSL += " float" + str(registerSize) + " v" + str(r) + " : TEXCOORD" + str(r) + ";\n";
mVertexHLSL += " float" + str(registerSize) + " v" + str(r) + " : " + varyingSemantic + str(r) + ";\n";
}
if (mFragmentShader->mUsesFragCoord)
{
mVertexHLSL += " float4 gl_FragCoord : TEXCOORD" + str(registers) + ";\n";
mVertexHLSL += " float4 gl_FragCoord : " + varyingSemantic + str(registers) + ";\n";
}
if (mVertexShader->mUsesPointSize && sm3)
{
mVertexHLSL += " float gl_PointSize : PSIZE;\n";
}
mVertexHLSL += "};\n"
......@@ -1262,6 +1271,11 @@ bool Program::linkVaryings()
" output.gl_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
" output.gl_Position.w = gl_Position.w;\n";
if (mVertexShader->mUsesPointSize && sm3)
{
mVertexHLSL += " output.gl_PointSize = clamp(gl_PointSize, 1.0, " + str((int)ALIASED_POINT_SIZE_RANGE_MAX_SM3) + ");\n";
}
if (mFragmentShader->mUsesFragCoord)
{
mVertexHLSL += " output.gl_FragCoord = gl_Position;\n";
......@@ -1345,7 +1359,7 @@ bool Program::linkVaryings()
for (int j = 0; j < rows; j++)
{
std::string n = str(varying->reg + i * rows + j);
mPixelHLSL += " float4 v" + n + " : TEXCOORD" + n + ";\n";
mPixelHLSL += " float4 v" + n + " : " + varyingSemantic + n + ";\n";
}
}
}
......@@ -1354,9 +1368,14 @@ bool Program::linkVaryings()
if (mFragmentShader->mUsesFragCoord)
{
mPixelHLSL += " float4 gl_FragCoord : TEXCOORD" + str(registers) + ";\n";
mPixelHLSL += " float4 gl_FragCoord : " + varyingSemantic + str(registers) + ";\n";
}
if (mFragmentShader->mUsesPointCoord && sm3)
{
mPixelHLSL += " float2 gl_PointCoord : TEXCOORD0;\n";
}
if (mFragmentShader->mUsesFrontFacing)
{
mPixelHLSL += " float vFace : VFACE;\n";
......@@ -1381,6 +1400,11 @@ bool Program::linkVaryings()
" gl_FragCoord.w = rhw;\n";
}
if (mFragmentShader->mUsesPointCoord && sm3)
{
mPixelHLSL += " gl_PointCoord = float2(input.gl_PointCoord.x, 1.0 - input.gl_PointCoord.y);\n";
}
if (mFragmentShader->mUsesFrontFacing)
{
mPixelHLSL += " gl_FrontFacing = dx_PointsOrLines || (dx_FrontCCW ? (input.vFace >= 0.0) : (input.vFace <= 0.0));\n";
......@@ -1447,10 +1471,6 @@ void Program::link()
return;
}
Context *context = getContext();
const char *vertexProfile = context->getVertexShaderProfile();
const char *pixelProfile = context->getPixelShaderProfile();
mPixelHLSL = mFragmentShader->getHLSL();
mVertexHLSL = mVertexShader->getHLSL();
......@@ -1459,6 +1479,10 @@ void Program::link()
return;
}
Context *context = getContext();
const char *vertexProfile = context->supportsShaderModel3() ? "vs_3_0" : "vs_2_0";
const char *pixelProfile = context->supportsShaderModel3() ? "ps_3_0" : "ps_2_0";
ID3DXBuffer *vertexBinary = compileToBinary(mVertexHLSL.c_str(), vertexProfile, &mConstantTableVS);
ID3DXBuffer *pixelBinary = compileToBinary(mPixelHLSL.c_str(), pixelProfile, &mConstantTablePS);
......
......@@ -262,6 +262,8 @@ void Shader::parseVaryings()
mUsesFragCoord = strstr(mHlsl, "GL_USES_FRAG_COORD") != NULL;
mUsesFrontFacing = strstr(mHlsl, "GL_USES_FRONT_FACING") != NULL;
mUsesPointSize = strstr(mHlsl, "GL_USES_POINT_SIZE") != NULL;
mUsesPointCoord = strstr(mHlsl, "GL_USES_POINT_COORD") != NULL;
}
}
......
......@@ -93,6 +93,8 @@ class Shader
bool mUsesFragCoord;
bool mUsesFrontFacing;
bool mUsesPointSize;
bool mUsesPointCoord;
Context *mContext;
......
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