gecko/dom/canvas/WebGL2ContextSamplers.cpp
Phil Ringnalda c98d9ec4e0 Backed out 12 changesets (bug 1170855) for Windows build bustage
CLOSED TREE

Backed out changeset 47070f494c9e (bug 1170855)
Backed out changeset 86e3fb3a2295 (bug 1170855)
Backed out changeset 49284df5294e (bug 1170855)
Backed out changeset ae7c769cb78d (bug 1170855)
Backed out changeset 1fbb0ef29363 (bug 1170855)
Backed out changeset 1fd9140044be (bug 1170855)
Backed out changeset cca48a1bc6ef (bug 1170855)
Backed out changeset 835570bc63bf (bug 1170855)
Backed out changeset 4ee1883ffc65 (bug 1170855)
Backed out changeset c666d71f4899 (bug 1170855)
Backed out changeset 046422ea849f (bug 1170855)
Backed out changeset d38fb3aea20a (bug 1170855)
2015-06-10 20:47:07 -07:00

220 lines
6.1 KiB
C++

/* -*- 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"
#include "WebGLSampler.h"
#include "GLContext.h"
using namespace mozilla;
using namespace mozilla::dom;
already_AddRefed<WebGLSampler>
WebGL2Context::CreateSampler()
{
if (IsContextLost())
return nullptr;
GLuint sampler;
MakeContextCurrent();
gl->fGenSamplers(1, &sampler);
nsRefPtr<WebGLSampler> globj = new WebGLSampler(this, sampler);
return globj.forget();
}
void
WebGL2Context::DeleteSampler(WebGLSampler* sampler)
{
if (IsContextLost())
return;
if (!ValidateObjectAllowDeletedOrNull("deleteSampler", sampler))
return;
if (!sampler || sampler->IsDeleted())
return;
sampler->RequestDelete();
}
bool
WebGL2Context::IsSampler(WebGLSampler* sampler)
{
if (IsContextLost())
return false;
if (!sampler)
return false;
if (!ValidateObjectAllowDeleted("isSampler", sampler))
return false;
if (sampler->IsDeleted())
return false;
MakeContextCurrent();
return gl->fIsSampler(sampler->mGLName);
}
void
WebGL2Context::BindSampler(GLuint unit, WebGLSampler* sampler)
{
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);
}
void
WebGL2Context::SamplerParameteri(WebGLSampler* sampler, GLenum pname, GLint param)
{
if (IsContextLost())
return;
if (!sampler || sampler->IsDeleted())
return ErrorInvalidOperation("samplerParameteri: invalid sampler");
if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param), "samplerParameteri"))
return;
WebGLContextUnchecked::SamplerParameteri(sampler, pname, param);
}
void
WebGL2Context::SamplerParameteriv(WebGLSampler* sampler, GLenum pname, const dom::Int32Array& param)
{
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());
}
void
WebGL2Context::SamplerParameteriv(WebGLSampler* sampler, GLenum pname, const dom::Sequence<GLint>& param)
{
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());
}
void
WebGL2Context::SamplerParameterf(WebGLSampler* sampler, GLenum pname, GLfloat param)
{
if (IsContextLost())
return;
if (!sampler || sampler->IsDeleted())
return ErrorInvalidOperation("samplerParameterf: invalid sampler");
if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param), "samplerParameterf"))
return;
WebGLContextUnchecked::SamplerParameterf(sampler, pname, param);
}
void
WebGL2Context::SamplerParameterfv(WebGLSampler* sampler, GLenum pname, const dom::Float32Array& param)
{
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());
}
void
WebGL2Context::SamplerParameterfv(WebGLSampler* sampler, GLenum pname, const dom::Sequence<GLfloat>& param)
{
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());
}
void
WebGL2Context::GetSamplerParameter(JSContext*, WebGLSampler* sampler, GLenum pname, JS::MutableHandleValue retval)
{
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;
}
}