ShaderUniform .java

net.minecraft.client.shader.ShaderUniform (class): members: setUniformLocation, uniformFloatBuffer, uniformIntBuffer, uniformLocation, getShaderName, set.

net.minecraft.client.shaderclass323 linesclient9.3 KB

API Surface (13)

int parseType(String p_148085_0_)
void setUniformLocation(int p_148084_1_)
String getShaderName()
void set(float p_148090_1_)
void set(float p_148087_1_, float p_148087_2_)
void set(float p_148095_1_, float p_148095_2_, float p_148095_3_)
void set(float p_148081_1_, float p_148081_2_, float p_148081_3_, float p_148081_4_)
void func_148092_b(float p_148092_1_, float p_148092_2_, float p_148092_3_, float p_148092_4_)
void set(int p_148083_1_, int p_148083_2_, int p_148083_3_, int p_148083_4_)
void set(float[] p_148097_1_)
void set(float p_148094_1_, float p_148094_2_, float p_148094_3_, float p_148094_4_, float p_148094_5_, float p_148094_6_, float p_148094_7_, float p_148094_8_, float p_148094_9_, float p_148094_10_, float p_148094_11_, float p_148094_12_, float p_148094_13_, float p_148094_14_, float p_148094_15_, float p_148094_16_)
void set(Matrix4f p_148088_1_)
void upload()

Fields & Constants (9)

logger
uniformLocation
uniformCount
uniformType
uniformIntBuffer
uniformFloatBuffer
shaderName
dirty
shaderManager

String literals (10)

"float"
"matrix"
", got "
"). Ignoring."
"Uniform.upload called, but type value ("
") is not "
"a valid type. Ignoring."
"Uniform.upload called, but count value ("
" not in the range of 1 to 4. Ignoring."
"not in the range of 1 to 4. Ignoring."

Code Graph: Dependencies (2)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ShaderUniform.java323 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.shader;
2
3
import java.nio.FloatBuffer;
4
import java.nio.IntBuffer;
5
import net.minecraft.client.renderer.OpenGlHelper;
6
import org.apache.logging.log4j.LogManager;
7
import org.apache.logging.log4j.Logger;
8
import org.lwjgl.BufferUtils;
9
import org.lwjgl.util.vector.Matrix4f;
10
11
public class ShaderUniform
12
{
13
    private static final Logger logger = LogManager.getLogger();
14
    private int uniformLocation;
15
    private final int uniformCount;
16
    private final int uniformType;
17
    private final IntBuffer uniformIntBuffer;
18
    private final FloatBuffer uniformFloatBuffer;
19
    private final String shaderName;
20
    private boolean dirty;
21
    private final ShaderManager shaderManager;
22
23
    public ShaderUniform(String name, int type, int count, ShaderManager manager)
24
    {
25
        this.shaderName = name;
26
        this.uniformCount = count;
27
        this.uniformType = type;
28
        this.shaderManager = manager;
29
30
        if (type <= 3)
31
        {
32
            this.uniformIntBuffer = BufferUtils.createIntBuffer(count);
33
            this.uniformFloatBuffer = null;
34
        }
35
        else
36
        {
37
            this.uniformIntBuffer = null;
38
            this.uniformFloatBuffer = BufferUtils.createFloatBuffer(count);
39
        }
40
41
        this.uniformLocation = -1;
42
        this.markDirty();
43
    }
44
45
    private void markDirty()
46
    {
47
        this.dirty = true;
48
49
        if (this.shaderManager != null)
50
        {
51
            this.shaderManager.markDirty();
52
        }
53
    }
54
55
    public static int parseType(String p_148085_0_)
56
    {
57
        int i = -1;
58
59
        if (p_148085_0_.equals("int"))
60
        {
61
            i = 0;
62
        }
63
        else if (p_148085_0_.equals("float"))
64
        {
65
            i = 4;
66
        }
67
        else if (p_148085_0_.startsWith("matrix"))
68
        {
69
            if (p_148085_0_.endsWith("2x2"))
70
            {
71
                i = 8;
72
            }
73
            else if (p_148085_0_.endsWith("3x3"))
74
            {
75
                i = 9;
76
            }
77
            else if (p_148085_0_.endsWith("4x4"))
78
            {
79
                i = 10;
80
            }
81
        }
82
83
        return i;
84
    }
85
86
    public void setUniformLocation(int p_148084_1_)
87
    {
88
        this.uniformLocation = p_148084_1_;
89
    }
90
91
    public String getShaderName()
92
    {
93
        return this.shaderName;
94
    }
95
96
    public void set(float p_148090_1_)
97
    {
98
        this.uniformFloatBuffer.position(0);
99
        this.uniformFloatBuffer.put(0, p_148090_1_);
100
        this.markDirty();
101
    }
102
103
    public void set(float p_148087_1_, float p_148087_2_)
104
    {
105
        this.uniformFloatBuffer.position(0);
106
        this.uniformFloatBuffer.put(0, p_148087_1_);
107
        this.uniformFloatBuffer.put(1, p_148087_2_);
108
        this.markDirty();
109
    }
110
111
    public void set(float p_148095_1_, float p_148095_2_, float p_148095_3_)
112
    {
113
        this.uniformFloatBuffer.position(0);
114
        this.uniformFloatBuffer.put(0, p_148095_1_);
115
        this.uniformFloatBuffer.put(1, p_148095_2_);
116
        this.uniformFloatBuffer.put(2, p_148095_3_);
117
        this.markDirty();
118
    }
119
120
    public void set(float p_148081_1_, float p_148081_2_, float p_148081_3_, float p_148081_4_)
121
    {
122
        this.uniformFloatBuffer.position(0);
123
        this.uniformFloatBuffer.put(p_148081_1_);
124
        this.uniformFloatBuffer.put(p_148081_2_);
125
        this.uniformFloatBuffer.put(p_148081_3_);
126
        this.uniformFloatBuffer.put(p_148081_4_);
127
        this.uniformFloatBuffer.flip();
128
        this.markDirty();
129
    }
130
131
    public void func_148092_b(float p_148092_1_, float p_148092_2_, float p_148092_3_, float p_148092_4_)
132
    {
133
        this.uniformFloatBuffer.position(0);
134
135
        if (this.uniformType >= 4)
136
        {
137
            this.uniformFloatBuffer.put(0, p_148092_1_);
138
        }
139
140
        if (this.uniformType >= 5)
141
        {
142
            this.uniformFloatBuffer.put(1, p_148092_2_);
143
        }
144
145
        if (this.uniformType >= 6)
146
        {
147
            this.uniformFloatBuffer.put(2, p_148092_3_);
148
        }
149
150
        if (this.uniformType >= 7)
151
        {
152
            this.uniformFloatBuffer.put(3, p_148092_4_);
153
        }
154
155
        this.markDirty();
156
    }
157
158
    public void set(int p_148083_1_, int p_148083_2_, int p_148083_3_, int p_148083_4_)
159
    {
160
        this.uniformIntBuffer.position(0);
161
162
        if (this.uniformType >= 0)
163
        {
164
            this.uniformIntBuffer.put(0, p_148083_1_);
165
        }
166
167
        if (this.uniformType >= 1)
168
        {
169
            this.uniformIntBuffer.put(1, p_148083_2_);
170
        }
171
172
        if (this.uniformType >= 2)
173
        {
174
            this.uniformIntBuffer.put(2, p_148083_3_);
175
        }
176
177
        if (this.uniformType >= 3)
178
        {
179
            this.uniformIntBuffer.put(3, p_148083_4_);
180
        }
181
182
        this.markDirty();
183
    }
184
185
    public void set(float[] p_148097_1_)
186
    {
187
        if (p_148097_1_.length < this.uniformCount)
188
        {
189
            logger.warn("Uniform.set called with a too-small value array (expected " + this.uniformCount + ", got " + p_148097_1_.length + "). Ignoring.");
190
        }
191
        else
192
        {
193
            this.uniformFloatBuffer.position(0);
194
            this.uniformFloatBuffer.put(p_148097_1_);
195
            this.uniformFloatBuffer.position(0);
196
            this.markDirty();
197
        }
198
    }
199
200
    public void set(float p_148094_1_, float p_148094_2_, float p_148094_3_, float p_148094_4_, float p_148094_5_, float p_148094_6_, float p_148094_7_, float p_148094_8_, float p_148094_9_, float p_148094_10_, float p_148094_11_, float p_148094_12_, float p_148094_13_, float p_148094_14_, float p_148094_15_, float p_148094_16_)
201
    {
202
        this.uniformFloatBuffer.position(0);
203
        this.uniformFloatBuffer.put(0, p_148094_1_);
204
        this.uniformFloatBuffer.put(1, p_148094_2_);
205
        this.uniformFloatBuffer.put(2, p_148094_3_);
206
        this.uniformFloatBuffer.put(3, p_148094_4_);
207
        this.uniformFloatBuffer.put(4, p_148094_5_);
208
        this.uniformFloatBuffer.put(5, p_148094_6_);
209
        this.uniformFloatBuffer.put(6, p_148094_7_);
210
        this.uniformFloatBuffer.put(7, p_148094_8_);
211
        this.uniformFloatBuffer.put(8, p_148094_9_);
212
        this.uniformFloatBuffer.put(9, p_148094_10_);
213
        this.uniformFloatBuffer.put(10, p_148094_11_);
214
        this.uniformFloatBuffer.put(11, p_148094_12_);
215
        this.uniformFloatBuffer.put(12, p_148094_13_);
216
        this.uniformFloatBuffer.put(13, p_148094_14_);
217
        this.uniformFloatBuffer.put(14, p_148094_15_);
218
        this.uniformFloatBuffer.put(15, p_148094_16_);
219
        this.markDirty();
220
    }
221
222
    public void set(Matrix4f p_148088_1_)
223
    {
224
        this.set(p_148088_1_.m00, p_148088_1_.m01, p_148088_1_.m02, p_148088_1_.m03, p_148088_1_.m10, p_148088_1_.m11, p_148088_1_.m12, p_148088_1_.m13, p_148088_1_.m20, p_148088_1_.m21, p_148088_1_.m22, p_148088_1_.m23, p_148088_1_.m30, p_148088_1_.m31, p_148088_1_.m32, p_148088_1_.m33);
225
    }
226
227
    public void upload()
228
    {
229
        if (!this.dirty)
230
        {
231
            ;
232
        }
233
234
        this.dirty = false;
235
236
        if (this.uniformType <= 3)
237
        {
238
            this.uploadInt();
239
        }
240
        else if (this.uniformType <= 7)
241
        {
242
            this.uploadFloat();
243
        }
244
        else
245
        {
246
            if (this.uniformType > 10)
247
            {
248
                logger.warn("Uniform.upload called, but type value (" + this.uniformType + ") is not " + "a valid type. Ignoring.");
249
                return;
250
            }
251
252
            this.uploadFloatMatrix();
253
        }
254
    }
255
256
    private void uploadInt()
257
    {
258
        switch (this.uniformType)
259
        {
260
            case 0:
261
                OpenGlHelper.glUniform1(this.uniformLocation, this.uniformIntBuffer);
262
                break;
263
264
            case 1:
265
                OpenGlHelper.glUniform2(this.uniformLocation, this.uniformIntBuffer);
266
                break;
267
268
            case 2:
269
                OpenGlHelper.glUniform3(this.uniformLocation, this.uniformIntBuffer);
270
                break;
271
272
            case 3:
273
                OpenGlHelper.glUniform4(this.uniformLocation, this.uniformIntBuffer);
274
                break;
275
276
            default:
277
                logger.warn("Uniform.upload called, but count value (" + this.uniformCount + ") is " + " not in the range of 1 to 4. Ignoring.");
278
        }
279
    }
280
281
    private void uploadFloat()
282
    {
283
        switch (this.uniformType)
284
        {
285
            case 4:
286
                OpenGlHelper.glUniform1(this.uniformLocation, this.uniformFloatBuffer);
287
                break;
288
289
            case 5:
290
                OpenGlHelper.glUniform2(this.uniformLocation, this.uniformFloatBuffer);
291
                break;
292
293
            case 6:
294
                OpenGlHelper.glUniform3(this.uniformLocation, this.uniformFloatBuffer);
295
                break;
296
297
            case 7:
298
                OpenGlHelper.glUniform4(this.uniformLocation, this.uniformFloatBuffer);
299
                break;
300
301
            default:
302
                logger.warn("Uniform.upload called, but count value (" + this.uniformCount + ") is " + "not in the range of 1 to 4. Ignoring.");
303
        }
304
    }
305
306
    private void uploadFloatMatrix()
307
    {
308
        switch (this.uniformType)
309
        {
310
            case 8:
311
                OpenGlHelper.glUniformMatrix2(this.uniformLocation, true, this.uniformFloatBuffer);
312
                break;
313
314
            case 9:
315
                OpenGlHelper.glUniformMatrix3(this.uniformLocation, true, this.uniformFloatBuffer);
316
                break;
317
318
            case 10:
319
                OpenGlHelper.glUniformMatrix4(this.uniformLocation, true, this.uniformFloatBuffer);
320
        }
321
    }
322
}
323

Deobfuscated MCP 1.8.9 source of ShaderUniform from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/shader/ShaderUniform.java), stored verbatim.