Commit 145e7e94 authored by zmoelnig's avatar zmoelnig
Browse files

using GemState accessors

git-svn-id: https://pd-gem.svn.sourceforge.net/svnroot/pd-gem/trunk/Gem@3663 49b2a0ca-c541-4d49-a7ef-d785e4371512
parent d1ed965c
......@@ -47,13 +47,16 @@ pix_buf :: ~pix_buf()
/////////////////////////////////////////////////////////
void pix_buf :: render(GemState *state)
{
if(!state)return;
bool doit=m_banged;
pixBlock*img=NULL;
state->get("pix", img);
cachedPixBlock.newimage = 0;
if (!state || !state->image || !&state->image->image) return;
if (!img || !&img->image) return;
doit|=m_auto;
doit|=state->image->newimage;
doit|=img->newimage;
//
if (m_cache&&m_cache->resendImage)
......@@ -62,11 +65,11 @@ void pix_buf :: render(GemState *state)
}
if (doit){
orgPixBlock = state->image;
state->image->image.copy2Image(&cachedPixBlock.image);
orgPixBlock = img;
img->image.copy2Image(&cachedPixBlock.image);
cachedPixBlock.newimage = 1;
}
state->image = &cachedPixBlock;
img = &cachedPixBlock;
m_banged = false;
}
......@@ -76,7 +79,7 @@ void pix_buf :: render(GemState *state)
/////////////////////////////////////////////////////////
void pix_buf :: postrender(GemState *state)
{
state->image = orgPixBlock;
state->set("pix", orgPixBlock);
}
/////////////////////////////////////////////////////////
......
......@@ -158,7 +158,7 @@ void pix_buffer_read :: render(GemState*state)
if (!m_haveImage) return;
/* push the incoming state->image into a temporary memory */
orgPixBlock = state->image;
state->get("pix", orgPixBlock);
/*
pd_findbyclass costs at least 2 if's
......@@ -168,7 +168,7 @@ void pix_buffer_read :: render(GemState*state)
*/
if (NULL==pd_findbyclass(m_bindname, pix_buffer_class)) return;
state->image = &m_pixBlock;
state->set("pix", &m_pixBlock);
}
......@@ -187,7 +187,7 @@ void pix_buffer_read :: postrender(GemState *state)
}
/* restore the original incoming image */
state->image = orgPixBlock;
state->set("pix", orgPixBlock);
}
/////////////////////////////////////////////////////////
......
......@@ -79,8 +79,11 @@ void pix_buffer_write :: frameMess(int f){
/////////////////////////////////////////////////////////
void pix_buffer_write :: render(GemState*state){
if (m_frame<0)return;
if (state && state->image && &state->image->image){
if (state->image->newimage || m_frame!=m_lastframe){
if(!state)return;
pixBlock*img=NULL;
state->get("pix", img);
if (state && img && &img->image){
if (img->newimage || m_frame!=m_lastframe){
if(m_bindname==NULL || m_bindname->s_name==NULL){
error("cowardly refusing to write to no pix_buffer");
m_frame=-1; return;
......@@ -92,7 +95,7 @@ void pix_buffer_write :: render(GemState*state){
}
pix_buffer *buffer=(pix_buffer *)(ohead)->data;
if (buffer){
buffer->putMess(&state->image->image,m_lastframe=m_frame);
buffer->putMess(&img->image,m_lastframe=m_frame);
m_frame=-1;
}
}
......
......@@ -55,7 +55,7 @@ void pix_clearblock :: render(GemState *state)
startRendering(); // i'm not sure, whether this breaks the default behaviour
return;
}
state->image = NULL;
state->set("pix", static_cast<pixBlock*>(NULL));
}
/////////////////////////////////////////////////////////
......@@ -64,7 +64,8 @@ void pix_clearblock :: render(GemState *state)
/////////////////////////////////////////////////////////
void pix_clearblock :: postrender(GemState *state)
{
state->image = NULL;
#warning shant we reset to the original image?
state->set("pix", static_cast<pixBlock*>(NULL));
}
/////////////////////////////////////////////////////////
......
......@@ -53,28 +53,32 @@ pix_coordinate :: ~pix_coordinate()
/////////////////////////////////////////////////////////
void pix_coordinate :: render(GemState *state)
{
m_oldTexCoords=state->texCoords;
m_oldNumCoords=state->numTexCoords;
pixBlock*img=NULL;
state->get("pix", img);
if (state->texture && m_numCoords){
state->numTexCoords = m_numCoords;
state->get("gl.tex.coords", m_oldTexCoords);
state->get("gl.tex.numcoords", m_oldNumCoords);
state->set("gl.tex.type", m_oldTexType);
if(state->texture==2 && state->image!=NULL){
if (m_oldTexType && m_numCoords){
state->set("gl.tex.numcoords", m_numCoords);
if(m_oldTexType==2 && img!=NULL){
// since we are using rectangle-textures (state->texture==2),
// we want to scale the coordinates by the image-dimensions if they are available
t_float xsize = (t_float)state->image->image.xsize;
t_float ysize = (t_float)state->image->image.ysize;
t_float xsize = (t_float)img->image.xsize;
t_float ysize = (t_float)img->image.ysize;
for (int i = 0; i < m_numCoords; i++)
{
m_rectcoords[i].s = xsize*m_coords[i].s;
m_rectcoords[i].t = ysize*m_coords[i].t;
}
state->texCoords=m_rectcoords;
state->set("gl.tex.coords", m_rectcoords);
} else
state->texCoords = m_coords;
}
state->set("gl.tex.coords", m_coords);
}
}
/////////////////////////////////////////////////////////
......@@ -83,8 +87,9 @@ void pix_coordinate :: render(GemState *state)
/////////////////////////////////////////////////////////
void pix_coordinate :: postrender(GemState *state)
{
state->texCoords= m_oldTexCoords;
state->numTexCoords= m_oldNumCoords;
state->set("gl.tex.coords", m_oldTexCoords);
state->set("gl.tex.numcoords", m_oldNumCoords);
state->set("gl.tex.type", m_oldTexType);
}
/////////////////////////////////////////////////////////
......
......@@ -69,6 +69,7 @@ class GEM_EXTERN pix_coordinate : public GemBase
// The number
int m_numCoords;
int m_oldTexType;
//////////
// this is what we get from upstream
......
......@@ -136,15 +136,15 @@ bool pix_cubemap :: isRunnable(void) {
}
void pix_cubemap :: pushTexCoords(GemState*state) {
m_oldTexCoords=state->texCoords;
m_oldNumCoords=state->numTexCoords;
m_oldTexture =state->texture;
state->get("gl.tex.coords", m_oldTexCoords);
state->get("gl.tex.numcoords", m_oldNumCoords);
state->get("gl.tex.type", m_oldTexture);
}
void pix_cubemap :: popTexCoords(GemState*state) {
state->texCoords = m_oldTexCoords;
state->numTexCoords= m_oldNumCoords;
state->texture = m_oldTexture;
state->set("gl.tex.coords", m_oldTexCoords);
state->set("gl.tex.numcoords", m_oldNumCoords);
state->set("gl.tex.type", m_oldTexture);
}
......@@ -194,9 +194,13 @@ void pix_cubemap :: render(GemState *state) {
if(!m_textureOnOff)return;
/* here comes the work: a new image has to be transfered from main memory to GPU and attached to a texture object */
if(state&&state->image) {
if(state->image->newimage)
m_img[0]=&state->image->image;
if(state) {
pixBlock*img=NULL;
state->get("pix", img);
if(img) {
if(img->newimage)
m_img[0]=&img->image;
}
}
......@@ -232,21 +236,23 @@ void pix_cubemap :: render(GemState *state) {
m_rebuildList = 0;
m_didTexture=true;
state->multiTexUnits = m_numTexUnits;
state->texture = 1;
state->texture=0;
state->set("gl.tex.units", m_numTexUnits);
state->set("gl.tex.type", 0); // ?
// sendExtTexture(m_textureObj, m_xRatio, m_yRatio, m_textureType, upsidedown);
}
void pix_cubemap :: rightImage(int id, GemState *state) {
if(!state)return;
if(id<0 || id>=6) {
error("not a valid image-slot %d", id);
}
if(state && state->image) {
if(state->image->newimage) {
m_img[id]=&state->image->image;
pixBlock*img=NULL;
state->get("pix", img);
if(img) {
if(img->newimage) {
m_img[id]=&img->image;
} else {
// m_img[id]=NULL;
}
......
......@@ -55,23 +55,25 @@ pix_draw :: ~pix_draw()
void pix_draw :: render(GemState *state)
{
int orientation=1;
if ( !state->image || !&state->image->image ) return;
glRasterPos2i(0, 0);
// hack to center image at 0,0
if(state->image->image.upsidedown)
orientation=-1;
pixBlock*img=NULL;
state->get("pix", img);
if ( !img || !&img->image ) return;
glRasterPos2i(0, 0);
// hack to center image at 0,0
if(img->image.upsidedown)
orientation=-1;
glPixelZoom(1,orientation);
glPixelZoom(1,orientation);
glBitmap(0, 0, 0.f, 0.f, -(state->image->image.xsize)/2.f,
-orientation*(state->image->image.ysize)/2.f, 0);
glBitmap(0, 0, 0.f, 0.f, -(img->image.xsize)/2.f,
-orientation*(img->image.ysize)/2.f, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glDrawPixels(state->image->image.xsize,
state->image->image.ysize,
state->image->image.format,
state->image->image.type,
state->image->image.data);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glDrawPixels(img->image.xsize,
img->image.ysize,
img->image.format,
img->image.type,
img->image.data);
}
/////////////////////////////////////////////////////////
......
......@@ -393,15 +393,18 @@ void pix_film :: render(GemState *state)
#ifdef HAVE_PTHREADS
if(m_thread_running) {
pthread_mutex_lock(m_mutex);
state->image=m_frame;
state->set("pix", m_frame);
} else
#endif /* PTHREADS */
state->image=m_handle->getFrame();
state->set("pix", m_handle->getFrame());
pixBlock*img=NULL;
state->get("pix", img);
// someone wants to process the image downstream, so make sure they get it
if (m_cache&&m_cache->resendImage&&state->image)
if (m_cache&&m_cache->resendImage&&img)
{
state->image->newimage=true;
img->newimage=true;
m_cache->resendImage = 0;
}
......@@ -409,7 +412,7 @@ void pix_film :: render(GemState *state)
m_handle->setAuto(m_auto);
frame=static_cast<int>(m_reqFrame);
if (NULL==state->image){
if (NULL==img){
outlet_float(m_outEnd,(m_numFrames>0 && static_cast<int>(m_reqFrame)<0)?(m_numFrames-1):0);
if(frame!=static_cast<int>(m_reqFrame)){
......@@ -422,8 +425,8 @@ void pix_film :: render(GemState *state)
*/
m_handle->changeImage(static_cast<int>(m_reqFrame), m_reqTrack);
}
state->image=m_handle->getFrame();
state->set("pix", m_handle->getFrame());
}
}
}
......@@ -435,7 +438,12 @@ void pix_film :: render(GemState *state)
void pix_film :: postrender(GemState *state)
{
if(!m_handle)return;
if (state && state->image)state->image->newimage = 0;
if (state) {
pixBlock*img=NULL;
state->get("pix", img);
if(img)
img->newimage = false;
}
#ifdef HAVE_PTHREADS
if(m_thread_running){
......
......@@ -258,7 +258,7 @@ void pix_image :: render(GemState *state)
m_pixBlock.newimage = 1;
m_cache->resendImage = 0;
}
state->image = &m_pixBlock;
state->set("pix", &m_pixBlock);
}
/////////////////////////////////////////////////////////
......@@ -268,8 +268,7 @@ void pix_image :: render(GemState *state)
void pix_image :: postrender(GemState *state)
{
m_pixBlock.newimage = 0;
state->image = NULL;
state->set("pix", static_cast<pixBlock*>(NULL));
#ifdef HAVE_PTHREADS
if(m_mutex)
pthread_mutex_unlock(m_mutex);
......
......@@ -72,7 +72,7 @@ void pix_imageInPlace :: render(GemState *state)
if (!m_loadedCache->textBind[m_curImage])
return;
state->texture = 1;
state->set("gl.tex.type", 1);
glEnable(GL_TEXTURE_2D);
......@@ -89,7 +89,7 @@ void pix_imageInPlace :: render(GemState *state)
/////////////////////////////////////////////////////////
void pix_imageInPlace :: postrender(GemState *state)
{
state->texture = 0;
state->set("gl.tex.type", 0);
glDisable(GL_TEXTURE_2D);
}
......
......@@ -60,9 +60,12 @@ pix_info :: ~pix_info()
/////////////////////////////////////////////////////////
void pix_info :: render(GemState *state)
{
// 0 0 0 6408 5121 1 1 0 0 9.59521e+08
t_atom abuf[3];
if (!state || !state->image){ //no pixblock (or even no image!)!
pixBlock*img=NULL;
if(state)state->get("pix", img);
if (!state || !img){ //no pixblock (or even no image!)!
outlet_float(m_pixblock, (t_float)-1);
outlet_float(m_misc, (t_float)-1);
outlet_float(m_format, (t_float)-1);
......@@ -71,9 +74,9 @@ void pix_info :: render(GemState *state)
outlet_float(m_x, (t_float)-1);
return;
}
SETFLOAT( &abuf[0], (t_float)state->image->newimage);
SETFLOAT( &abuf[1], (t_float)state->image->newfilm);
if (!&state->image->image){ // we have a pixblock, but no image!
SETFLOAT( &abuf[0], (t_float)img->newimage);
SETFLOAT( &abuf[1], (t_float)img->newfilm);
if (!&img->image){ // we have a pixblock, but no image!
outlet_list(m_pixblock, gensym("list"), 2, abuf);
outlet_float(m_misc, (t_float)-1);
......@@ -83,22 +86,22 @@ void pix_info :: render(GemState *state)
outlet_float(m_x, (t_float)-1);
return;
}
if(state->image->image.data){
t_gpointer*gp=(t_gpointer*)state->image->image.data;
if(img->image.data){
t_gpointer*gp=(t_gpointer*)img->image.data;
SETPOINTER(&abuf[2], gp);
outlet_anything(m_data, gensym("data"), 1, abuf+2);
}
outlet_list(m_pixblock, gensym("list"), 2, abuf);
SETFLOAT (&abuf[0], (t_float)state->image->image.type);
SETFLOAT (&abuf[1], (t_float)state->image->image.upsidedown);
SETFLOAT (&abuf[2], (t_float)state->image->image.notowned);
SETFLOAT (&abuf[0], (t_float)img->image.type);
SETFLOAT (&abuf[1], (t_float)img->image.upsidedown);
SETFLOAT (&abuf[2], (t_float)img->image.notowned);
outlet_list(m_misc, gensym("list"), 3, abuf);
// send out the colorspace (as integer!)
outlet_float(m_format, (t_float)state->image->image.format);
outlet_float(m_format, (t_float)img->image.format);
// send out the width/height/csize information
outlet_float(m_c, (t_float)state->image->image.csize);
outlet_float(m_y, (t_float)state->image->image.ysize);
outlet_float(m_x, (t_float)state->image->image.xsize);
outlet_float(m_c, (t_float)img->image.csize);
outlet_float(m_y, (t_float)img->image.ysize);
outlet_float(m_x, (t_float)img->image.xsize);
}
void pix_info :: obj_setupCallback(t_class *classPtr){
}
......@@ -62,18 +62,20 @@ void pix_movie :: render(GemState *state)
/* get the current frame from the file */
if (!state || !m_handle)return;
// get the frame from the decoding-object: film[].cpp
#ifdef HAVE_PTHREADS
if(m_thread_running) {
pthread_mutex_lock(m_mutex);
state->image=m_frame;
state->set("pix", m_frame);
} else
#endif /* PTHREADS */
state->image=m_handle->getFrame();
state->set("pix", m_handle->getFrame());
pixBlock*img=NULL;
state->get("pix", img);
frame=static_cast<int>(m_reqFrame);
if (state->image==0){
if (img==0){
outlet_float(m_outEnd,(m_numFrames>0 && static_cast<int>(m_reqFrame)<0)?(m_numFrames-1):0);
if(frame!=static_cast<int>(m_reqFrame)){
......@@ -85,7 +87,7 @@ void pix_movie :: render(GemState *state)
*/
m_handle->changeImage(static_cast<int>(m_reqFrame), m_reqTrack);
}
state->image=m_handle->getFrame();
state->set("pix", m_handle->getFrame());
}
}
......@@ -99,7 +101,11 @@ void pix_movie :: render(GemState *state)
void pix_movie :: postrender(GemState *state)
{
if(!m_handle)return;
if (state && state->image)state->image->newimage = 0;
if (state) {
pixBlock*img=NULL;
state->get("pix", img);
if(img)img->newimage = false;
}
#ifdef HAVE_PTHREADS
if(m_thread_running){
......
......@@ -202,7 +202,7 @@ void pix_multiimage :: render(GemState *state)
m_cache->resendImage = 0;
}
state->image = &m_pixBlock;
state->set("pix", &m_pixBlock);
}
/////////////////////////////////////////////////////////
......@@ -211,8 +211,8 @@ void pix_multiimage :: render(GemState *state)
/////////////////////////////////////////////////////////
void pix_multiimage :: postrender(GemState *state)
{
m_pixBlock.newimage = 0;
state->image = NULL;
m_pixBlock.newimage = 0;
state->set("pix", static_cast<pixBlock*>(NULL));
}
/////////////////////////////////////////////////////////
......
......@@ -120,25 +120,32 @@ inline void setTexCoords(TexCoord *coords, float xRatio, float yRatio, GLboolean
/////////////////////////////////////////////////////////
void pix_multitexture :: render(GemState *state)
{
m_oldTexCoords=state->texCoords;
m_oldNumCoords=state->numTexCoords;
m_oldTexture =state->texture;
int textype=0;
state->get("gl.tex.coords", m_oldTexCoords);
state->get("gl.tex.numcoords", m_oldNumCoords);
state->get("gl.tex.type", m_oldTexture);
state->get("gl.tex.units", m_reqTexUnits);
state->multiTexUnits = m_reqTexUnits;
if (m_textureType == GL_TEXTURE_2D)
{
m_xRatio = 1.0;
m_yRatio = 1.0;
state->texture = 1;
textype = 1;
}else{
m_xRatio = m_texSizeX;
m_yRatio = m_texSizeY;
state->texture = 2;
textype = 2;
}
setTexCoords(m_coords, m_xRatio, m_yRatio, true);
state->texCoords = m_coords;
state->numTexCoords = 4;
TexCoord*tc=m_coords;
state->set("gl.tex.coords", tc);
state->set("gl.tex.numcoords", 4);
state->set("gl.tex.type", textype);
for ( int i=0; i< m_reqTexUnits; i++ )
{
if(GLEW_VERSION_1_3) {
......@@ -162,10 +169,9 @@ void pix_multitexture :: render(GemState *state)
/////////////////////////////////////////////////////////
void pix_multitexture :: postrender(GemState *state)
{
state->texCoords = m_oldTexCoords;
state->numTexCoords= m_oldNumCoords;
state->texture = m_oldTexture;
state->set("gl.tex.coords", m_oldTexCoords);
state->set("gl.tex.numcoords", m_oldNumCoords);
state->set("gl.tex.type", m_oldTexture);
if(GLEW_VERSION_1_3) {
for ( int i = m_reqTexUnits; i>0; i--)
......
......@@ -247,15 +247,18 @@ void pix_record :: stopRecording()
void pix_record :: render(GemState *state)
{
//check if state exists
if(!state || !state->image)return;
if(!state->image->image.data){
if(!state)return;
pixBlock*img=NULL;
state->get("pix", img);
if(!img || !img->image.data){
return;
}
if(!m_handle)return;
if(m_banged||m_automatic){
// if(m_maxFrames != 0 && m_currentFrame >= m_maxFrames) m_recordStop = 1;
bool success=m_handle->write(&state->image->image);
bool success=m_handle->write(&img->image);
m_banged=false;
if(success) {
......
......@@ -75,7 +75,7 @@ pix_set :: ~pix_set()
/////////////////////////////////////////////////////////
void pix_set :: render(GemState *state)