Permalink
Browse files

Introduce multitexturing for masking

  • Loading branch information...
alexp-sssup committed Oct 18, 2010
1 parent 18d8da9 commit 32a63d62623f10ea815e31ef77d4723654fc4044
Showing with 160 additions and 109 deletions.
  1. +3 −42 backends/graphics.cpp
  2. +0 −15 backends/graphics.h
  3. +60 −7 backends/rendering.cpp
  4. +1 −1 i18n/fr.po
  5. +1 −1 i18n/pl.po
  6. +1 −1 i18n/zh_CN.po
  7. +8 −11 lightspark.frag
  8. +3 −3 parsing/tags.cpp
  9. +1 −3 parsing/tags.h
  10. +44 −14 scripting/flashdisplay.cpp
  11. +23 −11 scripting/flashdisplay.h
  12. +15 −0 threading.h
View
@@ -478,7 +478,9 @@ bool CairoRenderer::cairoPathFromTokens(cairo_t* cr, const std::vector<GeomToken
cairo_set_source(cr, pattern);
}
else
- ::abort();
+ {
+ LOG(LOG_NOT_IMPLEMENTED, "Unsupported fill style");
+ }
break;
}
default:
@@ -534,44 +536,3 @@ void CairoRenderer::execute()
cairo_destroy(cr);
cairo_surface_destroy(cairoSurface);
}
-
-void MaskedCairoRenderer::execute()
-{
- //Will be unlocked after uploadFence
- if(!Sheep::lockOwner())
- return;
- if(width==0 || height==0)
- {
- //Nothing to do, move on
- return;
- }
- cairo_surface_t* cairoSurface=allocateSurface();
- cairo_t* cr=cairo_create(cairoSurface);
-
- cairoClean(cr);
-
- cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
- cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
-
- //Apply mask
- maskMatrix.TranslateX-=xOffset;
- maskMatrix.TranslateY-=yOffset;
- const cairo_matrix_t& mat=MATRIXToCairo(maskMatrix);
- cairo_set_matrix(cr, &mat);
-
- bool empty=cairoPathFromTokens(cr, maskTokens, maskScaleFactor);
- if(!empty)
- cairo_clip(cr);
-
- matrix.TranslateX-=xOffset;
- matrix.TranslateY-=yOffset;
- const cairo_matrix_t& mat2=MATRIXToCairo(matrix);
- cairo_set_matrix(cr, &mat2);
-
- empty=cairoPathFromTokens(cr, tokens, scaleFactor);
- if(!empty)
- cairo_fill(cr);
-
- cairo_destroy(cr);
- cairo_surface_destroy(cairoSurface);
-}
View
@@ -227,20 +227,5 @@ class CairoRenderer: public ITextureUploadable, public IThreadJob, public Sheep
void execute();
};
-class MaskedCairoRenderer: public CairoRenderer
-{
-protected:
- MATRIX maskMatrix;
- const std::vector<GeomToken> maskTokens;
- const float maskScaleFactor;
-public:
- MaskedCairoRenderer(Shepherd* _o, CachedSurface& _t, const std::vector<GeomToken>& _g, const MATRIX& _m,
- uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, float _s,
- const std::vector<GeomToken>& _mg, const MATRIX& _mm, float _ms):
- CairoRenderer(_o,_t,_g,_m,_x,_y,_w,_h,_s),maskMatrix(_mm),maskTokens(_mg),maskScaleFactor(_ms){}
- //IThreadJob interface
- void execute();
-};
-
};
#endif
View
@@ -515,14 +515,32 @@ void RenderThread::commonGLInit(int width, int height)
glUseProgram(gpu_program);
cleanGLErrors();
int tex=glGetUniformLocation(gpu_program,"g_tex1");
- glUniform1i(tex,0);
+ cout << tex << endl;
+ if(tex!=-1)
+ glUniform1i(tex,0);
+ tex=glGetUniformLocation(gpu_program,"g_tex2");
+ cout << tex << endl;
+ if(tex!=-1)
+ glUniform1i(tex,1);
fragmentTexScaleUniform=glGetUniformLocation(gpu_program,"texScale");
- glUniform2f(fragmentTexScaleUniform,1,1);
+ cout << fragmentTexScaleUniform << endl;
+ if(fragmentTexScaleUniform!=-1)
+ glUniform2f(fragmentTexScaleUniform,1.0f/width,1.0f/height);
cleanGLErrors();
+ //Texturing must be enabled otherwise no tex coord will be sent to the shaders
+ glEnable(GL_TEXTURE_2D);
//Default to replace
- glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
- // create a framebuffer object
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
+ //At least two texture unit are guaranteed in OpenGL 1.3
+ //The second unit will be used to access the temporary buffer
+ glActiveTexture(GL_TEXTURE1);
+ glEnable(GL_TEXTURE_2D);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
+ glBindTexture(GL_TEXTURE_2D, tempTex.getId());
+
+ glActiveTexture(GL_TEXTURE0);
+ //Create a framebuffer object
glGenFramebuffers(1, &fboId);
glBindFramebuffer(GL_FRAMEBUFFER, fboId);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D, tempTex.getId(), 0);
@@ -677,6 +695,32 @@ void RenderThread::coreRendering(FTFont& font, bool testMode)
m_sys->inputRender();
materialOverride=false;
}
+
+ //Clear the tmp buffer
+ glBindFramebuffer(GL_FRAMEBUFFER, fboId);
+ glDrawBuffer(GL_COLOR_ATTACHMENT0);
+ glClearColor(1,0,0,0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glLoadIdentity();
+ glUseProgram(0);
+ glColor4f(0,1,0,1);
+ glActiveTexture(GL_TEXTURE1);
+ glDisable(GL_TEXTURE_2D);
+ glActiveTexture(GL_TEXTURE0);
+ glDisable(GL_TEXTURE_2D);
+ glBegin(GL_QUADS);
+ glVertex2i(windowWidth/2-100,windowHeight/2-100);
+ glVertex2i(windowWidth/2+100,windowHeight/2-100);
+ glVertex2i(windowWidth/2+100,windowHeight/2+100);
+ glVertex2i(windowWidth/2-100,windowHeight/2+100);
+ glEnd();
+ glActiveTexture(GL_TEXTURE1);
+ glEnable(GL_TEXTURE_2D);
+ glActiveTexture(GL_TEXTURE0);
+ glEnable(GL_TEXTURE_2D);
+ glUseProgram(gpu_program);
+ //End DEBUG
+
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDrawBuffer(GL_BACK);
//Clear the back buffer
@@ -712,11 +756,17 @@ void RenderThread::coreRendering(FTFont& font, bool testMode)
glTranslatef(-offsetX,(offsetY+windowHeight)*(-1.0f),0);
glUseProgram(0);
glDisable(GL_BLEND);
+ glActiveTexture(GL_TEXTURE1);
+ glDisable(GL_TEXTURE_2D);
+ glActiveTexture(GL_TEXTURE0);
glDisable(GL_TEXTURE_2D);
if(selectedDebug)
selectedDebug->debugRender(&font, true);
else
m_sys->debugRender(&font, true);
+ glActiveTexture(GL_TEXTURE1);
+ glEnable(GL_TEXTURE_2D);
+ glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glUseProgram(gpu_program);
@@ -728,6 +778,9 @@ void RenderThread::coreRendering(FTFont& font, bool testMode)
glScalef(1.0f/scaleX,-1.0f/scaleY,1);
glTranslatef(-offsetX,(offsetY+windowHeight)*(-1.0f),0);
glUseProgram(0);
+ glActiveTexture(GL_TEXTURE1);
+ glDisable(GL_TEXTURE_2D);
+ glActiveTexture(GL_TEXTURE0);
glDisable(GL_TEXTURE_2D);
glColor3f(0,0,0);
char frameBuf[20];
@@ -747,6 +800,9 @@ void RenderThread::coreRendering(FTFont& font, bool testMode)
list<ThreadProfile>::iterator it=m_sys->profilingData.begin();
for(;it!=m_sys->profilingData.end();it++)
it->plot(1000000/m_sys->getFrameRate(),&font);
+ glActiveTexture(GL_TEXTURE1);
+ glEnable(GL_TEXTURE_2D);
+ glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glUseProgram(gpu_program);
}
@@ -783,8 +839,6 @@ void* RenderThread::sdl_worker(RenderThread* th)
font.FaceSize(12);
try
{
- //Texturing must be enabled otherwise no tex coord will be sent to the shader
- glEnable(GL_TEXTURE_2D);
Chronometer chronometer;
while(1)
{
@@ -905,7 +959,6 @@ void* RenderThread::sdl_worker(RenderThread* th)
profile->accountTime(chronometer.checkpoint());
th->renderNeeded=false;
}
- glDisable(GL_TEXTURE_2D);
}
catch(LightsparkException& e)
{
View
@@ -11,10 +11,10 @@ msgstr ""
"PO-Revision-Date: 2010-08-22 17:26+0100\n"
"Last-Translator: Emmanuel Andry <eandry@mandriva.org>\n"
"Language-Team: \n"
+"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: teplain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
-"Language: fr\n"
"X-Poedit-Language: French\n"
"X-Poedit-Country: FRANCE\n"
View
@@ -12,10 +12,10 @@ msgstr ""
"PO-Revision-Date: 2010-08-20 23:03-0500\n"
"Last-Translator: <gostrc@gmail.com>\n"
"Language-Team: Polish\n"
+"Language: pl\n"
"MIME-Version: 1.0\n"
"Content-Type: teplain; charset=ISO-8859-2\n"
"Content-Transfer-Encoding: 8bit\n"
-"Language: pl\n"
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
"|| n%100>=20) ? 1 : 2);\n"
View
@@ -12,10 +12,10 @@ msgstr ""
"PO-Revision-Date: 2010-08-20 23:03-0500\n"
"Last-Translator: <song6song@gmail.com>\n"
"Language-Team: zh_CN\n"
+"Language: zh_CN\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
-"Language: zh_CN\n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: ../scripting/abc.cpp:925
View
@@ -1,35 +1,32 @@
-uniform sampler2D g_tex1;
+uniform sampler2D g_tex1, g_tex2;
uniform vec2 texScale;
-//We abuse of default varying to pass variou data
+//We abuse of default varying to pass various data
//gl_Color: Selector of current shader function
//gl_TexCoord[0]: Fill color/Texture coordinate
const mat3 YUVtoRGB = mat3( 1, 1, 1, //First coloumn
0, -0.344, 1.772, //Second coloumn
1.402, -0.714, 0); //Third coloumn
-vec4 solid_color()
-{
- return gl_TexCoord[0];
-}
-
vec4 tex_lookup()
{
- return texture2D(g_tex1,gl_TexCoord[0].xy*texScale);
+ return texture2D(g_tex1,gl_TexCoord[0].xy);
}
vec4 tex_lookup_yuv()
{
//Pixel format is VUYA
- vec4 val=texture2D(g_tex1,gl_TexCoord[0].xy*texScale).bgra-vec4(0,0.5,0.5,0);
+ vec4 val=texture2D(g_tex1,gl_TexCoord[0].xy).bgra-vec4(0,0.5,0.5,0);
val.rgb=YUVtoRGB*(val.rgb);
return val;
}
void main()
{
- gl_FragColor=(solid_color()*gl_Color.x)+
- (tex_lookup()*gl_Color.z)+
+ if(texture2D(g_tex2,gl_FragCoord.xy*texScale).a==0.0)
+ discard;
+
+ gl_FragColor=(tex_lookup()*gl_Color.z)+
(tex_lookup_yuv()*gl_Color.w);
}
View
@@ -959,6 +959,8 @@ void DefineShapeTag::computeCached()
void DefineShapeTag::invalidate()
{
+ //Acquire the lock to avoid data changes
+// SpinlockLocker locker(spinlock);
uint32_t x,y,width,height;
number_t bxmin,bxmax,bymin,bymax;
if(getBounds(bxmin,bxmax,bymin,bymax)==false)
@@ -1028,9 +1030,7 @@ void DefineShapeTag::inputRender()
void DefineShapeTag::Render()
{
- if(alpha==0)
- return;
- if(!visible)
+ if(skipRender())
return;
MatrixApplier ma(getMatrix());
View
@@ -73,8 +73,6 @@ class DisplayListTag: public Tag
class DictionaryTag: public Tag
{
-protected:
- std::vector<GeomToken> cachedTokens;
public:
Class_base* bindedTo;
RootMovieClip* loadedFrom;
@@ -93,7 +91,7 @@ class ControlTag: public Tag
virtual void execute(RootMovieClip* root)=0;
};
-class DefineShapeTag: public DictionaryTag, public DisplayObject
+class DefineShapeTag: public DictionaryTag, public Shape
{
private:
void computeCached();
Oops, something went wrong.

0 comments on commit 32a63d6

Please sign in to comment.