2014-09-18 02:08:41 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; 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 "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
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
already_AddRefed<WebGLSampler> WebGL2Context::CreateSampler() {
|
|
|
|
const FuncScope funcScope(*this, "createSampler");
|
|
|
|
if (IsContextLost()) return nullptr;
|
|
|
|
|
|
|
|
RefPtr<WebGLSampler> globj = new WebGLSampler(this);
|
|
|
|
return globj.forget();
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
void WebGL2Context::DeleteSampler(WebGLSampler* sampler) {
|
|
|
|
const FuncScope funcScope(*this, "deleteSampler");
|
|
|
|
if (!ValidateDeleteObject(sampler)) return;
|
|
|
|
|
|
|
|
for (uint32_t n = 0; n < mGLMaxTextureUnits; n++) {
|
|
|
|
if (mBoundSamplers[n] == sampler) {
|
|
|
|
mBoundSamplers[n] = nullptr;
|
2015-06-09 03:18:19 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-06-09 03:18:19 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
sampler->RequestDelete();
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
bool WebGL2Context::IsSampler(const WebGLSampler* const obj) {
|
|
|
|
const FuncScope funcScope(*this, "isSampler");
|
|
|
|
if (!ValidateIsObject(obj)) return false;
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
if (obj->IsDeleteRequested()) return false;
|
2018-10-17 09:54:28 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
return true;
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
void WebGL2Context::BindSampler(GLuint unit, WebGLSampler* sampler) {
|
|
|
|
const FuncScope funcScope(*this, "bindSampler");
|
|
|
|
if (IsContextLost()) return;
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
if (sampler && !ValidateObject("sampler", *sampler)) return;
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
if (unit >= mGLMaxTextureUnits)
|
|
|
|
return ErrorInvalidValue("unit must be < %u", mGLMaxTextureUnits);
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
////
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
gl->fBindSampler(unit, sampler ? sampler->mGLName : 0);
|
2014-09-18 02:08:41 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
mBoundSamplers[unit] = sampler;
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
void WebGL2Context::SamplerParameteri(WebGLSampler& sampler, GLenum pname,
|
|
|
|
GLint param) {
|
|
|
|
const FuncScope funcScope(*this, "samplerParameteri");
|
|
|
|
if (IsContextLost()) return;
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
if (!ValidateObject("sampler", sampler)) return;
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
sampler.SamplerParameter(pname, FloatOrInt(param));
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
void WebGL2Context::SamplerParameterf(WebGLSampler& sampler, GLenum pname,
|
|
|
|
GLfloat param) {
|
|
|
|
const FuncScope funcScope(*this, "samplerParameterf");
|
|
|
|
if (IsContextLost()) return;
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
if (!ValidateObject("sampler", sampler)) return;
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
sampler.SamplerParameter(pname, FloatOrInt(param));
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
void WebGL2Context::GetSamplerParameter(JSContext*, const WebGLSampler& sampler,
|
|
|
|
GLenum pname,
|
|
|
|
JS::MutableHandleValue retval) {
|
|
|
|
const FuncScope funcScope(*this, "getSamplerParameter");
|
|
|
|
retval.setNull();
|
2014-09-18 02:08:41 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
if (IsContextLost()) return;
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
if (!ValidateObject("sampler", sampler)) return;
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
////
|
2014-10-27 02:40:37 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
switch (pname) {
|
2014-10-27 02:40:37 +03:00
|
|
|
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:
|
2018-11-30 13:46:48 +03:00
|
|
|
case LOCAL_GL_TEXTURE_COMPARE_FUNC: {
|
|
|
|
GLint param = 0;
|
|
|
|
gl->fGetSamplerParameteriv(sampler.mGLName, pname, ¶m);
|
|
|
|
retval.set(JS::Int32Value(param));
|
|
|
|
}
|
|
|
|
return;
|
2014-10-27 02:40:37 +03:00
|
|
|
|
|
|
|
case LOCAL_GL_TEXTURE_MIN_LOD:
|
2018-11-30 13:46:48 +03:00
|
|
|
case LOCAL_GL_TEXTURE_MAX_LOD: {
|
|
|
|
GLfloat param = 0;
|
|
|
|
gl->fGetSamplerParameterfv(sampler.mGLName, pname, ¶m);
|
|
|
|
retval.set(JS::Float32Value(param));
|
|
|
|
}
|
|
|
|
return;
|
2016-11-18 02:01:28 +03:00
|
|
|
|
|
|
|
default:
|
2018-11-30 13:46:48 +03:00
|
|
|
ErrorInvalidEnumInfo("pname", pname);
|
|
|
|
return;
|
|
|
|
}
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
2015-07-15 03:37:28 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
} // namespace mozilla
|