2014-09-17 22:08:41 +00: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-26 23:40:37 +00:00
|
|
|
#include "WebGLSampler.h"
|
2014-09-17 22:08:41 +00:00
|
|
|
#include "GLContext.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
already_AddRefed<WebGLSampler>
|
|
|
|
WebGL2Context::CreateSampler()
|
|
|
|
{
|
2014-10-26 23:40:37 +00:00
|
|
|
if (IsContextLost())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
GLuint sampler;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fGenSamplers(1, &sampler);
|
|
|
|
|
|
|
|
nsRefPtr<WebGLSampler> globj = new WebGLSampler(this, sampler);
|
|
|
|
return globj.forget();
|
2014-09-17 22:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGL2Context::DeleteSampler(WebGLSampler* sampler)
|
|
|
|
{
|
2014-10-26 23:40:37 +00:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ValidateObjectAllowDeletedOrNull("deleteSampler", sampler))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!sampler || sampler->IsDeleted())
|
|
|
|
return;
|
|
|
|
|
|
|
|
sampler->RequestDelete();
|
2014-09-17 22:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGL2Context::IsSampler(WebGLSampler* sampler)
|
|
|
|
{
|
2014-10-26 23:40:37 +00:00
|
|
|
if (IsContextLost())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!sampler)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!ValidateObjectAllowDeleted("isSampler", sampler))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (sampler->IsDeleted())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !sampler->HasEverBeenBound();
|
2014-09-17 22:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGL2Context::BindSampler(GLuint unit, WebGLSampler* sampler)
|
|
|
|
{
|
2014-10-26 23:40:37 +00:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ValidateObjectAllowDeletedOrNull("bindSampler", sampler))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (GLint(unit) >= mGLMaxTextureUnits)
|
|
|
|
return ErrorInvalidValue("bindSampler: unit must be < %d", mGLMaxTextureUnits);
|
|
|
|
|
|
|
|
if (sampler && sampler->IsDeleted())
|
|
|
|
return ErrorInvalidOperation("bindSampler: binding deleted sampler");
|
|
|
|
|
|
|
|
WebGLContextUnchecked::BindSampler(unit, sampler);
|
2014-09-17 22:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGL2Context::SamplerParameteri(WebGLSampler* sampler, GLenum pname, GLint param)
|
|
|
|
{
|
2014-10-26 23:40:37 +00:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!sampler || sampler->IsDeleted())
|
|
|
|
return ErrorInvalidOperation("samplerParameteri: invalid sampler");
|
|
|
|
|
|
|
|
if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param), "samplerParameteri"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebGLContextUnchecked::SamplerParameteri(sampler, pname, param);
|
2014-09-17 22:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGL2Context::SamplerParameteriv(WebGLSampler* sampler, GLenum pname, const dom::Int32Array& param)
|
|
|
|
{
|
2014-10-26 23:40:37 +00:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!sampler || sampler->IsDeleted())
|
|
|
|
return ErrorInvalidOperation("samplerParameteriv: invalid sampler");
|
|
|
|
|
|
|
|
param.ComputeLengthAndData();
|
|
|
|
if (param.Length() < 1)
|
|
|
|
return /* TODO(djg): Error message */;
|
|
|
|
|
|
|
|
/* TODO(djg): All of these calls in ES3 only take 1 param */
|
|
|
|
if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param.Data()[0]), "samplerParameteriv"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebGLContextUnchecked::SamplerParameteriv(sampler, pname, param.Data());
|
2014-09-17 22:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGL2Context::SamplerParameteriv(WebGLSampler* sampler, GLenum pname, const dom::Sequence<GLint>& param)
|
|
|
|
{
|
2014-10-26 23:40:37 +00:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!sampler || sampler->IsDeleted())
|
|
|
|
return ErrorInvalidOperation("samplerParameteriv: invalid sampler");
|
|
|
|
|
|
|
|
if (param.Length() < 1)
|
|
|
|
return /* TODO(djg): Error message */;
|
|
|
|
|
|
|
|
/* TODO(djg): All of these calls in ES3 only take 1 param */
|
|
|
|
if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param[0]), "samplerParameteriv"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebGLContextUnchecked::SamplerParameteriv(sampler, pname, param.Elements());
|
2014-09-17 22:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGL2Context::SamplerParameterf(WebGLSampler* sampler, GLenum pname, GLfloat param)
|
|
|
|
{
|
2014-10-26 23:40:37 +00:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!sampler || sampler->IsDeleted())
|
|
|
|
return ErrorInvalidOperation("samplerParameterf: invalid sampler");
|
|
|
|
|
|
|
|
if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param), "samplerParameterf"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebGLContextUnchecked::SamplerParameterf(sampler, pname, param);
|
2014-09-17 22:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGL2Context::SamplerParameterfv(WebGLSampler* sampler, GLenum pname, const dom::Float32Array& param)
|
|
|
|
{
|
2014-10-26 23:40:37 +00:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!sampler || sampler->IsDeleted())
|
|
|
|
return ErrorInvalidOperation("samplerParameterfv: invalid sampler");
|
|
|
|
|
|
|
|
param.ComputeLengthAndData();
|
|
|
|
if (param.Length() < 1)
|
|
|
|
return /* TODO(djg): Error message */;
|
|
|
|
|
|
|
|
/* TODO(djg): All of these calls in ES3 only take 1 param */
|
|
|
|
if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param.Data()[0]), "samplerParameterfv"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebGLContextUnchecked::SamplerParameterfv(sampler, pname, param.Data());
|
2014-09-17 22:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGL2Context::SamplerParameterfv(WebGLSampler* sampler, GLenum pname, const dom::Sequence<GLfloat>& param)
|
|
|
|
{
|
2014-10-26 23:40:37 +00:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!sampler || sampler->IsDeleted())
|
|
|
|
return ErrorInvalidOperation("samplerParameterfv: invalid sampler");
|
|
|
|
|
|
|
|
if (param.Length() < 1)
|
|
|
|
return /* TODO(djg): Error message */;
|
|
|
|
|
|
|
|
/* TODO(djg): All of these calls in ES3 only take 1 param */
|
|
|
|
if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param[0]), "samplerParameterfv"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebGLContextUnchecked::SamplerParameterfv(sampler, pname, param.Elements());
|
2014-09-17 22:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGL2Context::GetSamplerParameter(JSContext*, WebGLSampler* sampler, GLenum pname, JS::MutableHandleValue retval)
|
|
|
|
{
|
2014-10-26 23:40:37 +00:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!sampler || sampler->IsDeleted())
|
|
|
|
return ErrorInvalidOperation("getSamplerParameter: invalid sampler");
|
|
|
|
|
|
|
|
if (!ValidateSamplerParameterName(pname, "getSamplerParameter"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
retval.set(JS::NullValue());
|
|
|
|
|
|
|
|
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:
|
|
|
|
retval.set(JS::Int32Value(
|
|
|
|
WebGLContextUnchecked::GetSamplerParameteriv(sampler, pname)));
|
|
|
|
return;
|
|
|
|
|
|
|
|
case LOCAL_GL_TEXTURE_MIN_LOD:
|
|
|
|
case LOCAL_GL_TEXTURE_MAX_LOD:
|
|
|
|
retval.set(JS::Float32Value(
|
|
|
|
WebGLContextUnchecked::GetSamplerParameterfv(sampler, pname)));
|
|
|
|
return;
|
|
|
|
}
|
2014-09-17 22:08:41 +00:00
|
|
|
}
|