Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oftexture addition #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/ofxShadersFX_DisplaceMapShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ class DisplaceMapShader : public MappingShader {

void setColormap(ofImage * p_colormap) { setImage(p_colormap, 0); }
void setColormap(const string & p_colormapPath) { setImage(p_colormapPath, 0); }
void setColorMap( ofTexture * p_colormap ) { setTexture( p_colormap, 0 ); }
void setDisplaceMap(ofImage * p_displacemap) { setImage(p_displacemap, 1); }
void setDisplaceMap(const string & p_displacemapPath) { setImage(p_displacemapPath, 1); }
void setDisplaceMap( ofTexture * p_displacemapPath ) { setTexture( p_displacemapPath, 1 ); }
void setMaximumHeight(float p_height) { m_maxHeight = p_height; }
void setNormalMatrix(const ofMatrix4x4 & p_mat) { m_normalMatrix = p_mat; }

Expand Down
3 changes: 2 additions & 1 deletion src/ofxShadersFX_LightingShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ void LightingShader::setupProgrammableRendererLights() {
}

const GLchar **glnames_ptr = &glnames[0];
GLuint indices[glnames.size()];
GLuint * indices = new GLuint[glnames.size()];

glGetUniformIndices(m_shader.getProgram(), glnames.size(), glnames_ptr, indices);

Expand Down Expand Up @@ -420,6 +420,7 @@ vector<string> LightingShader::generateLightPropsNames()
names.push_back(string("Lights.light[") + lightNumber + string(props[s]));
}
}

return names;
}

Expand Down
45 changes: 43 additions & 2 deletions src/ofxShadersFX_MappingShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ void MappingShader::begin() {
m_imgs[i]->bind();
}
}

for( unsigned int i = 0; i < m_texs.size(); ++i ) {
if( m_texs[ i ] != NULL ) {
stringstream number( "" );
number << i;

m_shader.setUniformTexture( string( "tex" ) + number.str(), ( *m_texs[ i ] ), i + 1 );
m_texs[ i ]->bind();
}
}
}


Expand All @@ -36,6 +46,12 @@ void MappingShader::end() {
m_imgs[i]->unbind();
}
}

for( unsigned int i = 0; i < m_texs.size(); ++i ) {
if( m_texs[ i ] != NULL ) {
m_texs[ i ]->unbind();
}
}
}


Expand Down Expand Up @@ -68,8 +84,13 @@ void MappingShader::freeAllocatedImages() {

delete m_imgs[imgIdxToDelete];
}
}

for( unsigned int i = 0; i < m_textureIndicesToDelete.size(); ++i ) {
const int imgIdxToDelete = m_textureIndicesToDelete[ i ];

delete m_texs[ imgIdxToDelete ];
}
}

void MappingShader::rearrangeLists(ofImage * p_img, int p_index) {
m_imgs.insert(m_imgs.begin() + p_index, p_img);
Expand Down Expand Up @@ -131,7 +152,27 @@ void MappingShader::setImage(const string & p_imgPath, int p_index) {
}


void MappingShader::setImages(const vector<ofImage *> & p_imgs) {
void MappingShader::setTexture( ofTexture * p_tex, int p_index )
{
// Delete the image at target index if it was allocated.
vector<int>::iterator idxToDelete = find( m_textureIndicesToDelete.begin(), m_textureIndicesToDelete.end(), p_index );

if( idxToDelete != m_textureIndicesToDelete.end() ) {
delete m_texs[ ( *idxToDelete ) ];
m_textureIndicesToDelete.erase( idxToDelete ); // image at this index is no longer allocated
}

// Replace image in place if vector is already large enough.
const int nbImgs = static_cast< int >( m_texs.size() );
if( p_index < nbImgs ) {
m_texs[ p_index ] = p_tex;
}
else {
m_texs.push_back( p_tex );
}
}

void MappingShader::setImages( const vector<ofImage *> & p_imgs ) {
freeAllocatedImages();
m_imgs = p_imgs;
}
Expand Down
7 changes: 5 additions & 2 deletions src/ofxShadersFX_MappingShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ class MappingShader : public Shader

void setImage(ofImage * p_img, int p_index);
void setImage(const string & p_imgPath, int p_index);
void setImage(ofTexture * p_tex, int p_index);
void setTexture( ofTexture * p_tex, int p_index );
void setImages(const vector<ofImage *> & p_imgs);

void clearMaps() { m_imgs.clear(); }
void clearMaps() { m_imgs.clear(); m_texs.clear(); }

// Attributes

vector<ofImage *> m_imgs;
vector< ofTexture * >m_texs;

private:
// Mutators
Expand All @@ -61,7 +64,7 @@ class MappingShader : public Shader

// To track if stored ofImages have been allocated by addon or user
// (we must not delete user-allocated images)
vector<int> m_indicesToDelete;
vector<int> m_indicesToDelete, m_textureIndicesToDelete;
MappingMethod m_method;

static const size_t SHADERS_TYPES = 3; // Number of different shaders types implemented
Expand Down