Complete the sampler object to match WebGPU

WebGPUSampler is much more complete than Dawn's Sampler.
This patch implement the missing part.

BUG=dawn:47

Change-Id: Ief45cb9710493e9d79ddab60fe3be5a123b76ebd
Reviewed-on: https://dawn-review.googlesource.com/c/3540
Commit-Queue: Shaobo Yan <shaobo.yan@intel.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Yan, Shaobo
2019-01-04 04:56:08 +00:00
committed by Commit Bot service account
parent ea56333c1e
commit 93158ebede
21 changed files with 446 additions and 17 deletions

View File

@@ -16,6 +16,7 @@
#include "common/Assert.h"
#include "dawn_native/opengl/DeviceGL.h"
#include "dawn_native/opengl/UtilsGL.h"
namespace dawn_native { namespace opengl {
@@ -64,11 +65,17 @@ namespace dawn_native { namespace opengl {
return GL_MIRRORED_REPEAT;
case dawn::AddressMode::ClampToEdge:
return GL_CLAMP_TO_EDGE;
case dawn::AddressMode::ClampToBorderColor:
return GL_CLAMP_TO_BORDER;
default:
UNREACHABLE();
}
}
static const float kTransparentBlack[4] = {0.0, 0.0, 0.0, 0.0};
static const float kOpaqueBlack[4] = {0.0, 0.0, 0.0, 1.0};
static const float kOpaqueWhite[4] = {1.0, 1.0, 1.0, 1.0};
} // namespace
Sampler::Sampler(Device* device, const SamplerDescriptor* descriptor)
@@ -80,6 +87,29 @@ namespace dawn_native { namespace opengl {
glSamplerParameteri(mHandle, GL_TEXTURE_WRAP_R, WrapMode(descriptor->addressModeW));
glSamplerParameteri(mHandle, GL_TEXTURE_WRAP_S, WrapMode(descriptor->addressModeU));
glSamplerParameteri(mHandle, GL_TEXTURE_WRAP_T, WrapMode(descriptor->addressModeV));
glSamplerParameterf(mHandle, GL_TEXTURE_MIN_LOD, descriptor->lodMinClamp);
glSamplerParameterf(mHandle, GL_TEXTURE_MAX_LOD, descriptor->lodMaxClamp);
if (ToOpenGLCompareFunction(descriptor->compareFunction) != GL_NEVER) {
glSamplerParameteri(mHandle, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
glSamplerParameteri(mHandle, GL_TEXTURE_COMPARE_FUNC,
ToOpenGLCompareFunction(descriptor->compareFunction));
}
switch (descriptor->borderColor) {
case dawn::BorderColor::TransparentBlack:
glSamplerParameterfv(mHandle, GL_TEXTURE_BORDER_COLOR, kTransparentBlack);
break;
case dawn::BorderColor::OpaqueBlack:
glSamplerParameterfv(mHandle, GL_TEXTURE_BORDER_COLOR, kOpaqueBlack);
break;
case dawn::BorderColor::OpaqueWhite:
glSamplerParameterfv(mHandle, GL_TEXTURE_BORDER_COLOR, kOpaqueWhite);
break;
default:
UNREACHABLE();
}
}
GLuint Sampler::GetHandle() const {

View File

@@ -0,0 +1,44 @@
// Copyright 2019 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "dawn_native/opengl/UtilsGL.h"
#include "common/Assert.h"
namespace dawn_native { namespace opengl {
GLuint ToOpenGLCompareFunction(dawn::CompareFunction compareFunction) {
switch (compareFunction) {
case dawn::CompareFunction::Never:
return GL_NEVER;
case dawn::CompareFunction::Less:
return GL_LESS;
case dawn::CompareFunction::LessEqual:
return GL_LEQUAL;
case dawn::CompareFunction::Greater:
return GL_GREATER;
case dawn::CompareFunction::GreaterEqual:
return GL_GEQUAL;
case dawn::CompareFunction::NotEqual:
return GL_NOTEQUAL;
case dawn::CompareFunction::Equal:
return GL_EQUAL;
case dawn::CompareFunction::Always:
return GL_ALWAYS;
default:
UNREACHABLE();
}
}
}} // namespace dawn_native::opengl

View File

@@ -0,0 +1,27 @@
// Copyright 2019 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef DAWNNATIVE_OPENGL_UTILSGL_H_
#define DAWNNATIVE_OPENGL_UTILSGL_H_
#include "dawn_native/dawn_platform.h"
#include "glad/glad.h"
namespace dawn_native { namespace opengl {
GLuint ToOpenGLCompareFunction(dawn::CompareFunction compareFunction);
}} // namespace dawn_native::opengl
#endif // DAWNNATIVE_OPENGL_UTILSGL_H_