Skip to content

Commit d68f415

Browse files
committed
Thick Lines and Varying Point Sizes for Programmable Renderer
1 parent dee2eb7 commit d68f415

14 files changed

+1248
-82
lines changed

libs/openFrameworks/app/ofAppNoWindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class ofNoopRenderer: public ofBaseRenderer{
147147
void setFillMode(ofFillFlag fill){}
148148
ofFillFlag getFillMode(){return OF_FILLED;}
149149
void setLineWidth(float lineWidth){}
150+
void setPointSize(float pointSize) {}
150151
void setBlendMode(ofBlendMode blendMode){}
151152
void setLineSmoothing(bool smooth){}
152153
void setCircleResolution(int res){};

libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp

Lines changed: 1116 additions & 71 deletions
Large diffs are not rendered by default.

libs/openFrameworks/gl/ofGLProgrammableRenderer.h

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,21 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
124124
void setRectMode(ofRectMode mode);
125125
ofRectMode getRectMode();
126126
void setLineWidth(float lineWidth);
127+
void setPointSize(float pointSize);
127128
void setDepthTest(bool depthTest);
128129
void setLineSmoothing(bool smooth);
129130
void setBlendMode(ofBlendMode blendMode);
130131
void enablePointSprites();
131132
void disablePointSprites();
132133
void enableAntiAliasing();
133134
void disableAntiAliasing();
135+
136+
// lines
137+
void enableLineSizeAttenuation();
138+
void disableLineSizeAttenuation();
139+
void enableLinesShaders();
140+
void disableLinesShaders();
141+
bool areLinesShadersEnabled() const;
134142

135143
// color options
136144
void setColor(float r, float g, float b); // 0-1
@@ -250,6 +258,43 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
250258
mutable ofMesh rectMesh;
251259
mutable ofMesh lineMesh;
252260
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+
};
253298

254299
void uploadCurrentMatrix();
255300

@@ -258,12 +303,20 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
258303
void endSmoothing();
259304

260305
void beginDefaultShader();
306+
std::shared_ptr<ShaderCollection>& getShaderCollectionForMode(GLuint drawMode);
261307
void uploadMatrices();
262308
void setDefaultUniforms();
263309

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);
265313
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+
267320

268321
ofMatrixStack matrixStack;
269322

@@ -273,6 +326,7 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
273326
const ofShader * currentShader;
274327

275328
bool verticesEnabled, colorsEnabled, texCoordsEnabled, normalsEnabled, bitmapStringEnabled;
329+
bool pointSpritesEnabled;
276330
bool usingCustomShader, settingDefaultShader, usingVideoShader;
277331
int currentTextureTarget;
278332

@@ -293,13 +347,23 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
293347
ofBitmapFont bitmapFont;
294348
ofPath path;
295349
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;
303367
ofShader defaultUniqueShader;
304368
#ifdef TARGET_ANDROID
305369
ofShader defaultOESTexColor;

libs/openFrameworks/gl/ofGLRenderer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,12 @@ void ofGLRenderer::setLineWidth(float lineWidth) {
12021202
glLineWidth(lineWidth);
12031203
}
12041204

1205+
//----------------------------------------------------------
1206+
void ofGLRenderer::setPointSize(float pointSize) {
1207+
currentStyle.pointSize = pointSize;
1208+
glPointSize(pointSize);
1209+
}
1210+
12051211
//----------------------------------------------------------
12061212
void ofGLRenderer::setDepthTest(bool depthTest) {
12071213
if (depthTest) {

libs/openFrameworks/gl/ofGLRenderer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class ofGLRenderer: public ofBaseGLRenderer{
111111
void setRectMode(ofRectMode mode);
112112
ofRectMode getRectMode();
113113
void setLineWidth(float lineWidth);
114+
void setPointSize(float pointSize);
114115
void setDepthTest(bool depthTest);
115116
void setLineSmoothing(bool smooth);
116117
void setBlendMode(ofBlendMode blendMode);

libs/openFrameworks/gl/ofShader.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,10 +954,19 @@ void ofShader::setUniformTexture(const string & name, int textureTarget, GLint t
954954
}
955955
}
956956

957+
957958
//--------------------------------------------------------------
958959
void ofShader::setUniformTexture(const string & name, const ofTexture & tex, int textureLocation) const {
960+
if (bLoaded) {
961+
ofTextureData texData = tex.getTextureData();
962+
setUniformTexture( name, texData, textureLocation);
963+
}
964+
}
965+
966+
//--------------------------------------------------------------
967+
void ofShader::setUniformTexture(const string & name, const ofTextureData & texData, int textureLocation) const{
959968
if (bLoaded) {
960-
ofTextureData texData = tex.getTextureData();
969+
//ofTextureData texData = tex.getTextureData();
961970
glActiveTexture(GL_TEXTURE0 + textureLocation);
962971
if (!ofIsGLProgrammableRenderer()) {
963972
glEnable(texData.textureTarget);

libs/openFrameworks/gl/ofShader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <unordered_map>
1818

1919
class ofTexture;
20+
class ofTextureData;
2021
class ofMatrix3x3;
2122
class ofParameterGroup;
2223
class ofBufferObject;
@@ -150,6 +151,7 @@ class ofShader {
150151
void setUniformTexture(const std::string & name, const ofBaseHasTexture& img, int textureLocation) const;
151152
void setUniformTexture(const std::string & name, const ofTexture& img, int textureLocation) const;
152153
void setUniformTexture(const std::string & name, int textureTarget, GLint textureID, int textureLocation) const;
154+
void setUniformTexture(const std::string & name, const ofTextureData& texData, int textureLocation) const;
153155

154156
// set a single uniform value
155157
void setUniform1i(const std::string & name, int v1) const;

libs/openFrameworks/graphics/ofCairoRenderer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,12 @@ void ofCairoRenderer::setLineWidth(float lineWidth) {
655655
cairo_set_line_width(cr, lineWidth);
656656
}
657657

658+
//--------------------------------------------
659+
void ofCairoRenderer::setPointSize(float pointSize) {
660+
currentStyle.pointSize = pointSize;
661+
// no point size for cairo
662+
}
663+
658664
//----------------------------------------------------------
659665
void ofCairoRenderer::setDepthTest(bool depthTest) {
660666
// cairo does not do any depth testing

libs/openFrameworks/graphics/ofCairoRenderer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class ofCairoRenderer: public ofBaseRenderer{
8383
void setFillMode(ofFillFlag fill);
8484
ofFillFlag getFillMode();
8585
void setLineWidth(float lineWidth);
86+
void setPointSize(float pointSize);
8687
void setDepthTest(bool depthTest);
8788
void setBlendMode(ofBlendMode blendMode);
8889
void setLineSmoothing(bool smooth);

libs/openFrameworks/graphics/ofGraphics.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,11 @@ void ofSetLineWidth(float lineWidth) {
528528
ofGetCurrentRenderer()->setLineWidth(lineWidth);
529529
}
530530

531+
//----------------------------------------------------------
532+
void ofSetPointSize(float pointSize) {
533+
ofGetCurrentRenderer()->setPointSize(pointSize);
534+
}
535+
531536
//----------------------------------------------------------
532537
void ofSetDepthTest(bool depthTest) {
533538
ofGetCurrentRenderer()->setDepthTest(depthTest);

0 commit comments

Comments
 (0)