2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2014-09-18 02:08:41 +04:00
|
|
|
/* 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 "WebGL2Context.h"
|
2014-10-27 02:40:37 +03:00
|
|
|
#include "WebGLSampler.h"
|
2014-09-18 02:08:41 +04:00
|
|
|
#include "GLContext.h"
|
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
namespace mozilla {
|
2014-09-18 02:08:41 +04:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
RefPtr<WebGLSampler> WebGL2Context::CreateSampler() {
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "createSampler");
|
2014-10-27 02:40:37 +03:00
|
|
|
if (IsContextLost()) return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
return new WebGLSampler(this);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebGL2Context::BindSampler(GLuint unit, WebGLSampler* sampler) {
|
2020-01-09 01:19:16 +03:00
|
|
|
FuncScope funcScope(*this, "bindSampler");
|
2014-10-27 02:40:37 +03:00
|
|
|
if (IsContextLost()) return;
|
2020-01-09 01:19:16 +03:00
|
|
|
funcScope.mBindFailureGuard = true;
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (sampler && !ValidateObject("sampler", *sampler)) return;
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
if (unit >= mBoundSamplers.Length())
|
|
|
|
return ErrorInvalidValue("unit must be < %u", mBoundSamplers.Length());
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2016-11-18 02:01:28 +03:00
|
|
|
////
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2016-11-18 02:01:28 +03:00
|
|
|
gl->fBindSampler(unit, sampler ? sampler->mGLName : 0);
|
2014-09-18 02:08:41 +04:00
|
|
|
|
2016-11-18 02:01:28 +03:00
|
|
|
mBoundSamplers[unit] = sampler;
|
2020-01-09 01:19:16 +03:00
|
|
|
|
|
|
|
funcScope.mBindFailureGuard = false;
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
2016-12-23 00:52:53 +03:00
|
|
|
void WebGL2Context::SamplerParameteri(WebGLSampler& sampler, GLenum pname,
|
|
|
|
GLint param) {
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "samplerParameteri");
|
2014-10-27 02:40:37 +03:00
|
|
|
if (IsContextLost()) return;
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateObject("sampler", sampler)) return;
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
sampler.SamplerParameter(pname, FloatOrInt(param));
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
2016-12-23 00:52:53 +03:00
|
|
|
void WebGL2Context::SamplerParameterf(WebGLSampler& sampler, GLenum pname,
|
|
|
|
GLfloat param) {
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "samplerParameterf");
|
2014-10-27 02:40:37 +03:00
|
|
|
if (IsContextLost()) return;
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateObject("sampler", sampler)) return;
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
sampler.SamplerParameter(pname, FloatOrInt(param));
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
Maybe<double> WebGL2Context::GetSamplerParameter(const WebGLSampler& sampler,
|
|
|
|
GLenum pname) const {
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "getSamplerParameter");
|
2020-01-09 01:19:16 +03:00
|
|
|
if (IsContextLost()) return {};
|
2014-09-18 02:08:41 +04:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
if (!ValidateObject("sampler", sampler)) return {};
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2016-11-18 02:01:28 +03:00
|
|
|
////
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2020-02-23 07:22:54 +03:00
|
|
|
const auto fnAsFloat = [&]() {
|
|
|
|
GLfloat param = 0;
|
|
|
|
gl->fGetSamplerParameterfv(sampler.mGLName, pname, ¶m);
|
|
|
|
return param;
|
|
|
|
};
|
|
|
|
|
2014-10-27 02:40:37 +03:00
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_TEXTURE_MIN_FILTER:
|
|
|
|
case LOCAL_GL_TEXTURE_MAG_FILTER:
|
|
|
|
case LOCAL_GL_TEXTURE_WRAP_S:
|
|
|
|
case LOCAL_GL_TEXTURE_WRAP_T:
|
|
|
|
case LOCAL_GL_TEXTURE_WRAP_R:
|
|
|
|
case LOCAL_GL_TEXTURE_COMPARE_MODE:
|
|
|
|
case LOCAL_GL_TEXTURE_COMPARE_FUNC: {
|
2016-11-18 02:01:28 +03:00
|
|
|
GLint param = 0;
|
|
|
|
gl->fGetSamplerParameteriv(sampler.mGLName, pname, ¶m);
|
2020-01-09 01:19:16 +03:00
|
|
|
return Some(param);
|
2016-11-18 02:01:28 +03:00
|
|
|
}
|
2014-10-27 02:40:37 +03:00
|
|
|
case LOCAL_GL_TEXTURE_MIN_LOD:
|
2020-02-23 07:22:54 +03:00
|
|
|
case LOCAL_GL_TEXTURE_MAX_LOD:
|
|
|
|
return Some(fnAsFloat());
|
|
|
|
|
|
|
|
case LOCAL_GL_TEXTURE_MAX_ANISOTROPY:
|
|
|
|
if (!IsExtensionEnabled(
|
|
|
|
WebGLExtensionID::EXT_texture_filter_anisotropic)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return Some(fnAsFloat());
|
2016-11-18 02:01:28 +03:00
|
|
|
|
|
|
|
default:
|
2020-02-23 07:22:54 +03:00
|
|
|
break;
|
2014-10-27 02:40:37 +03:00
|
|
|
}
|
2020-02-23 07:22:54 +03:00
|
|
|
ErrorInvalidEnumInfo("pname", pname);
|
|
|
|
return {};
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
2015-07-15 03:37:28 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|