GLSLEffect_TypTbl.cs 4.86 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using static PoroCYon.FNAGLSL.GLSLType;
using static Microsoft.Xna.Framework.Graphics.EffectParameterClass;
using static Microsoft.Xna.Framework.Graphics.EffectParameterType ;

using C = Microsoft.Xna.Framework.Graphics.EffectParameterClass;
using T = Microsoft.Xna.Framework.Graphics.EffectParameterType ;

namespace PoroCYon.FNAGLSL {
	public partial class GLSLEffect : Effect {
		readonly static Dictionary<GLSLType, int                 > typ2size ;
		readonly static Dictionary<GLSLType, EffectParameterClass> typ2class;
		readonly static Dictionary<GLSLType, EffectParameterType > typ2type ;

		static GLSLEffect() {
			typ2size = new Dictionary<GLSLType, int>() {
				{ FLOAT, sizeof(float) },
				{ FLOAT_VEC2, sizeof(float)*2 },
				{ FLOAT_VEC3, sizeof(float)*3 },
				{ FLOAT_VEC4, sizeof(float)*4 },
				{ INT, sizeof(int) },
				{ INT_VEC2, sizeof(int)*2 },
				{ INT_VEC3, sizeof(int)*3 },
				{ INT_VEC4, sizeof(int)*4 },
				{ UNSIGNED_INT, sizeof(uint) },
				{ UNSIGNED_INT_VEC2, sizeof(uint)*2 },
				{ UNSIGNED_INT_VEC3, sizeof(uint)*3 },
				{ UNSIGNED_INT_VEC4, sizeof(uint)*4 },
				{ BOOL, sizeof(uint)/*!!!*/ },
				{ BOOL_VEC2, sizeof(uint)*2 },
				{ BOOL_VEC3, sizeof(uint)*3 },
				{ BOOL_VEC4, sizeof(uint)*4 },
				// NOTE: need to be converted when sending these thru the
				//       glUniform fns
				{ FLOAT_MAT2, sizeof(float)*4*4 },
				{ FLOAT_MAT3, sizeof(float)*4*4 },
				{ FLOAT_MAT4, sizeof(float)*4*4 },
				{ FLOAT_MAT2x3, sizeof(float)*4*4 },
				{ FLOAT_MAT2x4, sizeof(float)*4*4 },
				{ FLOAT_MAT3x2, sizeof(float)*4*4 },
				{ FLOAT_MAT3x4, sizeof(float)*4*4 },
				{ FLOAT_MAT4x2, sizeof(float)*4*4 },
				{ FLOAT_MAT4x3, sizeof(float)*4*4 },
			};
			typ2class = new Dictionary<GLSLType, EffectParameterClass>() {
				{ FLOAT, Scalar },
				{ FLOAT_VEC2, Vector },
				{ FLOAT_VEC3, Vector },
				{ FLOAT_VEC4, Vector },
				{ INT, Scalar },
				{ INT_VEC2, Vector },
				{ INT_VEC3, Vector },
				{ INT_VEC4, Vector },
				{ UNSIGNED_INT, Scalar },
				{ UNSIGNED_INT_VEC2, Vector },
				{ UNSIGNED_INT_VEC3, Vector },
				{ UNSIGNED_INT_VEC4, Vector },
				{ BOOL, Scalar },
				{ BOOL_VEC2, Vector },
				{ BOOL_VEC3, Vector },
				{ BOOL_VEC4, Vector },
				{ FLOAT_MAT2, C.Matrix },
				{ FLOAT_MAT3, C.Matrix },
				{ FLOAT_MAT4, C.Matrix },
				{ FLOAT_MAT2x3, C.Matrix },
				{ FLOAT_MAT2x4, C.Matrix },
				{ FLOAT_MAT3x2, C.Matrix },
				{ FLOAT_MAT3x4, C.Matrix },
				{ FLOAT_MAT4x2, C.Matrix },
				{ FLOAT_MAT4x3, C.Matrix },
				{ SAMPLER_1D, C.Object },
				{ SAMPLER_2D, C.Object },
				{ SAMPLER_3D, C.Object },
				{ SAMPLER_CUBE, C.Object },
				{ INT_SAMPLER_1D, C.Object },
				{ INT_SAMPLER_2D, C.Object },
				{ INT_SAMPLER_3D, C.Object },
				{ INT_SAMPLER_CUBE, C.Object },
				{ UNSIGNED_INT_SAMPLER_1D, C.Object },
				{ UNSIGNED_INT_SAMPLER_2D, C.Object },
				{ UNSIGNED_INT_SAMPLER_3D, C.Object },
				{ UNSIGNED_INT_SAMPLER_CUBE, C.Object },
			};
			typ2type = new Dictionary<GLSLType, EffectParameterType>() {
				{ FLOAT, T.Single },
				{ FLOAT_VEC2, T.Single },
				{ FLOAT_VEC3, T.Single },
				{ FLOAT_VEC4, T.Single },
				{ INT, T.Int32 },
				{ INT_VEC2, T.Int32 },
				{ INT_VEC3, T.Int32 },
				{ INT_VEC4, T.Int32 },
				{ UNSIGNED_INT, T.Int32 },
				{ UNSIGNED_INT_VEC2, T.Int32 },
				{ UNSIGNED_INT_VEC3, T.Int32 },
				{ UNSIGNED_INT_VEC4, T.Int32 },
				{ BOOL, T.Bool },
				{ BOOL_VEC2, T.Bool },
				{ BOOL_VEC3, T.Bool },
				{ BOOL_VEC4, T.Bool },
				{ FLOAT_MAT2, T.Single },
				{ FLOAT_MAT3, T.Single },
				{ FLOAT_MAT4, T.Single },
				{ FLOAT_MAT2x3, T.Single },
				{ FLOAT_MAT2x4, T.Single },
				{ FLOAT_MAT3x2, T.Single },
				{ FLOAT_MAT3x4, T.Single },
				{ FLOAT_MAT4x2, T.Single },
				{ FLOAT_MAT4x3, T.Single },
				{ SAMPLER_1D, T.Texture1D },
				{ SAMPLER_2D, T.Texture2D },
				{ SAMPLER_3D, T.Texture3D },
				{ SAMPLER_CUBE, T.TextureCube },
				{ INT_SAMPLER_1D, T.Texture1D },
				{ INT_SAMPLER_2D, T.Texture2D },
				{ INT_SAMPLER_3D, T.Texture3D },
				{ INT_SAMPLER_CUBE, T.TextureCube },
				{ UNSIGNED_INT_SAMPLER_1D, T.Texture1D },
				{ UNSIGNED_INT_SAMPLER_2D, T.Texture2D },
				{ UNSIGNED_INT_SAMPLER_3D, T.Texture3D },
				{ UNSIGNED_INT_SAMPLER_CUBE, T.TextureCube },
			};
		}

		static int GetRows(GLSLType t) {
			switch (t) {
				case FLOAT_MAT2: case FLOAT_MAT3x2: case FLOAT_MAT4x2:
					return 2;
				case FLOAT_MAT3: case FLOAT_MAT2x3: case FLOAT_MAT4x3:
					return 3;
				case FLOAT_MAT4: case FLOAT_MAT2x4: case FLOAT_MAT3x4:
					return 4;
			}

			return 0;
		}
		static int GetCols(GLSLType t) {
			switch (t) {
				case FLOAT_MAT2: case FLOAT_MAT2x3: case FLOAT_MAT2x4:
					return 2;
				case FLOAT_MAT3: case FLOAT_MAT3x2: case FLOAT_MAT3x4:
					return 3;
				case FLOAT_MAT4: case FLOAT_MAT4x2: case FLOAT_MAT4x3:
					return 4;
			}

			return 0;
		}
	}
}