Draw() Performance problem
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/12/2010 at 00:40, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R12
Platform: Windows ;
Language(s) : C++ ;---------
Hi all,I have a full working SceneHookPlugin witch Draw some additional information about an object to the viewport. All works great except for the performance of the viewport, witch goes down to 20%.
To show the informations I use that function (GeClipmap, BaseBitmap...) :
https://developers.maxon.net/forum/topic/4169/3712_draw-text-to-viewport-like-measureconst&PID=15161#15161
Also the recalculation slows the fps-rate. Is there a Event like: "PolygonObject Changed?"How can I boost the performance?
Here is is the code-snippet:
static Bool DrawText(String text, LONG xpos, LONG ypos, BaseDraw *bd) { AutoAlloc<GeClipMap> cm; cm->Destroy(); if(!cm) return FALSE; if(cm->Init(0,0,1)!=IMAGERESULT_OK) return FALSE; cm->BeginDraw(); LONG width = cm->TextWidth(text); LONG height = cm->TextHeight(); cm->EndDraw(); cm->Destroy(); if(cm->Init(width, height, 1)!=IMAGERESULT_OK) return FALSE; cm->BeginDraw(); cm->SetColor(255, 255, 255, 0); cm->TextAt(0,0,text); cm->EndDraw(); bd->SetMatrix_Screen(); bd->SetLightList(BDRAW_SETLIGHTLIST_NOLIGHTS); Vector *padr = bNew Vector[4]; //... uvadr[3] = Vector(0,1,0); BaseBitmap *cmbmp = NULL; cmbmp = cm->GetBitmap(); if(!cmbmp) return FALSE; BaseBitmap *bmp = NULL; bmp = cmbmp->GetClone(); if(!bmp) return FALSE; // inverted alpha mode bd->DrawTexture(bmp, padr, cadr, vnadr, uvadr, 4, DRAW_ALPHA_INVERTED, DRAW_TEXTUREFLAGS_0); return TRUE; } Bool XXProgram::Draw(BaseSceneHook *node, BaseDocument *doc, BaseDraw *bd, BaseDrawHelp *bh, BaseThread *bt, SCENEHOOKDRAW flags) { if(!SCENEHOOKDRAW_DRAW_PASS) return FALSE; if(!doc) return FALSE; AutoAlloc <AtomArray> arr; doc->GetActivePolygonObjects(*arr, TRUE); //...calculations DrawText(result, 5, 15, bd); return TRUE; }
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/12/2010 at 11:28, xxxxxxxx wrote:
Ok guys,
I found that command (GetDirty). Now I can check if the PolygonObject was changed or not. (no useless calculation anymore). The performance is now a little bit better.
But please, any idea to improve the viewport?
Can I use HUD? When yes, how?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/12/2010 at 14:44, xxxxxxxx wrote:
Ok, now I use ASCII Sets: https://developers.maxon.net/forum/topic/3185/2565_drawing-text-to-editor-view&OB=ASC
Better performance now, but if someone have a better idea, share it.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 27/12/2010 at 01:18, xxxxxxxx wrote:
Hi,
i use the DrawTexture method. It has some overhead of course but the time it takes to draw the text is independent of the scene size and is also faily small, so it is no big deal.
A word about your memory management: Your plugin owns the bitmaps and vectors supplied to DrawTexture. So you have to free this stuff again. The copies and heap allocations are not needed. You could just allocate the arrays of vectors on the stack. And also use bm->GetBitmap() as argument to DrawTexture.
Everything else is nearly the same in my code (except for some checks which i neglected ...)
static void DrawTexture(BaseDraw *bd, BaseBitmap *bm, const Vector &pos;, const Vector &color;, const Vector &scale; = Vector(1.)) { Vector p[4] = { Vector(0,0,0), Vector(0,1,0), Vector(1,1,0), Vector(1,0,0) }; Vector col[4]; Vector uv[4]; Vector norm[4]; Vector size = scale ^ Vector(bm->GetBw(), bm->GetBh(), 0); for(int i=0; i<4; ++i) { uv[i] = p[i]; col[i] = color; norm[i] = Vector(0,0,1); p[i] = (p[i] ^ size) + pos; } #if 1 // hack around that DrawTexture ignores the supplied colors AutoAlloc<BaseBitmap> bmcopy; if(color != Vector(1)) { bm->CopyTo(bmcopy); bm = bmcopy; for(LONG y=0; y<bm->GetBh(); ++y) for(LONG x=0; x<bm->GetBw(); ++x) { UWORD r,g,b, alpha; bm->GetPixel(x, y, &r;, &g;, &b;); r *= color.x; g *= color.y; b *= color.z; bm->SetPixel(x, y, r, g, b); } } #endif bd->DrawTexture(bm, p, col, norm, uv, 4, DRAW_ALPHA_NORMAL, DRAW_TEXTUREFLAGS_INTERPOLATION_NEAREST); } static void DrawText(BaseDraw *bd, const String &text;, const Vector &pos;, const Vector &color; = Vector(1), const Vector &scale; = Vector(1)) { AutoAlloc<GeClipMap> bm; bm->Init(1, 1, 32); bm->BeginDraw(); LONG w = bm->TextWidth(text) + 8, h = bm->TextHeight() + 4; // must be enclosed in BeginDraw/EndDraw pairs bm->EndDraw(); bm->Init(w, h, 32); bm->BeginDraw(); bm->SetColor(0,0,0,180); bm->FillRect(0,0,w-1,h-1); bm->SetColor(255,255,255,255); bm->TextAt(4,2,text); bm->EndDraw(); DrawTexture(bd, bm->GetBitmap(), pos, color, scale); }
... stupid forum inserts extra newlines
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 08/01/2011 at 08:35, xxxxxxxx wrote:
Hi Michael Welter,
Thank you for your answer, but for me its to slow. Maxon please, give HUD free.