Commit 0ef53dbf by Alexis Hetu Committed by Alexis Hétu

CreateSampler should create a Sampler object by default

It should be possible to query the default parameters of a Sampler created with glGenSamplers, so checkSamplerAllocation() was added to make sure a created sampler was associated to a Sampler object where appropriate. I also cleaned up the API a little to share validation functions. Change-Id: I55d95c6663d41e2566b24eb76a431dd4b4da61e3 Reviewed-on: https://swiftshader-review.googlesource.com/3637Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent ad527754
...@@ -1326,6 +1326,8 @@ bool Context::bindTransformFeedback(GLuint id) ...@@ -1326,6 +1326,8 @@ bool Context::bindTransformFeedback(GLuint id)
bool Context::bindSampler(GLuint unit, GLuint sampler) bool Context::bindSampler(GLuint unit, GLuint sampler)
{ {
mResourceManager->checkSamplerAllocation(sampler);
Sampler* samplerObject = getSampler(sampler); Sampler* samplerObject = getSampler(sampler);
if(sampler) if(sampler)
...@@ -1570,6 +1572,11 @@ Sampler *Context::getSampler(GLuint sampler) const ...@@ -1570,6 +1572,11 @@ Sampler *Context::getSampler(GLuint sampler) const
return mResourceManager->getSampler(sampler); return mResourceManager->getSampler(sampler);
} }
bool Context::isSampler(GLuint sampler) const
{
return mResourceManager->isSampler(sampler);
}
Buffer *Context::getArrayBuffer() const Buffer *Context::getArrayBuffer() const
{ {
return mState.arrayBuffer; return mState.arrayBuffer;
...@@ -1719,6 +1726,94 @@ Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) cons ...@@ -1719,6 +1726,94 @@ Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) cons
return mState.samplerTexture[type][sampler]; return mState.samplerTexture[type][sampler];
} }
void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
{
mResourceManager->checkSamplerAllocation(sampler);
Sampler *samplerObject = getSampler(sampler);
ASSERT(samplerObject);
switch(pname)
{
case GL_TEXTURE_MIN_FILTER: samplerObject->setMinFilter(static_cast<GLenum>(param)); break;
case GL_TEXTURE_MAG_FILTER: samplerObject->setMagFilter(static_cast<GLenum>(param)); break;
case GL_TEXTURE_WRAP_S: samplerObject->setWrapS(static_cast<GLenum>(param)); break;
case GL_TEXTURE_WRAP_T: samplerObject->setWrapT(static_cast<GLenum>(param)); break;
case GL_TEXTURE_WRAP_R: samplerObject->setWrapR(static_cast<GLenum>(param)); break;
case GL_TEXTURE_MIN_LOD: samplerObject->setMinLod(static_cast<GLfloat>(param)); break;
case GL_TEXTURE_MAX_LOD: samplerObject->setMaxLod(static_cast<GLfloat>(param)); break;
case GL_TEXTURE_COMPARE_MODE: samplerObject->setComparisonMode(static_cast<GLenum>(param)); break;
case GL_TEXTURE_COMPARE_FUNC: samplerObject->setComparisonFunc(static_cast<GLenum>(param)); break;
default: UNREACHABLE(pname); break;
}
}
void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
{
mResourceManager->checkSamplerAllocation(sampler);
Sampler *samplerObject = getSampler(sampler);
ASSERT(samplerObject);
switch(pname)
{
case GL_TEXTURE_MIN_FILTER: samplerObject->setMinFilter(static_cast<GLenum>(roundf(param))); break;
case GL_TEXTURE_MAG_FILTER: samplerObject->setMagFilter(static_cast<GLenum>(roundf(param))); break;
case GL_TEXTURE_WRAP_S: samplerObject->setWrapS(static_cast<GLenum>(roundf(param))); break;
case GL_TEXTURE_WRAP_T: samplerObject->setWrapT(static_cast<GLenum>(roundf(param))); break;
case GL_TEXTURE_WRAP_R: samplerObject->setWrapR(static_cast<GLenum>(roundf(param))); break;
case GL_TEXTURE_MIN_LOD: samplerObject->setMinLod(param); break;
case GL_TEXTURE_MAX_LOD: samplerObject->setMaxLod(param); break;
case GL_TEXTURE_COMPARE_MODE: samplerObject->setComparisonMode(static_cast<GLenum>(roundf(param))); break;
case GL_TEXTURE_COMPARE_FUNC: samplerObject->setComparisonFunc(static_cast<GLenum>(roundf(param))); break;
default: UNREACHABLE(pname); break;
}
}
GLint Context::getSamplerParameteri(GLuint sampler, GLenum pname)
{
mResourceManager->checkSamplerAllocation(sampler);
Sampler *samplerObject = getSampler(sampler);
ASSERT(samplerObject);
switch(pname)
{
case GL_TEXTURE_MIN_FILTER: return static_cast<GLint>(samplerObject->getMinFilter());
case GL_TEXTURE_MAG_FILTER: return static_cast<GLint>(samplerObject->getMagFilter());
case GL_TEXTURE_WRAP_S: return static_cast<GLint>(samplerObject->getWrapS());
case GL_TEXTURE_WRAP_T: return static_cast<GLint>(samplerObject->getWrapT());
case GL_TEXTURE_WRAP_R: return static_cast<GLint>(samplerObject->getWrapR());
case GL_TEXTURE_MIN_LOD: return static_cast<GLint>(roundf(samplerObject->getMinLod()));
case GL_TEXTURE_MAX_LOD: return static_cast<GLint>(roundf(samplerObject->getMaxLod()));
case GL_TEXTURE_COMPARE_MODE: return static_cast<GLint>(samplerObject->getComparisonMode());
case GL_TEXTURE_COMPARE_FUNC: return static_cast<GLint>(samplerObject->getComparisonFunc());
default: UNREACHABLE(pname); return 0;
}
}
GLfloat Context::getSamplerParameterf(GLuint sampler, GLenum pname)
{
mResourceManager->checkSamplerAllocation(sampler);
Sampler *samplerObject = getSampler(sampler);
ASSERT(samplerObject);
switch(pname)
{
case GL_TEXTURE_MIN_FILTER: return static_cast<GLfloat>(samplerObject->getMinFilter());
case GL_TEXTURE_MAG_FILTER: return static_cast<GLfloat>(samplerObject->getMagFilter());
case GL_TEXTURE_WRAP_S: return static_cast<GLfloat>(samplerObject->getWrapS());
case GL_TEXTURE_WRAP_T: return static_cast<GLfloat>(samplerObject->getWrapT());
case GL_TEXTURE_WRAP_R: return static_cast<GLfloat>(samplerObject->getWrapR());
case GL_TEXTURE_MIN_LOD: return samplerObject->getMinLod();
case GL_TEXTURE_MAX_LOD: return samplerObject->getMaxLod();
case GL_TEXTURE_COMPARE_MODE: return static_cast<GLfloat>(samplerObject->getComparisonMode());
case GL_TEXTURE_COMPARE_FUNC: return static_cast<GLfloat>(samplerObject->getComparisonFunc());
default: UNREACHABLE(pname); return 0;
}
}
bool Context::getBooleanv(GLenum pname, GLboolean *params) const bool Context::getBooleanv(GLenum pname, GLboolean *params) const
{ {
switch(pname) switch(pname)
......
...@@ -560,6 +560,7 @@ public: ...@@ -560,6 +560,7 @@ public:
TransformFeedback *getTransformFeedback(GLuint transformFeedback) const; TransformFeedback *getTransformFeedback(GLuint transformFeedback) const;
TransformFeedback *getTransformFeedback() const; TransformFeedback *getTransformFeedback() const;
Sampler *getSampler(GLuint sampler) const; Sampler *getSampler(GLuint sampler) const;
bool isSampler(GLuint sampler) const;
Buffer *getArrayBuffer() const; Buffer *getArrayBuffer() const;
Buffer *getElementArrayBuffer() const; Buffer *getElementArrayBuffer() const;
...@@ -583,6 +584,10 @@ public: ...@@ -583,6 +584,10 @@ public:
template<typename T> bool getIntegerv(GLenum pname, T *params) const; template<typename T> bool getIntegerv(GLenum pname, T *params) const;
bool getBooleanv(GLenum pname, GLboolean *params) const; bool getBooleanv(GLenum pname, GLboolean *params) const;
template<typename T> bool getTransformFeedbackiv(GLuint xfb, GLenum pname, T *param) const; template<typename T> bool getTransformFeedbackiv(GLuint xfb, GLenum pname, T *param) const;
void samplerParameteri(GLuint sampler, GLenum pname, GLint param);
void samplerParameterf(GLuint sampler, GLenum pname, GLfloat param);
GLint getSamplerParameteri(GLuint sampler, GLenum pname);
GLfloat getSamplerParameterf(GLuint sampler, GLenum pname);
bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams) const; bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams) const;
......
...@@ -40,6 +40,27 @@ public: ...@@ -40,6 +40,27 @@ public:
mCompareFunc = GL_LEQUAL; mCompareFunc = GL_LEQUAL;
} }
void setMinFilter(GLenum minFilter) { mMinFilter = minFilter; }
void setMagFilter(GLenum magFilter) { mMagFilter = magFilter; }
void setWrapS(GLenum wrapS) { mWrapModeS = wrapS; }
void setWrapT(GLenum wrapT) { mWrapModeT = wrapT; }
void setWrapR(GLenum wrapR) { mWrapModeR = wrapR; }
void setMinLod(GLfloat minLod) { mMinLod = minLod; }
void setMaxLod(GLfloat maxLod) { mMaxLod = maxLod; }
void setComparisonMode(GLenum comparisonMode) { mCompareMode = comparisonMode; }
void setComparisonFunc(GLenum comparisonFunc) { mCompareFunc = comparisonFunc; }
GLenum getMinFilter() const { return mMinFilter; }
GLenum getMagFilter() const { return mMagFilter; }
GLenum getWrapS() const { return mWrapModeS; }
GLenum getWrapT() const { return mWrapModeT; }
GLenum getWrapR() const { return mWrapModeR; }
GLfloat getMinLod() const { return mMinLod; }
GLfloat getMaxLod() const { return mMaxLod; }
GLenum getComparisonMode() const { return mCompareMode; }
GLenum getComparisonFunc() const { return mCompareFunc; }
private:
GLenum mMinFilter; GLenum mMinFilter;
GLenum mMagFilter; GLenum mMagFilter;
......
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