Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
360 changes: 171 additions & 189 deletions libs/openFrameworks/app/ofAppNoWindow.cpp

Large diffs are not rendered by default.

2,020 changes: 988 additions & 1,032 deletions libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp

Large diffs are not rendered by default.

180 changes: 86 additions & 94 deletions libs/openFrameworks/gl/ofGLProgrammableRenderer.h
Original file line number Diff line number Diff line change
@@ -1,63 +1,61 @@
#pragma once

#include "ofGLBaseTypes.h"
#include "ofPolyline.h"
#include "ofShader.h"
#include "ofMatrixStack.h"
#include "of3dGraphics.h"
#include "ofBitmapFont.h"
#include "ofGLBaseTypes.h"
#include "ofMatrixStack.h"
#include "ofPath.h"
#include "ofPolyline.h"
#include "ofShader.h"
//#include "ofMaterialBaseTypes.h"

class ofShapeTessellation;
class ofFbo;
class ofVbo;
static const int OF_NO_TEXTURE=-1;
static const int OF_NO_TEXTURE = -1;

class ofGLProgrammableRenderer: public ofBaseGLRenderer{
class ofGLProgrammableRenderer : public ofBaseGLRenderer {
public:
ofGLProgrammableRenderer(const ofAppBaseWindow * window);
ofGLProgrammableRenderer(const ofAppBaseWindow * window);

void setup(int glVersionMajor, int glVersionMinor);

static const std::string TYPE;
const std::string & getType(){ return TYPE; }
void startRender();
void finishRender();
static const std::string TYPE;
const std::string & getType() { return TYPE; }

void startRender();
void finishRender();

using ofBaseRenderer::draw;
using ofBaseGLRenderer::draw;
using ofBaseRenderer::draw;
void draw(const ofMesh & vertexData, ofPolyRenderMode renderType, bool useColors, bool useTextures, bool useNormals) const;
void draw(const of3dPrimitive& model, ofPolyRenderMode renderType) const;
void draw(const ofNode& node) const;
void draw(const of3dPrimitive & model, ofPolyRenderMode renderType) const;
void draw(const ofNode & node) const;
void draw(const ofPolyline & poly) const;
void draw(const ofPath & path) const;
void draw(const ofImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const;
void draw(const ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const;
void draw(const ofShortImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const;
void draw(const ofTexture & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const;
void draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const;
void draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const;
void draw(const ofVbo & vbo, GLuint drawMode, int first, int total) const;
void drawElements(const ofVbo & vbo, GLuint drawMode, int amt, int offsetelements = 0) const;
void drawInstanced(const ofVbo & vbo, GLuint drawMode, int first, int total, int primCount) const;
void drawElementsInstanced(const ofVbo & vbo, GLuint drawMode, int amt, int primCount) const;
void draw(const ofVboMesh & mesh, ofPolyRenderMode renderType) const;
void drawInstanced(const ofVboMesh & mesh, ofPolyRenderMode renderType, int primCount) const;
ofPath & getPath();



ofPath & getPath();

//--------------------------------------------
// transformations
void pushView();
void popView();
void popView();

// setup matrices and viewport (upto you to push and pop view before and after)
// if width or height are 0, assume windows dimensions (ofGetWidth(), ofGetHeight())
// if nearDist or farDist are 0 assume defaults (calculated based on width / height)
void viewport(ofRectangle viewport);
void viewport(float x = 0, float y = 0, float width = -1, float height = -1, bool vflip=true);
void viewport(float x = 0, float y = 0, float width = -1, float height = -1, bool vflip = true);
void setupScreenPerspective(float width = -1, float height = -1, float fov = 60, float nearDist = 0, float farDist = 0);
void setupScreenOrtho(float width = -1, float height = -1, float nearDist = -1, float farDist = 1);
void setOrientation(ofOrientation orientation, bool vFlip);
Expand All @@ -66,10 +64,10 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
int getViewportWidth() const;
int getViewportHeight() const;
bool isVFlipped() const;

void setCoordHandedness(ofHandednessType handedness);
ofHandednessType getCoordHandedness() const;

//our openGL wrappers
void pushMatrix();
void popMatrix();
Expand All @@ -82,41 +80,41 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
void rotateZRad(float radians);
void rotateRad(float radians);
void matrixMode(ofMatrixMode mode);
void loadIdentityMatrix (void);
void loadMatrix (const glm::mat4 & m);
void loadMatrix (const float * m);
void multMatrix (const glm::mat4 & m);
void multMatrix (const float * m);
void loadIdentityMatrix(void);
void loadMatrix(const glm::mat4 & m);
void loadMatrix(const float * m);
void multMatrix(const glm::mat4 & m);
void multMatrix(const float * m);
void loadViewMatrix(const glm::mat4 & m);
void multViewMatrix(const glm::mat4 & m);

/// \brief Queries the current OpenGL matrix state
///
/// Returns the specified matrix as held by the renderer's current matrix
/// stack.
///
/// You can query one of the following:
///
/// [OF_MATRIX_MODELVIEW | OF_MATRIX_PROJECTION | OF_MATRIX_TEXTURE]
///
/// Each query will return the state of the matrix as it was uploaded to
/// the shader currently bound.
///
/// \param matrixMode_ Which matrix mode to query
/// \note If an invalid matrixMode is queried, this method will return the
/// identity matrix, and print an error message.
/// \brief Queries the current OpenGL matrix state
///
/// Returns the specified matrix as held by the renderer's current matrix
/// stack.
///
/// You can query one of the following:
///
/// [OF_MATRIX_MODELVIEW | OF_MATRIX_PROJECTION | OF_MATRIX_TEXTURE]
///
/// Each query will return the state of the matrix as it was uploaded to
/// the shader currently bound.
///
/// \param matrixMode_ Which matrix mode to query
/// \note If an invalid matrixMode is queried, this method will return the
/// identity matrix, and print an error message.
glm::mat4 getCurrentMatrix(ofMatrixMode matrixMode_) const;
glm::mat4 getCurrentOrientationMatrix() const;
glm::mat4 getCurrentViewMatrix() const;
glm::mat4 getCurrentNormalMatrix() const;
glm::mat4 getCurrentModelMatrix() const;

glm::vec3 getCurrentEyePosition() const;

// screen coordinate things / default gl values
void setupGraphicDefaults();
void setupScreen();

// drawing modes
void setFillMode(ofFillFlag fill);
ofFillFlag getFillMode();
Expand All @@ -131,34 +129,33 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
void disablePointSprites();
void enableAntiAliasing();
void disableAntiAliasing();

// color options
void setColor(float r, float g, float b); // 0-1
void setColor(float r, float g, float b, float a); // 0-1
void setColor(const ofFloatColor & color);
void setColor(const ofFloatColor & color, float _a);
void setColor(float gray); // new set a color as grayscale with one argument
void setHexColor( int hexColor ); // hex, like web 0xFF0033;
void setHexColor(int hexColor); // hex, like web 0xFF0033;

void setBitmapTextMode(ofBitmapMode mode);

void setBitmapTextMode(ofDrawBitmapMode mode);

// bg color
ofFloatColor getBackgroundColor();
void setBackgroundColor(const ofFloatColor & c);
void background(const ofFloatColor & c);
void background(float brightness);
void background(int hexColor, int _a=255);
void background(float r, float g, float b, float a=1.f);
void background(int hexColor, int _a = 255);
void background(float r, float g, float b, float a = 1.f);

bool getBackgroundAuto();
void setBackgroundAuto(bool bManual); // default is true
void setBackgroundAuto(bool bManual); // default is true

void clear();
void clear(float r, float g, float b, float a=0.f);
void clear(float brightness, float a=0.f);
void clear(float r, float g, float b, float a = 0.f);
void clear(float brightness, float a = 0.f);
void clearAlpha();



// drawing
void drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const;
void drawRectangle(float x, float y, float z, float w, float h) const;
Expand All @@ -168,7 +165,6 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
void drawString(std::string text, float x, float y, float z) const;
void drawString(const ofTrueTypeFont & font, std::string text, float x, float y) const;


void enableTextureTarget(const ofTexture & tex, int textureLocation);
void disableTextureTarget(int textureTarget, int textureLocation);
void setAlphaMaskTex(const ofTexture & tex);
Expand Down Expand Up @@ -198,7 +194,7 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
#endif
void unbind(const ofFbo & fbo);

void begin(const ofFbo & fbo, ofFboMode mode);
void begin(const ofFbo & fbo, ofFboMode mode);
void end(const ofFbo & fbo);

ofStyle getStyle() const;
Expand All @@ -211,23 +207,23 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
const ofShader * getVideoShader(const ofBaseVideoDraws & video) const;
void setVideoShaderUniforms(const ofBaseVideoDraws & video, const ofShader & shader) const;

void enableLighting();
void disableLighting();
bool getLightingEnabled();
void enableSeparateSpecularLight(){}
void disableSeparateSpecularLight(){}
void setSmoothLighting(bool b){}
void setGlobalAmbientColor(const ofFloatColor& c){}
void enableLight(int lightIndex);
void disableLight(int lightIndex);
void setLightSpotlightCutOff(int lightIndex, float spotCutOff){}
void setLightSpotConcentration(int lightIndex, float exponent){}
void setLightAttenuation(int lightIndex, float constant, float linear, float quadratic ){}
void setLightAmbientColor(int lightIndex, const ofFloatColor& c){}
void setLightDiffuseColor(int lightIndex, const ofFloatColor& c){}
void setLightSpecularColor(int lightIndex, const ofFloatColor& c){}
void setLightPosition(int lightIndex, const glm::vec4 & position){}
void setLightSpotDirection(int lightIndex, const glm::vec4 & direction){}
void enableLighting();
void disableLighting();
bool getLightingEnabled();
void enableSeparateSpecularLight() { }
void disableSeparateSpecularLight() { }
void setSmoothLighting(bool b) { }
void setGlobalAmbientColor(const ofFloatColor & c) { }
void enableLight(int lightIndex);
void disableLight(int lightIndex);
void setLightSpotlightCutOff(int lightIndex, float spotCutOff) { }
void setLightSpotConcentration(int lightIndex, float exponent) { }
void setLightAttenuation(int lightIndex, float constant, float linear, float quadratic) { }
void setLightAmbientColor(int lightIndex, const ofFloatColor & c) { }
void setLightDiffuseColor(int lightIndex, const ofFloatColor & c) { }
void setLightSpecularColor(int lightIndex, const ofFloatColor & c) { }
void setLightPosition(int lightIndex, const glm::vec4 & position) { }
void setLightSpotDirection(int lightIndex, const glm::vec4 & direction) { }

std::string defaultVertexShaderHeader(GLenum textureTarget);
std::string defaultFragmentShaderHeader(GLenum textureTarget);
Expand All @@ -242,8 +238,6 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
of3dGraphics & get3dGraphics();

private:


ofPolyline circlePolyline;
mutable ofMesh circleMesh;
mutable ofMesh triangleMesh;
Expand All @@ -253,7 +247,6 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{

void uploadCurrentMatrix();


void startSmoothing();
void endSmoothing();

Expand All @@ -264,12 +257,11 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
void setAttributes(bool vertices, bool color, bool tex, bool normals);
void setAlphaBitmapText(bool bitmapText);


ofMatrixStack matrixStack;

bool bBackgroundAuto;
int major, minor;

const ofShader * currentShader;

bool verticesEnabled, colorsEnabled, texCoordsEnabled, normalsEnabled, bitmapStringEnabled;
Expand All @@ -281,14 +273,14 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{

const ofBaseMaterial * currentMaterial;
int alphaMaskTextureTarget;
const ofShadow* currentShadow;

const ofShadow * currentShadow;
bool bIsShadowDepthPass;
GLenum shadowCubeFace;
bool bCustomShadowShader = false;

ofStyle currentStyle;
std::deque <ofStyle> styleHistory;
std::deque<ofStyle> styleHistory;
of3dGraphics graphics3d;
ofBitmapFont bitmapFont;
ofPath path;
Expand All @@ -305,12 +297,12 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
ofShader defaultOESTexColor;
ofShader defaultOESTexNoColor;
#endif

ofShader alphaMaskRectShader;
ofShader alphaMask2DShader;

ofShader bitmapStringShader;

ofShader shaderPlanarYUY2;
ofShader shaderNV12;
ofShader shaderNV21;
Expand All @@ -319,7 +311,7 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
ofShader shaderNV12Rect;
ofShader shaderNV21Rect;
ofShader shaderPlanarYUVRect;

glm::vec3 currentEyePos;

//void setDefaultFramebufferId(const GLuint& fboId_); ///< windowing systems might use this to set the default framebuffer for this renderer.
Expand All @@ -330,7 +322,7 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{
//void setFramebufferId(const GLuint& fboId_); // sets the current framebuffer id

// framebuffer binding state
std::deque<GLuint> framebufferIdStack; ///< keeps track of currently bound framebuffers
GLuint defaultFramebufferId; ///< default GL_FRAMEBUFFER_BINDING, windowing frameworks might want to set this to their MSAA framebuffer, defaults to 0
GLuint currentFramebufferId; ///< the framebuffer id currently bound to the GL_FRAMEBUFFER target
std::deque<GLuint> framebufferIdStack; ///< keeps track of currently bound framebuffers
GLuint defaultFramebufferId; ///< default GL_FRAMEBUFFER_BINDING, windowing frameworks might want to set this to their MSAA framebuffer, defaults to 0
GLuint currentFramebufferId; ///< the framebuffer id currently bound to the GL_FRAMEBUFFER target
};
Loading