@@ -124,13 +124,21 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
124
124
void setRectMode (ofRectMode mode);
125
125
ofRectMode getRectMode ();
126
126
void setLineWidth (float lineWidth);
127
+ void setPointSize (float pointSize);
127
128
void setDepthTest (bool depthTest);
128
129
void setLineSmoothing (bool smooth);
129
130
void setBlendMode (ofBlendMode blendMode);
130
131
void enablePointSprites ();
131
132
void disablePointSprites ();
132
133
void enableAntiAliasing ();
133
134
void disableAntiAliasing ();
135
+
136
+ // lines
137
+ void enableLineSizeAttenuation ();
138
+ void disableLineSizeAttenuation ();
139
+ void enableLinesShaders ();
140
+ void disableLinesShaders ();
141
+ bool areLinesShadersEnabled () const ;
134
142
135
143
// color options
136
144
void setColor (float r, float g, float b); // 0-1
@@ -250,6 +258,43 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
250
258
mutable ofMesh rectMesh;
251
259
mutable ofMesh lineMesh;
252
260
mutable ofVbo meshVbo;
261
+ mutable ofMesh polylineMesh;
262
+
263
+ // when adding more draw modes, POINTS, LINES, etc.
264
+ // store in a structure so we don't have to make a lot of variables
265
+ // this structure if based on the one from ofMaterial
266
+ class ShaderCollection {
267
+ public:
268
+ void bindAttribute ( GLuint location, const std::string & name );
269
+ void bindDefaults ();
270
+ void linkPrograms ();
271
+ void setupAllVertexShaders (const std::string &aShaderSrc);
272
+
273
+ ofShader texRectColor;
274
+ ofShader texRectNoColor;
275
+ ofShader tex2DColor;
276
+ ofShader tex2DNoColor;
277
+ ofShader noTexColor;
278
+ ofShader noTexNoColor;
279
+ };
280
+
281
+ // useful for lines //
282
+ class LinesBundle {
283
+ public:
284
+ std::vector<glm::vec4> lineMeshNextVerts;
285
+ std::vector<glm::vec4> lineMeshPrevVerts;
286
+ ofVboMesh vboMesh;
287
+ int vertAttribPrev = 4 ;
288
+ int vertAttribNext = 5 ;
289
+ };
290
+
291
+ struct TextureUniform {
292
+ ofTextureData texData;
293
+ // not going to store a texture since we don't want to retain the texture here
294
+ // ofTexture texture;
295
+ int textureLocation;
296
+ std::string uniformName;
297
+ };
253
298
254
299
void uploadCurrentMatrix ();
255
300
@@ -258,12 +303,20 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
258
303
void endSmoothing ();
259
304
260
305
void beginDefaultShader ();
306
+ std::shared_ptr<ShaderCollection>& getShaderCollectionForMode (GLuint drawMode);
261
307
void uploadMatrices ();
262
308
void setDefaultUniforms ();
263
309
264
- void setAttributes (bool vertices, bool color, bool tex, bool normals);
310
+ // adding a drawMode variable that will switch shaders based on GL_TRIANGLES, GL_POINTS or GL_LINES
311
+ void setAttributes (bool vertices, bool color, bool tex, bool normals, GLuint drawMode);
312
+ // void setAttributes(bool vertices, bool color, bool tex, bool normals);
265
313
void setAlphaBitmapText (bool bitmapText);
266
-
314
+
315
+
316
+ // LINES
317
+ void configureMeshToMatchWithNewVertsAndIndices (const ofMesh& aSrcMesh, ofVboMesh& aDstMesh, std::size_t aTargetNumVertices, std::size_t aTargetNumIndices);
318
+ void configureLinesBundleFromMesh (LinesBundle& aLinesBundle, GLuint drawMode, const ofMesh& amesh);
319
+
267
320
268
321
ofMatrixStack matrixStack;
269
322
@@ -273,6 +326,7 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
273
326
const ofShader * currentShader;
274
327
275
328
bool verticesEnabled, colorsEnabled, texCoordsEnabled, normalsEnabled, bitmapStringEnabled;
329
+ bool pointSpritesEnabled;
276
330
bool usingCustomShader, settingDefaultShader, usingVideoShader;
277
331
int currentTextureTarget;
278
332
@@ -293,13 +347,23 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
293
347
ofBitmapFont bitmapFont;
294
348
ofPath path;
295
349
const ofAppBaseWindow * window;
296
-
297
- ofShader defaultTexRectColor;
298
- ofShader defaultTexRectNoColor;
299
- ofShader defaultTex2DColor;
300
- ofShader defaultTex2DNoColor;
301
- ofShader defaultNoTexColor;
302
- ofShader defaultNoTexNoColor;
350
+
351
+ mutable GLuint mDrawMode = GL_TRIANGLES;
352
+ std::unordered_map<GLuint, LinesBundle> mLinesBundleMap ;
353
+ mutable bool mBRenderingLines = false ;
354
+ mutable bool mBLineSizeAttenutation = false ; // screen space
355
+ mutable bool mBEnableLinesShaders = true ;
356
+
357
+ // the index GL_TRIANGLES store everything that is not GL_POINTS or GL_LINES, GL_LINE_STRIP
358
+ std::unordered_map<GLuint, std::shared_ptr<ShaderCollection> > mDefaultShadersMap ;
359
+ std::vector<TextureUniform> mUniformsTex ;
360
+
361
+ // ofShader defaultTexRectColor;
362
+ // ofShader defaultTexRectNoColor;
363
+ // ofShader defaultTex2DColor;
364
+ // ofShader defaultTex2DNoColor;
365
+ // ofShader defaultNoTexColor;
366
+ // ofShader defaultNoTexNoColor;
303
367
ofShader defaultUniqueShader;
304
368
#ifdef TARGET_ANDROID
305
369
ofShader defaultOESTexColor;
0 commit comments