Implement glGetAttachedShaders and glGetShaderPrecisionFormat.

TRAC #11599 Signed-off-by: Andrew Lewycky Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@85 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 02bc1594
...@@ -298,11 +298,11 @@ GLuint Context::createShader(GLenum type) ...@@ -298,11 +298,11 @@ GLuint Context::createShader(GLenum type)
if (type == GL_VERTEX_SHADER) if (type == GL_VERTEX_SHADER)
{ {
mShaderMap[handle] = new VertexShader(); mShaderMap[handle] = new VertexShader(handle);
} }
else if (type == GL_FRAGMENT_SHADER) else if (type == GL_FRAGMENT_SHADER)
{ {
mShaderMap[handle] = new FragmentShader(); mShaderMap[handle] = new FragmentShader(handle);
} }
else UNREACHABLE(); else UNREACHABLE();
......
...@@ -1058,6 +1058,36 @@ void Program::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) ...@@ -1058,6 +1058,36 @@ void Program::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog)
} }
} }
void Program::getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders)
{
int total = 0;
if (mVertexShader)
{
if (total < maxCount)
{
shaders[total] = mVertexShader->getHandle();
}
total++;
}
if (mFragmentShader)
{
if (total < maxCount)
{
shaders[total] = mFragmentShader->getHandle();
}
total++;
}
if (count)
{
*count = total;
}
}
void Program::flagForDeletion() void Program::flagForDeletion()
{ {
mDeleteStatus = true; mDeleteStatus = true;
......
...@@ -72,6 +72,7 @@ class Program ...@@ -72,6 +72,7 @@ class Program
bool isLinked(); bool isLinked();
int getInfoLogLength() const; int getInfoLogLength() const;
void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog); void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog);
void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders);
void flagForDeletion(); void flagForDeletion();
bool isFlaggedForDeletion() const; bool isFlaggedForDeletion() const;
......
...@@ -20,7 +20,7 @@ namespace gl ...@@ -20,7 +20,7 @@ namespace gl
void *Shader::mFragmentCompiler = NULL; void *Shader::mFragmentCompiler = NULL;
void *Shader::mVertexCompiler = NULL; void *Shader::mVertexCompiler = NULL;
Shader::Shader() Shader::Shader(GLuint handle) : mHandle(handle)
{ {
mSource = NULL; mSource = NULL;
mHlsl = NULL; mHlsl = NULL;
...@@ -49,6 +49,11 @@ Shader::~Shader() ...@@ -49,6 +49,11 @@ Shader::~Shader()
delete[] mInfoLog; delete[] mInfoLog;
} }
GLuint Shader::getHandle() const
{
return mHandle;
}
void Shader::setSource(GLsizei count, const char **string, const GLint *length) void Shader::setSource(GLsizei count, const char **string, const GLint *length)
{ {
delete[] mSource; delete[] mSource;
...@@ -282,7 +287,7 @@ InputMapping::~InputMapping() ...@@ -282,7 +287,7 @@ InputMapping::~InputMapping()
delete[] mAttribute; delete[] mAttribute;
} }
VertexShader::VertexShader() VertexShader::VertexShader(GLuint handle) : Shader(handle)
{ {
} }
...@@ -396,7 +401,7 @@ void VertexShader::parseAttributes() ...@@ -396,7 +401,7 @@ void VertexShader::parseAttributes()
} }
} }
FragmentShader::FragmentShader() FragmentShader::FragmentShader(GLuint handle) : Shader(handle)
{ {
} }
......
...@@ -23,11 +23,12 @@ namespace gl ...@@ -23,11 +23,12 @@ namespace gl
class Shader class Shader
{ {
public: public:
Shader(); explicit Shader(GLuint handle);
virtual ~Shader(); virtual ~Shader();
virtual GLenum getType() = 0; virtual GLenum getType() = 0;
GLuint getHandle() const;
void deleteSource(); void deleteSource();
void setSource(GLsizei count, const char **string, const GLint *length); void setSource(GLsizei count, const char **string, const GLint *length);
...@@ -54,6 +55,7 @@ class Shader ...@@ -54,6 +55,7 @@ class Shader
void compileToHLSL(void *compiler); void compileToHLSL(void *compiler);
const GLuint mHandle;
int mAttachCount; // Number of program objects this shader is attached to int mAttachCount; // Number of program objects this shader is attached to
bool mDeleteStatus; // Flag to indicate that the shader can be deleted when no longer in use bool mDeleteStatus; // Flag to indicate that the shader can be deleted when no longer in use
...@@ -82,7 +84,7 @@ class InputMapping ...@@ -82,7 +84,7 @@ class InputMapping
class VertexShader : public Shader class VertexShader : public Shader
{ {
public: public:
VertexShader(); explicit VertexShader(GLuint handle);
~VertexShader(); ~VertexShader();
...@@ -104,7 +106,7 @@ class VertexShader : public Shader ...@@ -104,7 +106,7 @@ class VertexShader : public Shader
class FragmentShader : public Shader class FragmentShader : public Shader
{ {
public: public:
FragmentShader(); explicit FragmentShader(GLuint handle);
~FragmentShader(); ~FragmentShader();
......
...@@ -1667,7 +1667,19 @@ void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* c ...@@ -1667,7 +1667,19 @@ void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* c
return error(GL_INVALID_VALUE); return error(GL_INVALID_VALUE);
} }
UNIMPLEMENTED(); // FIXME gl::Context *context = gl::getContext();
if (context)
{
gl::Program *programObject = context->getProgram(program);
if (!programObject)
{
return error(GL_INVALID_VALUE);
}
return programObject->getAttachedShaders(maxcount, count, shaders);
}
} }
catch(std::bad_alloc&) catch(std::bad_alloc&)
{ {
...@@ -2099,7 +2111,39 @@ void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontyp ...@@ -2099,7 +2111,39 @@ void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontyp
try try
{ {
UNIMPLEMENTED(); // FIXME switch (shadertype)
{
case GL_VERTEX_SHADER:
case GL_FRAGMENT_SHADER:
break;
default:
return error(GL_INVALID_ENUM);
}
switch (precisiontype)
{
case GL_LOW_FLOAT:
case GL_MEDIUM_FLOAT:
case GL_HIGH_FLOAT:
// Assume IEEE 754 precision
range[0] = 127;
range[1] = 127;
precision[0] = 23;
precision[1] = 23;
break;
case GL_LOW_INT:
case GL_MEDIUM_INT:
case GL_HIGH_INT:
// Some (most) hardware only supports single-precision floating-point numbers,
// which can accurately represent integers up to +/-16777216
range[0] = 24;
range[1] = 24;
precision[0] = 0;
precision[1] = 0;
break;
default:
return error(GL_INVALID_ENUM);
}
} }
catch(std::bad_alloc&) catch(std::bad_alloc&)
{ {
......
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