Exemplo n.º 1
0
        private Geometry CreateQuadGeometry()
        {
            PropertyBuffer vertexData = CreatePropertyBuffer();

            TexturedQuadVertex vertex1 = new TexturedQuadVertex();
            TexturedQuadVertex vertex2 = new TexturedQuadVertex();
            TexturedQuadVertex vertex3 = new TexturedQuadVertex();
            TexturedQuadVertex vertex4 = new TexturedQuadVertex();

            vertex1.position = new Vec2(-0.5f, -0.5f);
            vertex2.position = new Vec2(-0.5f, 0.5f);
            vertex3.position = new Vec2(0.5f, -0.5f);
            vertex4.position = new Vec2(0.5f, 0.5f);


            TexturedQuadVertex[] texturedQuadVertexData = new TexturedQuadVertex[4] {
                vertex1, vertex2, vertex3, vertex4
            };

            int    lenght = Marshal.SizeOf(vertex1);
            IntPtr pA     = Marshal.AllocHGlobal(lenght * 4);

            for (int i = 0; i < 4; i++)
            {
                Marshal.StructureToPtr(texturedQuadVertexData[i], pA + i * lenght, true);
            }
            vertexData.SetData(pA, 4);

            Geometry geometry = new Geometry();

            geometry.AddVertexBuffer(vertexData);
            geometry.SetType(Geometry.Type.TRIANGLE_STRIP);
            return(geometry);
        }
Exemplo n.º 2
0
        public void PropertyBufferSetData()
        {
            tlog.Debug(tag, $"PropertyBufferSetData START");

            PropertyMap buffer = new PropertyMap();

            Assert.IsNotNull(buffer, "should be not null");
            Assert.IsInstanceOf <PropertyMap>(buffer, "should be an instance of PropertyMap class!");
            buffer.Add("aIndex", new PropertyValue((int)PropertyType.Float));
            buffer.Add("aValue", new PropertyValue((int)PropertyType.Float));

            var testingTarget = new PropertyBuffer(buffer);

            Assert.IsNotNull(testingTarget, "should be not null");
            Assert.IsInstanceOf <PropertyBuffer>(testingTarget, "Should be an instance of PropertyBuffer class!");
            try
            {
                global::System.IntPtr data = new global::System.IntPtr();
                testingTarget.SetData(data, 0);
            }
            catch (Exception e)
            {
                LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
                Assert.Fail("Caught Exception" + e.ToString());
            }
            Assert.AreEqual(0, testingTarget.GetSize(), "Should be Equal.");

            testingTarget.Dispose();
            buffer.Dispose();
            tlog.Debug(tag, $"PropertyBufferSetData END (OK)");
        }
Exemplo n.º 3
0
        private Renderer CreateRenderer()
        {
            TexturedQuadVertex vertex1 = new TexturedQuadVertex();
            TexturedQuadVertex vertex2 = new TexturedQuadVertex();
            TexturedQuadVertex vertex3 = new TexturedQuadVertex();
            TexturedQuadVertex vertex4 = new TexturedQuadVertex();

            vertex1.position = new Vec2(-0.5f, -0.5f);
            vertex2.position = new Vec2(0.5f, -0.5f);
            vertex3.position = new Vec2(-0.5f, 0.5f);
            vertex4.position = new Vec2(0.5f, 0.5f);
            vertex1.texCoord = new Vec2(0.0f, 0.0f);
            vertex2.texCoord = new Vec2(1.0f, 0.0f);
            vertex3.texCoord = new Vec2(0.0f, 1.0f);
            vertex4.texCoord = new Vec2(1.0f, 1.0f);

            TexturedQuadVertex[] texturedQuadVertexData = new TexturedQuadVertex[4] {
                vertex1, vertex2, vertex3, vertex4
            };

            PropertyMap property = new PropertyMap();

            property.Add("aPosition", new PropertyValue((int)PropertyType.Vector2));
            property.Add("aTexCoord", new PropertyValue((int)PropertyType.Vector2));
            PropertyBuffer vertexBuffer = new PropertyBuffer(property);

            const int vertexCount = 4;

            unsafe
            {
                float *pc = (float *)Marshal.UnsafeAddrOfPinnedArrayElement(texturedQuadVertexData, 0);
                IntPtr pA = new IntPtr(pc);
                vertexBuffer.SetData(pA, vertexCount);
            }

            Geometry geometry = new Geometry();

            geometry.AddVertexBuffer(vertexBuffer);
            geometry.SetType(Geometry.Type.TRIANGLE_STRIP);

            // Create the shader
            Shader shader = new Shader(VERSION_3_ES + VERTEX_SHADER, VERSION_3_ES + FRAGMENT_SHADER);

            // Create the renderer
            Renderer renderer = new Renderer(geometry, shader);

            return(renderer);
        }
Exemplo n.º 4
0
        protected override void OnCreate()
        {
            base.OnCreate();
            Window window = NUIApplication.GetDefaultWindow();

            window.BackgroundColor = Color.Black;

            View view = new View()
            {
                Size = new Size(window.WindowSize)
            };

            window.Add(view);


            PropertyMap vertexFormat = new PropertyMap();

            vertexFormat.Add("aPosition", new PropertyValue((int)PropertyType.Vector2));
            PropertyBuffer vertexBuffer = new PropertyBuffer(vertexFormat);

            vertexBuffer.SetData(RectangleDataPtr(), 4);
            Geometry geometry = new Geometry();

            geometry.AddVertexBuffer(vertexBuffer);
            geometry.SetType(Geometry.Type.TRIANGLE_STRIP);
            Shader shader = new Shader(VERTEX_SHADER, FRAGMENT_SHADER);

            PixelData pixelData = PixelBuffer.Convert(ImageLoading.LoadImageFromFile(
                                                          "./res/background_image.jpg",
                                                          new Size2D(),
                                                          FittingModeType.ScaleToFill
                                                          ));
            Texture texture = new Texture(
                TextureType.TEXTURE_2D,
                pixelData.GetPixelFormat(),
                pixelData.GetWidth(),
                pixelData.GetHeight()
                );

            texture.Upload(pixelData);
            TextureSet textureSet = new TextureSet();

            textureSet.SetTexture(0u, texture);
            Renderer renderer = new Renderer(geometry, shader);

            renderer.SetTextures(textureSet);
            view.AddRenderer(renderer);
        }
Exemplo n.º 5
0
        private Geometry GenerateGeometry()
        {
            PropertyMap vertexFormat = new PropertyMap();

            vertexFormat.Add("aPosition", new PropertyValue((int)PropertyType.Vector3));
            vertexFormat.Add("aNormal", new PropertyValue((int)PropertyType.Vector3));
            vertexFormat.Add("aTexCoord", new PropertyValue((int)PropertyType.Vector2));
            PropertyBuffer vertexBuffer = new PropertyBuffer(vertexFormat);

            vertexBuffer.SetData(SphereVertexDataPtr(), SPHERE_VERTEX_NUMBER);

            ushort[] indexBuffer = SphereIndexData();

            Geometry geometry = new Geometry();

            geometry.AddVertexBuffer(vertexBuffer);
            geometry.SetIndexBuffer(indexBuffer, SPHERE_INDEX_NUMBER);
            geometry.SetType(Geometry.Type.TRIANGLES);
            return(geometry);
        }
Exemplo n.º 6
0
        /// <summary>
        /// View which is clipping image and applying mask
        /// </summary>
        /// <param name="resourceImageUrl">Image which will be cripped</param>
        /// <param name="maskImageUrl">Image for masking</param>
        public ClippingMaskView(string resourceImageUrl, string maskImageUrl)
        {
            // Load mask image file and make PixelData
            PixelData pixelData = PixelBuffer.Convert(
                ImageLoading.LoadImageFromFile(
                    maskImageUrl,
                    new Size2D(),
                    FittingModeType.ScaleToFill
                    )
                );

            // Make mask image texture and upload.
            Texture maskTexture = new Texture(
                TextureType.TEXTURE_2D,
                pixelData.GetPixelFormat(),
                pixelData.GetWidth(),
                pixelData.GetHeight()
                );

            maskTexture.Upload(pixelData);

            Size maskImageSize = new Size(maskTexture.GetWidth(), maskTexture.GetHeight());

            // Background Image will be clipped
            BackgroundImage = new ImageView()
            {
                PositionUsesPivotPoint = true,
                PivotPoint             = Tizen.NUI.PivotPoint.Center,
                ParentOrigin           = Tizen.NUI.ParentOrigin.Center,
                Size        = maskImageSize,
                ResourceUrl = resourceImageUrl,
            };
            Add(BackgroundImage);

            // Set properties for render task
            Camera camera = new Camera(new Vector2(maskImageSize.Width, maskImageSize.Height))
            {
                PositionUsesPivotPoint = true,
                PivotPoint             = Tizen.NUI.PivotPoint.Center,
                ParentOrigin           = Tizen.NUI.ParentOrigin.Center,
            };

            camera.SetInvertYAxis(true);
            Add(camera);

            RenderTask task = NUIApplication.GetDefaultWindow().GetRenderTaskList().CreateTask();

            task.SetRefreshRate((uint)RenderTask.RefreshRate.REFRESH_ALWAYS);
            task.SetSourceView(BackgroundImage);
            task.SetExclusive(true);
            task.SetInputEnabled(false);
            task.SetClearColor(new Vector4(1.0f, 1.0f, 1.0f, 1.0f));
            task.SetClearEnabled(true);
            task.SetCamera(camera);

            // Clipped Texture
            Texture clippedTexture = new Texture(
                TextureType.TEXTURE_2D,
                PixelFormat.RGBA8888,
                (uint)maskImageSize.Width,
                (uint)maskImageSize.Height
                );

            FrameBuffer frameBuffer = new FrameBuffer(
                (uint)maskImageSize.Width,
                (uint)maskImageSize.Height,
                (uint)FrameBuffer.Attachment.Mask.NONE
                );

            frameBuffer.AttachColorTexture(clippedTexture);
            task.SetFrameBuffer(frameBuffer);

            /* Create Renderer to apply mask */
            PropertyMap vertexFormat = new PropertyMap();

            vertexFormat.Add("aPosition", new PropertyValue((int)PropertyType.Vector2));
            PropertyBuffer vertexBuffer = new PropertyBuffer(vertexFormat);

            vertexBuffer.SetData(RectangleDataPtr(), 4);

            /* Create geometry */
            Geometry geometry = new Geometry();

            geometry.AddVertexBuffer(vertexBuffer);
            geometry.SetType(Geometry.Type.TRIANGLE_STRIP);

            /* Create Shader */
            Shader shader = new Shader(VERTEX_SHADER, FRAGMENT_SHADER);

            TextureSet textureSet = new TextureSet();

            textureSet.SetTexture(0u, clippedTexture);
            textureSet.SetTexture(1u, maskTexture);

            Renderer renderer = new Renderer(geometry, shader);

            renderer.SetTextures(textureSet);

            AddRenderer(renderer);
        }
Exemplo n.º 7
0
        private static void CreateGeometry()
        {
            if (geometry == null)
            {
                geometry = new Geometry();

                const int vertexCount = 34;

                circleArray = new float[vertexCount * 2];
                quadArray   = new float[vertexCount * 2];

                // Create the circle geometry

                // Radius is bound to actor's dimensions so this should not be increased.
                // If a bigger circle is required then the actor size should be increased.
                const float radius = 0.5f;
                Vector2     center = new Vector2(0.0f, 0.0f);

                // Create a buffer for vertex data
                Vector2[] circleBuffer = new Vector2[vertexCount];
                int       idx          = 0;

                // Center vertex for triangle fan
                circleBuffer[idx++] = center;

                // Outer vertices of the circle
                const int outerVertexCount = vertexCount - 1;

                for (int i = 0; i < outerVertexCount; ++i)
                {
                    float percent = (i / (float)(outerVertexCount - 1));
                    float rad     = percent * 2.0f * (float)Math.PI;

                    // Vertex position
                    Vector2 tmpvec = new Vector2(0, 0);
                    tmpvec.X = (float)(center.X + radius * Math.Cos(rad));
                    tmpvec.Y = (float)(center.Y + radius * Math.Sin(rad));

                    circleBuffer[idx++] = tmpvec;
                }

                for (int i = 0; i < idx; i++)
                {
                    circleArray[i * 2]     = circleBuffer[i].X;
                    circleArray[i * 2 + 1] = circleBuffer[i].Y;
                }

                PropertyMap circleVertexFormat = new PropertyMap();
                circleVertexFormat.Add("aPositionCircle", new PropertyValue((int)PropertyType.Vector2));
                PropertyBuffer circleVertices = new PropertyBuffer(circleVertexFormat);

                unsafe
                {
                    float *pc = (float *)Marshal.UnsafeAddrOfPinnedArrayElement(circleArray, 0);
                    IntPtr pA = new IntPtr(pc);
                    circleVertices.SetData(pA, vertexCount);
                }


                // Create the Quad Geometry
                Vector2[] quadBuffer = new Vector2[vertexCount];
                idx = 0;
                quadBuffer[idx++] = new Vector2(center.X, center.Y);

                const int vertsPerSide = (vertexCount - 2) / 4;
                Vector2   outer        = new Vector2(0.5f, 0.0f);
                quadBuffer[idx++] = new Vector2(outer.X, outer.Y);
                float incrementPerBuffer = 1.0f / (float)(vertsPerSide);

                for (int i = 0; i < vertsPerSide && outer.Y < 0.5f; ++i)
                {
                    outer.Y          += incrementPerBuffer;
                    quadBuffer[idx++] = new Vector2(outer.X, outer.Y);
                }

                for (int i = 0; i < vertsPerSide && outer.X > -0.5f; ++i)
                {
                    outer.X          -= incrementPerBuffer;
                    quadBuffer[idx++] = new Vector2(outer.X, outer.Y);
                }

                for (int i = 0; i < vertsPerSide && outer.Y > -0.5f; ++i)
                {
                    outer.Y          -= incrementPerBuffer;
                    quadBuffer[idx++] = new Vector2(outer.X, outer.Y);
                }

                for (int i = 0; i < vertsPerSide && outer.X < 0.5f; ++i)
                {
                    outer.X          += incrementPerBuffer;
                    quadBuffer[idx++] = new Vector2(outer.X, outer.Y);
                }

                for (int i = 0; i < vertsPerSide && outer.Y < 0.0f; ++i)
                {
                    outer.Y          += incrementPerBuffer;
                    quadBuffer[idx++] = new Vector2(outer.X, outer.Y);
                }

                for (int i = 0; i < idx; i++)
                {
                    quadArray[i * 2]     = quadBuffer[i].X;
                    quadArray[i * 2 + 1] = quadBuffer[i].Y;
                }

                PropertyMap vertexFormat = new PropertyMap();
                vertexFormat.Add("aPositionQuad", new PropertyValue((int)PropertyType.Vector2));
                PropertyBuffer quadVertices2 = new PropertyBuffer(vertexFormat);
                unsafe
                {
                    float *pc = (float *)Marshal.UnsafeAddrOfPinnedArrayElement(quadArray, 0);
                    IntPtr pA = new IntPtr(pc);
                    quadVertices2.SetData(pA, vertexCount);
                }
                //int length2 = Marshal.SizeOf(quadBuffer[0]);
                //IntPtr p2 = Marshal.AllocHGlobal(length2 * vertexCount);
                //quadVertices2.SetData(p2, vertexCount);

                // Create the geometry object itself
                geometry.AddVertexBuffer(circleVertices);
                geometry.AddVertexBuffer(quadVertices2);
                geometry.SetType(Geometry.Type.TRIANGLE_FAN);
            }
        }