/src/mozilla-central/dom/canvas/WebGL2ContextSamplers.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #include "WebGL2Context.h" |
7 | | #include "WebGLSampler.h" |
8 | | #include "GLContext.h" |
9 | | |
10 | | namespace mozilla { |
11 | | |
12 | | already_AddRefed<WebGLSampler> |
13 | | WebGL2Context::CreateSampler() |
14 | 0 | { |
15 | 0 | const FuncScope funcScope(*this, "createSampler"); |
16 | 0 | if (IsContextLost()) |
17 | 0 | return nullptr; |
18 | 0 | |
19 | 0 | RefPtr<WebGLSampler> globj = new WebGLSampler(this); |
20 | 0 | return globj.forget(); |
21 | 0 | } |
22 | | |
23 | | void |
24 | | WebGL2Context::DeleteSampler(WebGLSampler* sampler) |
25 | 0 | { |
26 | 0 | const FuncScope funcScope(*this, "deleteSampler"); |
27 | 0 | if (!ValidateDeleteObject(sampler)) |
28 | 0 | return; |
29 | 0 | |
30 | 0 | for (uint32_t n = 0; n < mGLMaxTextureUnits; n++) { |
31 | 0 | if (mBoundSamplers[n] == sampler) { |
32 | 0 | mBoundSamplers[n] = nullptr; |
33 | 0 |
|
34 | 0 | InvalidateResolveCacheForTextureWithTexUnit(n); |
35 | 0 | } |
36 | 0 | } |
37 | 0 |
|
38 | 0 | sampler->RequestDelete(); |
39 | 0 | } |
40 | | |
41 | | bool |
42 | | WebGL2Context::IsSampler(const WebGLSampler* const obj) |
43 | 0 | { |
44 | 0 | const FuncScope funcScope(*this, "isSampler"); |
45 | 0 | if (!ValidateIsObject(obj)) |
46 | 0 | return false; |
47 | 0 | |
48 | 0 | return gl->fIsSampler(obj->mGLName); |
49 | 0 | } |
50 | | |
51 | | void |
52 | | WebGL2Context::BindSampler(GLuint unit, WebGLSampler* sampler) |
53 | 0 | { |
54 | 0 | const FuncScope funcScope(*this, "bindSampler"); |
55 | 0 | if (IsContextLost()) |
56 | 0 | return; |
57 | 0 | |
58 | 0 | if (sampler && !ValidateObject("sampler", *sampler)) |
59 | 0 | return; |
60 | 0 | |
61 | 0 | if (unit >= mGLMaxTextureUnits) |
62 | 0 | return ErrorInvalidValue("unit must be < %u", mGLMaxTextureUnits); |
63 | 0 | |
64 | 0 | //// |
65 | 0 | |
66 | 0 | gl->fBindSampler(unit, sampler ? sampler->mGLName : 0); |
67 | 0 |
|
68 | 0 | InvalidateResolveCacheForTextureWithTexUnit(unit); |
69 | 0 | mBoundSamplers[unit] = sampler; |
70 | 0 | } |
71 | | |
72 | | void |
73 | | WebGL2Context::SamplerParameteri(WebGLSampler& sampler, GLenum pname, GLint param) |
74 | 0 | { |
75 | 0 | const FuncScope funcScope(*this, "samplerParameteri"); |
76 | 0 | if (IsContextLost()) |
77 | 0 | return; |
78 | 0 | |
79 | 0 | if (!ValidateObject("sampler", sampler)) |
80 | 0 | return; |
81 | 0 | |
82 | 0 | sampler.SamplerParameter(pname, FloatOrInt(param)); |
83 | 0 | } |
84 | | |
85 | | void |
86 | | WebGL2Context::SamplerParameterf(WebGLSampler& sampler, GLenum pname, GLfloat param) |
87 | 0 | { |
88 | 0 | const FuncScope funcScope(*this, "samplerParameterf"); |
89 | 0 | if (IsContextLost()) |
90 | 0 | return; |
91 | 0 | |
92 | 0 | if (!ValidateObject("sampler", sampler)) |
93 | 0 | return; |
94 | 0 | |
95 | 0 | sampler.SamplerParameter(pname, FloatOrInt(param)); |
96 | 0 | } |
97 | | |
98 | | void |
99 | | WebGL2Context::GetSamplerParameter(JSContext*, const WebGLSampler& sampler, GLenum pname, |
100 | | JS::MutableHandleValue retval) |
101 | 0 | { |
102 | 0 | const FuncScope funcScope(*this, "getSamplerParameter"); |
103 | 0 | retval.setNull(); |
104 | 0 |
|
105 | 0 | if (IsContextLost()) |
106 | 0 | return; |
107 | 0 | |
108 | 0 | if (!ValidateObject("sampler", sampler)) |
109 | 0 | return; |
110 | 0 | |
111 | 0 | //// |
112 | 0 | |
113 | 0 | switch (pname) { |
114 | 0 | case LOCAL_GL_TEXTURE_MIN_FILTER: |
115 | 0 | case LOCAL_GL_TEXTURE_MAG_FILTER: |
116 | 0 | case LOCAL_GL_TEXTURE_WRAP_S: |
117 | 0 | case LOCAL_GL_TEXTURE_WRAP_T: |
118 | 0 | case LOCAL_GL_TEXTURE_WRAP_R: |
119 | 0 | case LOCAL_GL_TEXTURE_COMPARE_MODE: |
120 | 0 | case LOCAL_GL_TEXTURE_COMPARE_FUNC: |
121 | 0 | { |
122 | 0 | GLint param = 0; |
123 | 0 | gl->fGetSamplerParameteriv(sampler.mGLName, pname, ¶m); |
124 | 0 | retval.set(JS::Int32Value(param)); |
125 | 0 | } |
126 | 0 | return; |
127 | 0 |
|
128 | 0 | case LOCAL_GL_TEXTURE_MIN_LOD: |
129 | 0 | case LOCAL_GL_TEXTURE_MAX_LOD: |
130 | 0 | { |
131 | 0 | GLfloat param = 0; |
132 | 0 | gl->fGetSamplerParameterfv(sampler.mGLName, pname, ¶m); |
133 | 0 | retval.set(JS::Float32Value(param)); |
134 | 0 | } |
135 | 0 | return; |
136 | 0 |
|
137 | 0 | default: |
138 | 0 | ErrorInvalidEnumInfo("pname", pname); |
139 | 0 | return; |
140 | 0 | } |
141 | 0 | } |
142 | | |
143 | | } // namespace mozilla |