aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llrender/llrender.h
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llrender/llrender.h')
-rw-r--r--linden/indra/llrender/llrender.h239
1 files changed, 239 insertions, 0 deletions
diff --git a/linden/indra/llrender/llrender.h b/linden/indra/llrender/llrender.h
new file mode 100644
index 0000000..03280fe
--- /dev/null
+++ b/linden/indra/llrender/llrender.h
@@ -0,0 +1,239 @@
1/**
2 * @file llrender.h
3 * @brief LLRender definition
4 *
5 * This class acts as a wrapper for OpenGL calls.
6 * The goal of this class is to minimize the number of api calls due to legacy rendering
7 * code, to define an interface for a multiple rendering API abstraction of the UI
8 * rendering, and to abstract out direct rendering calls in a way that is cleaner and easier to maintain.
9 *
10 * $LicenseInfo:firstyear=2001&license=viewergpl$
11 *
12 * Copyright (c) 2001-2008, Linden Research, Inc.
13 *
14 * Second Life Viewer Source Code
15 * The source code in this file ("Source Code") is provided by Linden Lab
16 * to you under the terms of the GNU General Public License, version 2.0
17 * ("GPL"), unless you have obtained a separate licensing agreement
18 * ("Other License"), formally executed by you and Linden Lab. Terms of
19 * the GPL can be found in doc/GPL-license.txt in this distribution, or
20 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
21 *
22 * There are special exceptions to the terms and conditions of the GPL as
23 * it is applied to this Source Code. View the full text of the exception
24 * in the file doc/FLOSS-exception.txt in this software distribution, or
25 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
26 *
27 * By copying, modifying or distributing this software, you acknowledge
28 * that you have read and understood your obligations described above,
29 * and agree to abide by those obligations.
30 *
31 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
32 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
33 * COMPLETENESS OR PERFORMANCE.
34 * $/LicenseInfo$
35 */
36
37#ifndef LL_LLGLRENDER_H
38#define LL_LLGLRENDER_H
39
40#include "stdtypes.h"
41#include "llgltypes.h"
42#include "llglheaders.h"
43#include "llvertexbuffer.h"
44
45class LLTexUnit
46{
47public:
48 typedef enum
49 {
50 TB_REPLACE = 0,
51 TB_ADD,
52 TB_MULT,
53 TB_MULT_X2,
54 TB_ALPHA_BLEND,
55 TB_COMBINE // Doesn't need to be set directly, setTexture___Blend() set TB_COMBINE automatically
56 } eTextureBlendType;
57
58 typedef enum
59 {
60 TBO_REPLACE = 0, // Use Source 1
61 TBO_MULT, // Multiply: ( Source1 * Source2 )
62 TBO_MULT_X2, // Multiply then scale by 2: ( 2.0 * ( Source1 * Source2 ) )
63 TBO_MULT_X4, // Multiply then scale by 4: ( 4.0 * ( Source1 * Source2 ) )
64 TBO_ADD, // Add: ( Source1 + Source2 )
65 TBO_ADD_SIGNED, // Add then subtract 0.5: ( ( Source1 + Source2 ) - 0.5 )
66 TBO_SUBTRACT, // Subtract Source2 from Source1: ( Source1 - Source2 )
67 TBO_LERP_VERT_ALPHA, // Interpolate based on Vertex Alpha (VA): ( Source1 * VA + Source2 * (1-VA) )
68 TBO_LERP_TEX_ALPHA, // Interpolate based on Texture Alpha (TA): ( Source1 * TA + Source2 * (1-TA) )
69 TBO_LERP_PREV_ALPHA, // Interpolate based on Previous Alpha (PA): ( Source1 * PA + Source2 * (1-PA) )
70 TBO_LERP_CONST_ALPHA, // Interpolate based on Const Alpha (CA): ( Source1 * CA + Source2 * (1-CA) )
71 TBO_LERP_VERT_COLOR // Interpolate based on Vertex Col (VC): ( Source1 * VC + Source2 * (1-VC) )
72 // *Note* TBO_LERP_VERTEX_COLOR only works with setTextureColorBlend(),
73 // and falls back to TBO_LERP_VERTEX_ALPHA for setTextureAlphaBlend().
74 } eTextureBlendOp;
75
76 typedef enum
77 {
78 TBS_PREV_COLOR = 0, // Color from the previous texture stage
79 TBS_PREV_ALPHA,
80 TBS_ONE_MINUS_PREV_COLOR,
81 TBS_ONE_MINUS_PREV_ALPHA,
82 TBS_TEX_COLOR, // Color from the texture bound to this stage
83 TBS_TEX_ALPHA,
84 TBS_ONE_MINUS_TEX_COLOR,
85 TBS_ONE_MINUS_TEX_ALPHA,
86 TBS_VERT_COLOR, // The vertex color currently set
87 TBS_VERT_ALPHA,
88 TBS_ONE_MINUS_VERT_COLOR,
89 TBS_ONE_MINUS_VERT_ALPHA,
90 TBS_CONST_COLOR, // The constant color value currently set
91 TBS_CONST_ALPHA,
92 TBS_ONE_MINUS_CONST_COLOR,
93 TBS_ONE_MINUS_CONST_ALPHA
94 } eTextureBlendSrc;
95
96 LLTexUnit(U32 index);
97 U32 getIndex(void);
98
99 void enable(void);
100 void disable(void);
101 void activate(void);
102
103 void bindTexture(const LLImageGL* texture);
104 void unbindTexture(void);
105
106 void setTextureBlendType(eTextureBlendType type);
107
108 inline void setTextureColorBlend(eTextureBlendOp op, eTextureBlendSrc src1, eTextureBlendSrc src2 = TBS_PREV_COLOR)
109 { setTextureCombiner(op, src1, src2, false); }
110
111 // NOTE: If *_COLOR enums are passed to src1 or src2, the corresponding *_ALPHA enum will be used instead.
112 inline void setTextureAlphaBlend(eTextureBlendOp op, eTextureBlendSrc src1, eTextureBlendSrc src2 = TBS_PREV_ALPHA)
113 { setTextureCombiner(op, src1, src2, true); }
114
115private:
116 U32 mIndex;
117 bool mIsEnabled;
118 eTextureBlendType mCurrBlendType;
119 eTextureBlendOp mCurrColorOp;
120 eTextureBlendSrc mCurrColorSrc1;
121 eTextureBlendSrc mCurrColorSrc2;
122 eTextureBlendOp mCurrAlphaOp;
123 eTextureBlendSrc mCurrAlphaSrc1;
124 eTextureBlendSrc mCurrAlphaSrc2;
125 S32 mCurrColorScale;
126 S32 mCurrAlphaScale;
127
128 void debugTextureUnit(void);
129 void setColorScale(S32 scale);
130 void setAlphaScale(S32 scale);
131 GLint getTextureSource(eTextureBlendSrc src);
132 GLint getTextureSourceType(eTextureBlendSrc src, bool isAlpha = false);
133 void setTextureCombiner(eTextureBlendOp op, eTextureBlendSrc src1, eTextureBlendSrc src2, bool isAlpha = false);
134};
135
136class LLRender
137{
138 friend class LLTexUnit;
139public:
140 typedef enum
141 {
142 CF_NEVER = 0,
143 CF_ALWAYS,
144 CF_LESS,
145 CF_LESS_EQUAL,
146 CF_EQUAL,
147 CF_NOT_EQUAL,
148 CF_GREATER_EQUAL,
149 CF_GREATER,
150 CF_DEFAULT
151 } eCompareFunc;
152
153 typedef enum
154 {
155 BT_ALPHA = 0,
156 BT_ADD,
157 BT_ADD_WITH_ALPHA, // Additive blend modulated by the fragment's alpha.
158 BT_MULT,
159 BT_MULT_X2,
160 BT_REPLACE
161 } eBlendType;
162
163 typedef enum
164 {
165 BF_ONE = 0,
166 BF_ZERO,
167 BF_DEST_COLOR,
168 BF_SOURCE_COLOR,
169 BF_ONE_MINUS_DEST_COLOR,
170 BF_ONE_MINUS_SOURCE_COLOR,
171 BF_DEST_ALPHA,
172 BF_SOURCE_ALPHA,
173 BF_ONE_MINUS_DEST_ALPHA,
174 BF_ONE_MINUS_SOURCE_ALPHA
175 } eBlendFactor;
176
177 LLRender();
178 ~LLRender();
179
180 void translatef(const GLfloat& x, const GLfloat& y, const GLfloat& z);
181 void pushMatrix();
182 void popMatrix();
183
184 void flush();
185
186 void begin(const GLuint& mode);
187 void end();
188 void vertex2i(const GLint& x, const GLint& y);
189 void vertex2f(const GLfloat& x, const GLfloat& y);
190 void vertex3f(const GLfloat& x, const GLfloat& y, const GLfloat& z);
191 void vertex2fv(const GLfloat* v);
192 void vertex3fv(const GLfloat* v);
193
194 void texCoord2i(const GLint& x, const GLint& y);
195 void texCoord2f(const GLfloat& x, const GLfloat& y);
196 void texCoord2fv(const GLfloat* tc);
197
198 void color4ub(const GLubyte& r, const GLubyte& g, const GLubyte& b, const GLubyte& a);
199 void color4f(const GLfloat& r, const GLfloat& g, const GLfloat& b, const GLfloat& a);
200 void color4fv(const GLfloat* c);
201 void color3f(const GLfloat& r, const GLfloat& g, const GLfloat& b);
202 void color3fv(const GLfloat* c);
203 void color4ubv(const GLubyte* c);
204
205 void setColorMask(bool writeColor, bool writeAlpha);
206 void setColorMask(bool writeColorR, bool writeColorG, bool writeColorB, bool writeAlpha);
207 void setSceneBlendType(eBlendType type);
208
209 void setAlphaRejectSettings(eCompareFunc func, F32 value = 0.01f);
210
211 void blendFunc(eBlendFactor sfactor, eBlendFactor dfactor);
212
213 LLTexUnit* getTexUnit(U32 index);
214
215 typedef struct Vertex
216 {
217 GLfloat v[3];
218 GLubyte c[4];
219 GLfloat uv[2];
220 };
221
222public:
223
224private:
225 U32 mCount;
226 U32 mMode;
227 U32 mCurrTextureUnitIndex;
228 LLPointer<LLVertexBuffer> mBuffer;
229 LLStrider<LLVector3> mVerticesp;
230 LLStrider<LLVector2> mTexcoordsp;
231 LLStrider<LLColor4U> mColorsp;
232 std::vector<LLTexUnit*> mTexUnits;
233};
234
235
236
237extern LLRender gGL;
238
239#endif