2014-09-18 02:08:41 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WebGLSampler.h"
|
|
|
|
|
|
|
|
#include "GLContext.h"
|
|
|
|
#include "mozilla/dom/WebGL2RenderingContextBinding.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "WebGLContext.h"
|
2014-09-18 02:08:41 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
namespace mozilla {
|
2014-09-18 02:08:41 +04:00
|
|
|
|
2018-08-07 22:12:09 +03:00
|
|
|
|
|
|
|
|
|
|
|
WebGLSampler::WebGLSampler(WebGLContext* const webgl)
|
2016-11-30 05:30:28 +03:00
|
|
|
: WebGLRefCountedObject(webgl)
|
2018-08-07 22:12:09 +03:00
|
|
|
, mGLName([&]() {
|
|
|
|
GLuint ret = 0;
|
|
|
|
webgl->gl->fGenSamplers(1, &ret);
|
|
|
|
return ret;
|
|
|
|
}())
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2014-10-27 02:40:37 +03:00
|
|
|
mContext->mSamplers.insertBack(this);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
WebGLSampler::~WebGLSampler()
|
2014-10-27 02:40:37 +03:00
|
|
|
{
|
|
|
|
DeleteOnce();
|
|
|
|
}
|
2014-09-18 02:08:41 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
WebGLSampler::Delete()
|
|
|
|
{
|
2014-10-27 02:40:37 +03:00
|
|
|
mContext->gl->fDeleteSamplers(1, &mGLName);
|
|
|
|
|
|
|
|
removeFrom(mContext->mSamplers);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
WebGLContext*
|
|
|
|
WebGLSampler::GetParentObject() const
|
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
return mContext;
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
2015-07-15 03:37:28 +03:00
|
|
|
WebGLSampler::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2018-06-26 00:20:54 +03:00
|
|
|
return dom::WebGLSampler_Binding::Wrap(cx, this, givenProto);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
static bool
|
2018-07-27 07:46:33 +03:00
|
|
|
ValidateSamplerParameterParams(WebGLContext* webgl, GLenum pname,
|
2016-12-23 00:52:53 +03:00
|
|
|
const FloatOrInt& param)
|
2016-01-21 09:49:41 +03:00
|
|
|
{
|
2016-12-23 00:52:53 +03:00
|
|
|
const auto& paramInt = param.i;
|
|
|
|
|
2016-01-21 09:49:41 +03:00
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_TEXTURE_MIN_FILTER:
|
2016-11-02 00:58:07 +03:00
|
|
|
switch (paramInt) {
|
|
|
|
case LOCAL_GL_NEAREST:
|
|
|
|
case LOCAL_GL_LINEAR:
|
|
|
|
case LOCAL_GL_NEAREST_MIPMAP_NEAREST:
|
|
|
|
case LOCAL_GL_NEAREST_MIPMAP_LINEAR:
|
|
|
|
case LOCAL_GL_LINEAR_MIPMAP_NEAREST:
|
|
|
|
case LOCAL_GL_LINEAR_MIPMAP_LINEAR:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-01-21 09:49:41 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_TEXTURE_MAG_FILTER:
|
2016-11-02 00:58:07 +03:00
|
|
|
switch (paramInt) {
|
|
|
|
case LOCAL_GL_NEAREST:
|
|
|
|
case LOCAL_GL_LINEAR:
|
|
|
|
return true;
|
2016-01-21 09:49:41 +03:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-01-21 09:49:41 +03:00
|
|
|
break;
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
case LOCAL_GL_TEXTURE_WRAP_S:
|
2016-01-21 09:49:41 +03:00
|
|
|
case LOCAL_GL_TEXTURE_WRAP_T:
|
|
|
|
case LOCAL_GL_TEXTURE_WRAP_R:
|
2016-11-02 00:58:07 +03:00
|
|
|
switch (paramInt) {
|
|
|
|
case LOCAL_GL_CLAMP_TO_EDGE:
|
|
|
|
case LOCAL_GL_REPEAT:
|
|
|
|
case LOCAL_GL_MIRRORED_REPEAT:
|
|
|
|
return true;
|
2016-01-21 09:49:41 +03:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-01-21 09:49:41 +03:00
|
|
|
break;
|
|
|
|
|
2016-11-07 05:22:31 +03:00
|
|
|
case LOCAL_GL_TEXTURE_MIN_LOD:
|
2016-11-02 00:58:07 +03:00
|
|
|
case LOCAL_GL_TEXTURE_MAX_LOD:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case LOCAL_GL_TEXTURE_COMPARE_MODE:
|
|
|
|
switch (paramInt) {
|
|
|
|
case LOCAL_GL_NONE:
|
|
|
|
case LOCAL_GL_COMPARE_REF_TO_TEXTURE:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-11-07 05:22:31 +03:00
|
|
|
break;
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
case LOCAL_GL_TEXTURE_COMPARE_FUNC:
|
|
|
|
switch (paramInt) {
|
|
|
|
case LOCAL_GL_LEQUAL:
|
|
|
|
case LOCAL_GL_GEQUAL:
|
|
|
|
case LOCAL_GL_LESS:
|
|
|
|
case LOCAL_GL_GREATER:
|
|
|
|
case LOCAL_GL_EQUAL:
|
|
|
|
case LOCAL_GL_NOTEQUAL:
|
|
|
|
case LOCAL_GL_ALWAYS:
|
|
|
|
case LOCAL_GL_NEVER:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-11-07 05:22:31 +03:00
|
|
|
break;
|
|
|
|
|
2016-01-21 09:49:41 +03:00
|
|
|
default:
|
2018-07-27 07:46:33 +03:00
|
|
|
webgl->ErrorInvalidEnumInfo("pname", pname);
|
2016-11-02 00:58:07 +03:00
|
|
|
return false;
|
2016-01-21 09:49:41 +03:00
|
|
|
}
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
webgl->ErrorInvalidEnumInfo("param", paramInt);
|
2016-11-02 00:58:07 +03:00
|
|
|
return false;
|
2016-01-21 09:49:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-07-27 07:46:33 +03:00
|
|
|
WebGLSampler::SamplerParameter(GLenum pname, const FloatOrInt& param)
|
2016-01-21 09:49:41 +03:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateSamplerParameterParams(mContext, pname, param))
|
2016-11-02 00:58:07 +03:00
|
|
|
return;
|
|
|
|
|
2016-01-21 09:49:41 +03:00
|
|
|
switch (pname) {
|
2016-11-02 00:58:07 +03:00
|
|
|
case LOCAL_GL_TEXTURE_MIN_FILTER:
|
2018-08-07 22:12:09 +03:00
|
|
|
mState.minFilter = param.i;
|
2016-01-21 09:49:41 +03:00
|
|
|
break;
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
case LOCAL_GL_TEXTURE_MAG_FILTER:
|
2018-08-07 22:12:09 +03:00
|
|
|
mState.magFilter = param.i;
|
2016-01-21 09:49:41 +03:00
|
|
|
break;
|
|
|
|
|
2016-11-07 05:22:31 +03:00
|
|
|
case LOCAL_GL_TEXTURE_WRAP_S:
|
2018-08-07 22:12:09 +03:00
|
|
|
mState.wrapS = param.i;
|
2016-11-07 05:22:31 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_TEXTURE_WRAP_T:
|
2018-08-07 22:12:09 +03:00
|
|
|
mState.wrapT = param.i;
|
2016-11-07 05:22:31 +03:00
|
|
|
break;
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
case LOCAL_GL_TEXTURE_COMPARE_MODE:
|
2018-08-07 22:12:09 +03:00
|
|
|
mState.compareMode = param.i;
|
2016-11-07 05:22:31 +03:00
|
|
|
break;
|
|
|
|
|
2016-01-21 09:49:41 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mContext->mBoundSamplers.Length(); ++i) {
|
|
|
|
if (this == mContext->mBoundSamplers[i])
|
|
|
|
mContext->InvalidateResolveCacheForTextureWithTexUnit(i);
|
|
|
|
}
|
2016-11-02 00:58:07 +03:00
|
|
|
|
|
|
|
////
|
|
|
|
|
2016-12-23 00:52:53 +03:00
|
|
|
if (param.isFloat) {
|
|
|
|
mContext->gl->fSamplerParameterf(mGLName, pname, param.f);
|
|
|
|
} else {
|
|
|
|
mContext->gl->fSamplerParameteri(mGLName, pname, param.i);
|
|
|
|
}
|
2016-01-21 09:49:41 +03:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
////
|
2014-09-18 02:08:41 +04:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLSampler)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLSampler, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLSampler, Release)
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|