Esempio n. 1
0
        public static void glVertex3f(T x, T y, T z)
        {
            IVector <T> WorldPoint = MatrixFactory <T> .CreateVector3D(x, y, z);

            WorldPoint = m_CurAccumulatedMatrix.TransformVector(WorldPoint);
            T OneOverZ = M.One <T>().Divide(WorldPoint[2]);

            WorldPoint[0] = WorldPoint[0].Multiply(OneOverZ).Add(1).Multiply(s_GLViewport.X2 * .5f).Add(s_GLViewport.X1);
            WorldPoint[1] = WorldPoint[1].Multiply(OneOverZ).Add(1).Multiply(s_GLViewport.Y2 * .5f).Add(s_GLViewport.Y1);

            m_pVertexCache[m_NumCachedVertex].m_Position          = WorldPoint;
            m_pVertexCache[m_NumCachedVertex].m_Color             = m_LastSetColor;
            m_pVertexCache[m_NumCachedVertex].m_Normal            = m_LastSetNormal;
            m_pVertexCache[m_NumCachedVertex].m_TextureCoordinate = m_LastSetTextureCoordinate;

            m_NumCachedVertex++;

            //double Dilation = 0;
            T Dilation = M.New <T>(.175);

            switch (s_BeginMode)
            {
            /*
             * case GL_POINTS:
             * {
             *  RenderLine(m_pVertexCache[0].m_Position, m_pVertexCache[0].m_Position, m_LastSetColor);
             *  m_NumCachedVertex3fs = 0;
             * }
             * break;
             *
             * case LINES:
             * {
             *  if(m_NumCachedVertex3fs == 2)
             *  {
             *      // <WIP> use both vertex colors LBB [1/14/2002]
             *      RenderLine(m_pVertexCache[0].m_Position, m_pVertexCache[1].m_Position, m_pVertexCache[0].m_Color);
             *      m_NumCachedVertex3fs = 0;
             *  }
             * }
             * break;
             */

            case GL_TRIANGLES:
                if (m_NumCachedVertex == 3)
                {
                    IVector <T> Winding = VectorUtilities <T> .Cross(
                        m_pVertexCache[1].m_Position.Subtract(m_pVertexCache[0].m_Position),
                        m_pVertexCache[2].m_Position.Subtract(m_pVertexCache[0].m_Position));



                    if (Winding[2].GreaterThan(0))
                    {
                        s_GouraudSpanGen.Colors(m_pVertexCache[0].m_Color,
                                                m_pVertexCache[1].m_Color,
                                                m_pVertexCache[2].m_Color);
                        s_GouraudSpanGen.Triangle(m_pVertexCache[0].m_Position[0], m_pVertexCache[0].m_Position[1],
                                                  m_pVertexCache[1].m_Position[0], m_pVertexCache[1].m_Position[1],
                                                  m_pVertexCache[2].m_Position[0], m_pVertexCache[2].m_Position[1], Dilation);
                        s_Rasterizer.AddPath(s_GouraudSpanGen);
                        //s_Rasterizer.gamma(new gamma_linear(0.0, 0.809));
                        //renderer_scanlines.render_scanlines_aa_solid(ras, sl, ren_base, m_pVertexCache[0].m_Color.Get_rgba8());
                        Renderer <T> .GenerateAndRender(s_Rasterizer, s_ScanlineUnpacked, s_ClippingPixelFormatProxy, s_SpanAllocator, s_GouraudSpanGen);
                    }

                    m_NumCachedVertex = 0;
                }
                break;

            case GL_QUADS:
                if (m_NumCachedVertex == 4)
                {
                    IVector <T> Winding = VectorUtilities <T> .Cross(
                        m_pVertexCache[1].m_Position.Subtract(m_pVertexCache[0].m_Position),
                        m_pVertexCache[2].m_Position.Subtract(m_pVertexCache[0].m_Position));

                    if (Winding[2].GreaterThan(0))
                    {
                        switch (s_ShadeModel)
                        {
                        case GL_FLAT:
                            // this can be faster if we don't try to shade it (no span generator)
                            s_SharedPathStorage.RemoveAll();
                            s_SharedPathStorage.MoveTo(m_pVertexCache[0].m_Position[0], m_pVertexCache[0].m_Position[1]);
                            s_SharedPathStorage.LineTo(m_pVertexCache[1].m_Position[0], m_pVertexCache[1].m_Position[1]);
                            s_SharedPathStorage.LineTo(m_pVertexCache[2].m_Position[0], m_pVertexCache[2].m_Position[1]);
                            s_SharedPathStorage.LineTo(m_pVertexCache[3].m_Position[0], m_pVertexCache[3].m_Position[1]);

                            s_Rasterizer.AddPath(s_SharedPathStorage);
                            Renderer <T> .RenderSolid(s_ClippingPixelFormatProxy, s_Rasterizer, s_ScanlineUnpacked, m_pVertexCache[0].m_Color.GetAsRGBA_Bytes());

                            break;

                        case GL_SMOOTH:
                            s_GouraudSpanGen.Colors(
                                m_pVertexCache[0].m_Color,
                                m_pVertexCache[1].m_Color,
                                m_pVertexCache[2].m_Color);

                            s_GouraudSpanGen.Triangle(
                                m_pVertexCache[0].m_Position[0], m_pVertexCache[0].m_Position[1],
                                m_pVertexCache[1].m_Position[0], m_pVertexCache[1].m_Position[1],
                                m_pVertexCache[2].m_Position[0], m_pVertexCache[2].m_Position[1], Dilation);

                            s_Rasterizer.AddPath(s_GouraudSpanGen);
                            //s_Rasterizer.gamma(new gamma_linear(0.0, 0.809));

                            Renderer <T> .RenderSolid(s_ClippingPixelFormatProxy, s_Rasterizer, s_ScanlineUnpacked, m_pVertexCache[0].m_Color.GetAsRGBA_Bytes());

                            s_GouraudSpanGen.Colors(
                                m_pVertexCache[0].m_Color,
                                m_pVertexCache[2].m_Color,
                                m_pVertexCache[3].m_Color);

                            s_GouraudSpanGen.Triangle(
                                m_pVertexCache[0].m_Position[0], m_pVertexCache[0].m_Position[1],
                                m_pVertexCache[2].m_Position[0], m_pVertexCache[2].m_Position[1],
                                m_pVertexCache[3].m_Position[0], m_pVertexCache[3].m_Position[1], M.Zero <T>());
                            s_Rasterizer.AddPath(s_GouraudSpanGen);
                            Renderer <T> .RenderSolid(s_ClippingPixelFormatProxy, s_Rasterizer, s_ScanlineUnpacked, m_pVertexCache[0].m_Color.GetAsRGBA_Bytes());

                            break;

                        default:
                            throw new System.NotImplementedException();
                        }
                    }

                    m_NumCachedVertex = 0;
                }
                break;

            default:
                // Be sure to call Begin before you pass Vertexes. LBB [1/12/2002]
                throw new System.NotImplementedException("You do not have a mode set or you have an invalid mode. LBB [1/12/2002]");
            }
        }
Esempio n. 2
0
        //template<class Scanline, class Ras>
        public void render_gouraud(IScanlineCache sl, IRasterizer <T> ras)
        {
            T alpha = m_alpha.value();
            T brc   = M.One <T>();

#if SourceDepth24
            pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr());
#else
            FormatRGBA pf = new FormatRGBA(rbuf_window(), new BlenderBGRA());
#endif
            FormatClippingProxy ren_base = new FormatClippingProxy(pf);

            AGG.SpanAllocator   span_alloc = new SpanAllocator();
            SpanGouraudRgba <T> span_gen   = new SpanGouraudRgba <T>();

            ras.Gamma(new GammaLinear(0.0, m_gamma.value().ToDouble()));

            T d = m_dilation.value();

            // Six triangles
            T xc = m_x[0].Add(m_x[1]).Add(m_x[2]).Divide(3.0);
            T yc = m_y[0].Add(m_y[1]).Add(m_y[2]).Divide(3.0);

            T x1 = m_x[1].Add(m_x[0]).Divide(2).Subtract(xc.Subtract(m_x[1].Add(m_x[0]).Divide(2)));
            T y1 = m_y[1].Add(m_y[0]).Divide(2).Subtract(yc.Subtract(m_y[1].Add(m_y[0]).Divide(2)));

            T x2 = m_x[2].Add(m_x[1]).Divide(2).Subtract(xc.Subtract(m_x[2].Add(m_x[1]).Divide(2)));
            T y2 = m_y[2].Add(m_y[1]).Divide(2).Subtract(yc.Subtract(m_y[2].Add(m_y[1]).Divide(2)));

            T x3 = m_x[0].Add(m_x[2]).Divide(2).Subtract(xc.Subtract(m_x[0].Add(m_x[2]).Divide(2)));
            T y3 = m_y[0].Add(m_y[2]).Divide(2).Subtract(yc.Subtract(m_y[0].Add(m_y[2]).Divide(2)));

            span_gen.Colors(new RGBA_Doubles(1, 0, 0, alpha.ToDouble()),
                            new RGBA_Doubles(0, 1, 0, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[0], m_y[0], m_x[1], m_y[1], xc, yc, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);


            span_gen.Colors(new RGBA_Doubles(0, 1, 0, alpha.ToDouble()),
                            new RGBA_Doubles(0, 0, 1, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[1], m_y[1], m_x[2], m_y[2], xc, yc, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);


            span_gen.Colors(new RGBA_Doubles(0, 0, 1, alpha.ToDouble()),
                            new RGBA_Doubles(1, 0, 0, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[2], m_y[2], m_x[0], m_y[0], xc, yc, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);


            brc = M.One <T>().Subtract(brc);
            span_gen.Colors(new RGBA_Doubles(1, 0, 0, alpha.ToDouble()),
                            new RGBA_Doubles(0, 1, 0, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[0], m_y[0], m_x[1], m_y[1], x1, y1, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);


            span_gen.Colors(new RGBA_Doubles(0, 1, 0, alpha.ToDouble()),
                            new RGBA_Doubles(0, 0, 1, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[1], m_y[1], m_x[2], m_y[2], x2, y2, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);


            span_gen.Colors(new RGBA_Doubles(0, 0, 1, alpha.ToDouble()),
                            new RGBA_Doubles(1, 0, 0, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[2], m_y[2], m_x[0], m_y[0], x3, y3, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);
        }