public override void DoIterationCycle(int numIterationsPerThread) { if (!IsAllocated()) { return; } int perThreadCount = 0; while (perThreadCount < numIterationsPerThread) { foreach (Iterator iter in iterators) { iter.StartIterateTask(); } foreach (Iterator iter in iterators) { iter.Finish(); } globalStats.IterCount += (ulong)DotsPerCycle; globalStats.DotCount = 0; globalStats.PeakDensity = 0.0f; for (int i = 0; i < iterators.Length; i++) { globalStats.DotCount += iterators[i].Stats.DotCount; } uint totalSubPixels = (uint)(xRes * yRes * AALevel * AALevel); float density = (float)globalStats.DotCount / (float)totalSubPixels; float invPixArea = Math.Abs((fractal->VpsTransform.XAxis.X * fractal->VpsTransform.YAxis.Y) - (fractal->VpsTransform.XAxis.Y * fractal->VpsTransform.YAxis.X)); globalStats.ScaleConstant = Tone_C2 * (invPixArea * (float)(AALevel * AALevel)) / (float)globalStats.IterCount; GL.BindFramebuffer(FramebufferTarget.Framebuffer, accumFBO); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, accumTexID, 0); GL.Enable(EnableCap.Blend); GL.BlendEquation(BlendEquationMode.FuncAdd); GL.BlendFunc((BlendingFactor)BlendingFactorSrc.One, (BlendingFactor)BlendingFactorDest.One); GL.Disable(EnableCap.PointSmooth); GL.PointSize(1.0f); GL.Viewport(0, 0, xRes * AALevel, yRes * AALevel); GL.MatrixMode(MatrixMode.Projection); GLUtil.GLLoadAffineMatrix(projTransform, -1.0f); GL.MatrixMode(MatrixMode.Modelview); GLUtil.GLLoadAffineMatrix(viewTransform); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, paletteTexID); GL.Color4(DownScaleFactor, DownScaleFactor, DownScaleFactor, DownScaleFactor); GL.EnableClientState((ArrayCap)EnableCap.VertexArray); GL.EnableClientState((ArrayCap)EnableCap.TextureCoordArray); GL.VertexPointer(2, VertexPointerType.Float, 16, (IntPtr)dots); GL.TexCoordPointer(2, TexCoordPointerType.Float, 16, (IntPtr)((byte *)dots + 8)); GL.DrawElements(BeginMode.Points, DotsPerCycle, DrawElementsType.UnsignedShort, (IntPtr)dotIndicies); GL.DisableClientState((ArrayCap)EnableCap.VertexArray); GL.DisableClientState((ArrayCap)EnableCap.TextureCoordArray); GL.Disable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, 0); GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); GL.Finish(); perThreadCount += DotsPerIterator; } }
public void Render(int glOutputTexID) { if (!SafeToRender) { return; } GL.Viewport(0, 0, ClientSize.Width, ClientSize.Height); Vec4 bgCol = FractalManager.Fractal.BackgroundColor; GL.ClearColor(bgCol.X, bgCol.Y, bgCol.Z, bgCol.W); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Enable(EnableCap.LineSmooth); GL.Enable(EnableCap.PointSmooth); GL.Enable(EnableCap.Blend); GL.BlendFuncSeparate(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha, BlendingFactorSrc.One, BlendingFactorDest.Zero); GL.MatrixMode(MatrixMode.Projection); GLUtil.GLLoadAffineMatrix(projTransform, -1.0f); GL.MatrixMode(MatrixMode.Modelview); GLUtil.GLLoadAffineMatrix(viewTransform); if (glOutputTexID != 0) { GL.MatrixMode(MatrixMode.Projection); GL.PushMatrix(); GL.LoadIdentity(); GL.Ortho(0, 1, 0, 1, -1, 1); GL.MatrixMode(MatrixMode.Modelview); GL.PushMatrix(); GL.LoadIdentity(); GL.BindTexture(TextureTarget.Texture2D, glOutputTexID); GL.Enable(EnableCap.Texture2D); GL.Begin(BeginMode.Quads); GL.Color4(1.0f, 1.0f, 1.0f, 1.0f); GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(0.0f, 0.0f); GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(1.0f, 0.0f); GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(1.0f, 1.0f); GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(0.0f, 1.0f); GL.End(); GL.BindTexture(TextureTarget.Texture2D, 0); GL.MatrixMode(MatrixMode.Projection); GL.PopMatrix(); GL.MatrixMode(MatrixMode.Modelview); GL.PopMatrix(); } if (EditMode && (dragModifier & DragModifier.Ctrl) == DragModifier.Ctrl) { GL.LineWidth(1.0f); DrawGrid(); } if (EditMode) { if (dragState == DragState.Dragging) { if (hoverBranch != null) { DrawWidget(hoverBranch, true); } GL.PointSize(6.0f); GL.Begin(BeginMode.Points); GL.Color4(1.0f, 1.0f, 0.5f, 1.0f); GL.Vertex2(dragHandlePos.X, dragHandlePos.Y); GL.End(); GL.PointSize(1.0f); } else { foreach (Branch branch in FractalManager.Branches) { DrawWidget(branch, branch == FractalManager.SelectedBranch); } if (hoverType != SelectionType.None) { GL.PointSize(6.0f); GL.Begin(BeginMode.Points); GL.Color4(0.5f, 1.0f, 1.0f, 1.0f); GL.Vertex2(hoverHandlePos.X, hoverHandlePos.Y); GL.End(); GL.PointSize(1.0f); } } } //GL.PointSize(6.0f); //GL.Begin(BeginMode.Points); //GL.Color4(1.0f,1.0f,1.0f,1.0f); //GL.Vertex2(debugPos.X, debugPos.Y); //GL.End(); GL.Finish(); SwapBuffers(); }