gecko-dev/dom/canvas/WebGL2ContextSamplers.cpp

148 строки
3.5 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"
namespace mozilla {
already_AddRefed<WebGLSampler>
WebGL2Context::CreateSampler()
{
if (IsContextLost())
return nullptr;
GLuint sampler;
MakeContextCurrent();
gl->fGenSamplers(1, &sampler);
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<WebGLSampler> globj = new WebGLSampler(this, sampler);
return globj.forget();
}
void
WebGL2Context::DeleteSampler(WebGLSampler* sampler)
{
if (!ValidateDeleteObject("deleteSampler", sampler))
return;
for (int n = 0; n < mGLMaxTextureUnits; n++) {
if (mBoundSamplers[n] == sampler) {
mBoundSamplers[n] = nullptr;
InvalidateResolveCacheForTextureWithTexUnit(n);
}
}
sampler->RequestDelete();
}
bool
WebGL2Context::IsSampler(const WebGLSampler* sampler)
{
if (!ValidateIsObject("isSampler", sampler))
return false;
MakeContextCurrent();
return gl->fIsSampler(sampler->mGLName);
}
void
WebGL2Context::BindSampler(GLuint unit, WebGLSampler* sampler)
{
if (IsContextLost())
return;
if (sampler && !ValidateObject("bindSampler", *sampler))
return;
if (GLint(unit) >= mGLMaxTextureUnits)
return ErrorInvalidValue("bindSampler: unit must be < %d", mGLMaxTextureUnits);
////
gl->MakeCurrent();
gl->fBindSampler(unit, sampler ? sampler->mGLName : 0);
InvalidateResolveCacheForTextureWithTexUnit(unit);
mBoundSamplers[unit] = sampler;
}
void
WebGL2Context::SamplerParameteri(WebGLSampler& sampler, GLenum pname, GLint param)
{
const char funcName[] = "samplerParameteri";
if (IsContextLost())
return;
if (!ValidateObject(funcName, sampler))
return;
sampler.SamplerParameter(funcName, pname, FloatOrInt(param));
}
void
WebGL2Context::SamplerParameterf(WebGLSampler& sampler, GLenum pname, GLfloat param)
{
const char funcName[] = "samplerParameterf";
if (IsContextLost())
return;
if (!ValidateObject(funcName, sampler))
return;
sampler.SamplerParameter(funcName, pname, FloatOrInt(param));
}
void
WebGL2Context::GetSamplerParameter(JSContext*, const WebGLSampler& sampler, GLenum pname,
JS::MutableHandleValue retval)
{
const char funcName[] = "getSamplerParameter";
retval.setNull();
if (IsContextLost())
return;
if (!ValidateObject(funcName, sampler))
return;
////
gl->MakeCurrent();
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:
{
GLint param = 0;
gl->fGetSamplerParameteriv(sampler.mGLName, pname, &param);
retval.set(JS::Int32Value(param));
}
return;
case LOCAL_GL_TEXTURE_MIN_LOD:
case LOCAL_GL_TEXTURE_MAX_LOD:
{
GLfloat param = 0;
gl->fGetSamplerParameterfv(sampler.mGLName, pname, &param);
retval.set(JS::Float32Value(param));
}
return;
default:
ErrorInvalidEnumArg(funcName, "pname", pname);
return;
}
}
} // namespace mozilla