internal MyLodMeshMerge(MyClipmap parentClipmap, int lod, int lodDivisions, ref MatrixD worldMatrix, ref Vector3D massiveCenter, float massiveRadius, RenderFlags renderFlags)
            {
                Debug.Assert(parentClipmap != null, "Parent clipmap cannot be null");
                Debug.Assert(lod >= 0, "Lod level must be non-negative");
                Debug.Assert(lodDivisions >= 0, "Invalid number of lod divisions");
                m_parentClipmap = parentClipmap;
                m_lod = lod;
                m_lodDivisions = lodDivisions;

                if (m_lodDivisions <= 0)
                    return;

                m_dirtyProxyIndices = new HashSet<int>();
                m_cellProxyToAabbProxy = new Dictionary<MyClipmapCellProxy, int>();
                m_boundingBoxes = new MyDynamicAABBTreeD(Vector3D.Zero);

                int cellCount = lodDivisions*lodDivisions*lodDivisions;
                m_mergeJobs = new MergeJobInfo[cellCount];
                m_mergedLodMeshProxies = new MyClipmapCellProxy[cellCount];
                m_trackedActors = new HashSet<MyActor>[cellCount];

                for (int divideIndex = 0; divideIndex < cellCount; ++divideIndex)
                {
                    m_mergedLodMeshProxies[divideIndex] = new MyClipmapCellProxy(new MyCellCoord(Lod, GetCellFromDivideIndex(divideIndex)), ref worldMatrix, massiveCenter, massiveRadius, renderFlags, true);
                    m_mergeJobs[divideIndex] = new MergeJobInfo { CurrentWorkId = 0, LodMeshesBeingMerged = new List<LodMeshId>(), NextPossibleMergeStartTime = MyCommon.FrameCounter };
                    m_trackedActors[divideIndex] = new HashSet<MyActor>();
                    m_dirtyProxyIndices.Add(divideIndex);
                }
            }
Ejemplo n.º 2
0
        internal MyClipmapHandler(uint id, MyClipmapScaleEnum scaleGroup, MatrixD worldMatrix, Vector3I sizeLod0, RenderFlags additionalFlags)
        {
            m_clipmapBase = new MyClipmap(id, scaleGroup, worldMatrix, sizeLod0, this);
            m_renderFlags = additionalFlags;

            MyClipmap.AddToUpdate(MyEnvironment.CameraPosition, m_clipmapBase);
        }
 public MyRenderAtmosphere(uint id, string debugName, string model, MatrixD worldMatrix, MyMeshDrawTechnique drawTechnique, RenderFlags renderFlags, float atmosphereRadius, float planetRadius, Vector3 atmosphereWavelengths)
     : base(id, debugName,model, worldMatrix,drawTechnique, renderFlags)
 {
     m_atmosphereWavelengths = atmosphereWavelengths;
     m_atmosphereRadius = atmosphereRadius;
     m_planetRadius = planetRadius;
 }
 public MyRenderBatch(uint id, string debugName, MatrixD worldMatrix, RenderFlags renderFlags, List<MyRenderBatchPart> batchParts)
     : base(id, debugName, worldMatrix, renderFlags)
 {
     m_localAABB = BoundingBoxD.CreateInvalid();
     m_batchParts.Clear();
     m_batchParts.AddList(batchParts);
 }
Ejemplo n.º 5
0
        public MyMwcVector3Int? RenderCellCoord; //Render cell coordinate if voxel
 


        public MyRenderObject(MyEntity entity, MyMwcVector3Int? renderCellCoord)
        {
            Entity = entity;
            Flags = MyElementFlag.EF_AABB_DIRTY;
            m_renderFlags = RenderFlags.SkipIfTooSmall | RenderFlags.NeedsResolveCastShadow;
            RenderCellCoord = renderCellCoord;
        }
 public MyRenderObject(uint id, string debugName, RenderFlags renderFlags = RenderFlags.Visible | RenderFlags.SkipIfTooSmall | RenderFlags.NeedsResolveCastShadow, CullingOptions cullingOptions = VRageRender.CullingOptions.Default)
     : base(id)
 {
     DebugName = debugName;
     Flags = MyElementFlag.EF_AABB_DIRTY;
     m_renderFlags = renderFlags;
     m_cullingOptions = cullingOptions;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// <see cref="ISceneRenderer.Render"/>
        /// </summary>   
        public void Render(ICameraController cam, Dictionary<Node, List<Mesh>> visibleMeshesByNode,
            bool visibleSetChanged,
            bool texturesChanged,
            RenderFlags flags, 
            Renderer renderer)
        {
            GL.Disable(EnableCap.Texture2D);
            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
            GL.Enable(EnableCap.DepthTest);
            GL.FrontFace(FrontFaceDirection.Ccw);

            if (flags.HasFlag(RenderFlags.Wireframe))
            {
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            }

            // If textures changed, we may need to upload some of them to VRAM.
            if (texturesChanged)
            {
                UploadTextures();
            }

            GL.MatrixMode(MatrixMode.Modelview);
            var view = cam == null ? Matrix4.LookAt(0, 10, 5, 0, 0, 0, 0, 1, 0) : cam.GetView();

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadMatrix(ref view);

            var tmp = InitposeMax.X - InitposeMin.X;
            tmp = Math.Max(InitposeMax.Y - InitposeMin.Y, tmp);
            tmp = Math.Max(InitposeMax.Z - InitposeMin.Z, tmp);
            tmp = 2.0f / tmp;

            var world = Matrix4.Scale(tmp);
            world *= Matrix4.CreateTranslation(-(InitposeMin + InitposeMax) * 0.5f);
            PushWorld(ref world);
            //
            var animated = Owner.SceneAnimator.IsAnimationActive;
            var needAlpha = RecursiveRender(Owner.Raw.RootNode, visibleMeshesByNode, flags, animated);
            if (flags.HasFlag(RenderFlags.ShowSkeleton) || flags.HasFlag(RenderFlags.ShowNormals))
            {
                //RecursiveRenderNoScale(Owner.Raw.RootNode, visibleMeshesByNode, flags, 1.0f / tmp, animated);
            }

            if (needAlpha)
            {
                // handle semi-transparent geometry
                RecursiveRenderWithAlpha(Owner.Raw.RootNode, visibleMeshesByNode, flags, animated);
            }
            PopWorld();

            // always switch back to FILL
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);

            GL.Disable(EnableCap.DepthTest);
            GL.Disable(EnableCap.Texture2D);
            GL.Disable(EnableCap.Lighting);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Draws the mesh geometry given the current pipeline state. 
        /// 
        /// The pipeline is restored afterwards.
        /// </summary>
        /// <param name="flags">Rendering mode</param>
        public void Render(RenderFlags flags)
        {
            GL.PushClientAttrib(ClientAttribMask.ClientVertexArrayBit);

            Debug.Assert(_vbo.VertexBufferId != 0);
            Debug.Assert(_vbo.ElementBufferId != 0);

            // normals
            if (flags.HasFlag(RenderFlags.Shaded))
            {
                if (_vbo.NormalBufferId != 0)
                {
                    GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo.NormalBufferId);
                    GL.NormalPointer(NormalPointerType.Float, Vector3.SizeInBytes, IntPtr.Zero);
                    GL.EnableClientState(ArrayCap.NormalArray);
                }
            }

            // vertex colors
            if (_vbo.ColorBufferId != 0)
            {
                GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo.ColorBufferId);
                GL.ColorPointer(4, ColorPointerType.UnsignedByte, sizeof(int), IntPtr.Zero);
                GL.EnableClientState(ArrayCap.ColorArray);
            }

            // UV coordinates
            if (flags.HasFlag(RenderFlags.Textured))
            {
                if (_vbo.TexCoordBufferId != 0)
                {
                    GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo.TexCoordBufferId);
                    GL.TexCoordPointer(2, TexCoordPointerType.Float, 8, IntPtr.Zero);
                    GL.EnableClientState(ArrayCap.TextureCoordArray);
                }
            }


            // vertex position
            GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo.VertexBufferId);
            GL.VertexPointer(3, VertexPointerType.Float, Vector3.SizeInBytes, IntPtr.Zero);
            GL.EnableClientState(ArrayCap.VertexArray);


            // primitives
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, _vbo.ElementBufferId);
            GL.DrawElements(BeginMode.Triangles, _vbo.NumIndices /* actually, count(indices) */,
                _vbo.Is32BitIndices ? DrawElementsType.UnsignedInt : DrawElementsType.UnsignedShort,
                IntPtr.Zero);

            // Restore the state
            GL.PopClientAttrib();
        }
Ejemplo n.º 9
0
		internal MyClipmapCellProxy(MyCellCoord cellCoord, ref VRageMath.MatrixD worldMatrix, RenderFlags additionalFlags = 0)
        {
            m_worldMatrix = worldMatrix;

            m_actor = MyActorFactory.CreateSceneObject();
            m_actor.SetMatrix(ref worldMatrix);
            m_actor.AddComponent(MyComponentFactory<MyFoliageComponent>.Create());

            m_lod = cellCoord.Lod;

            Mesh = MyMeshes.CreateVoxelCell(cellCoord.CoordInLod, cellCoord.Lod);
            m_actor.GetRenderable().SetModel(Mesh);
			m_actor.GetRenderable().m_additionalFlags = MyProxiesFactory.GetRenderableProxyFlags(additionalFlags);
        }
Ejemplo n.º 10
0
        internal MyClipmapHandler(uint id, MyClipmapScaleEnum scaleGroup, MatrixD worldMatrix, Vector3I sizeLod0, Vector3D massiveCenter, float massiveRadius, bool spherize, RenderFlags additionalFlags, VRage.Voxels.MyClipmap.PruningFunc prunningFunc)
        {
            m_clipmapBase = new MyClipmap(id, scaleGroup, worldMatrix, sizeLod0, this, massiveCenter, massiveRadius, prunningFunc);
            m_massiveCenter = massiveCenter;
            m_renderFlags = additionalFlags;

            if (spherize)
                m_massiveRadius = massiveRadius;

            const int mergeLodSubdivideCount = 3;
            m_mergeHandler = new MyLodMeshMergeHandler(Base, MyCellCoord.MAX_LOD_COUNT, mergeLodSubdivideCount, ref worldMatrix, ref massiveCenter, massiveRadius, m_renderFlags);

            MyClipmap.AddToUpdate(MyEnvironment.CameraPosition, Base);
        }
Ejemplo n.º 11
0
        internal MyClipmapHandler(uint id, MyClipmapScaleEnum scaleGroup, MatrixD worldMatrix, Vector3I sizeLod0, Vector3D massiveCenter, float massiveRadius, bool spherize, RenderFlags additionalFlags, VRage.Voxels.MyClipmap.PruningFunc prunningFunc)
        {
            m_clipmapBase = new MyClipmap(id, scaleGroup, worldMatrix, sizeLod0, this, massiveCenter, massiveRadius, prunningFunc);
            m_massiveCenter = massiveCenter;
            m_renderFlags = additionalFlags;
            m_mergeHandler = null;

            if (spherize)
                m_massiveRadius = massiveRadius;

            if (MyLodMeshMergeHandler.ShouldAllocate(m_mergeHandler))
                m_mergeHandler = AllocateMergeHandler();

            MyClipmap.AddToUpdate(MyEnvironment.CameraPosition, Base);
        }
        public MyRenderEntity(uint id, string debugName, string model, MatrixD worldMatrix, MyMeshDrawTechnique drawTechnique, RenderFlags renderFlags)
            : base(id, debugName, worldMatrix, renderFlags)
        {
            System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(model));

            var renderModel = AddLODs(model);
            if (renderModel != null)
            {
                m_localAABB = (BoundingBoxD)renderModel.BoundingBox;
                m_localVolume = (BoundingSphereD)renderModel.BoundingSphere;
                m_localVolumeOffset = (Vector3D)renderModel.BoundingSphere.Center;
            }

            m_drawTechnique = drawTechnique;
            m_isDataSet = true;
        }
 protected virtual void AsTextArgument(CodeWriter writer, RenderFlags flags)
 {
 }
Ejemplo n.º 14
0
    /// <summary>
    /// Renders 3D text
    /// </summary>
    public void Render3DText(string text, RenderFlags flags)
    {
        if (device == null)
        {
            throw new System.ArgumentNullException();
        }

        // Set up renderstate
        savedStateBlock.Capture();
        drawTextStateBlock.Apply();
        device.VertexFormat = CustomVertex.PositionNormalTextured.Format;
        device.PixelShader  = null;
        device.SetStreamSource(0, vertexBuffer, 0, VertexInformation.GetFormatSize(CustomVertex.PositionNormalTextured.Format));

        // Set filter states
        if ((flags & RenderFlags.Filtered) != 0)
        {
            samplerState0.MinFilter = TextureFilter.Linear;
            samplerState0.MagFilter = TextureFilter.Linear;
        }

        // Position for each text element
        float x = 0.0f;
        float y = 0.0f;

        // Center the text block at the origin
        if ((flags & RenderFlags.Centered) != 0)
        {
            System.Drawing.SizeF sz = GetTextExtent(text);
            x = -(((float)sz.Width) / 10.0f) / 2.0f;
            y = -(((float)sz.Height) / 10.0f) / 2.0f;
        }

        // Turn off culling for two-sided text
        if ((flags & RenderFlags.TwoSided) != 0)
        {
            renderState.CullMode = Cull.None;
        }

        // Adjust for character spacing
        x -= spacingPerChar / 10.0f;
        float fStartX = x;

        // Fill vertex buffer
        GraphicsStream strm         = vertexBuffer.Lock(0, 0, LockFlags.Discard);
        int            numTriangles = 0;

        foreach (char c in text)
        {
            if (c == '\n')
            {
                x  = fStartX;
                y -= (textureCoords[0, 3] - textureCoords[0, 1]) * textureHeight / 10.0f;
            }

            if ((c - 32) < 0 || (c - 32) >= 128 - 32)
            {
                continue;
            }

            float tx1 = textureCoords[c - 32, 0];
            float ty1 = textureCoords[c - 32, 1];
            float tx2 = textureCoords[c - 32, 2];
            float ty2 = textureCoords[c - 32, 3];

            float w = (tx2 - tx1) * textureWidth / (10.0f * textureScale);
            float h = (ty2 - ty1) * textureHeight / (10.0f * textureScale);

            if (c != ' ')
            {
                strm.Write(new CustomVertex.PositionNormalTextured(new Vector3(x + 0, y + 0, 0), new Vector3(0, 0, -1), tx1, ty2));
                strm.Write(new CustomVertex.PositionNormalTextured(new Vector3(x + 0, y + h, 0), new Vector3(0, 0, -1), tx1, ty1));
                strm.Write(new CustomVertex.PositionNormalTextured(new Vector3(x + w, y + 0, 0), new Vector3(0, 0, -1), tx2, ty2));
                strm.Write(new CustomVertex.PositionNormalTextured(new Vector3(x + w, y + h, 0), new Vector3(0, 0, -1), tx2, ty1));
                strm.Write(new CustomVertex.PositionNormalTextured(new Vector3(x + w, y + 0, 0), new Vector3(0, 0, -1), tx2, ty2));
                strm.Write(new CustomVertex.PositionNormalTextured(new Vector3(x + 0, y + h, 0), new Vector3(0, 0, -1), tx1, ty1));
                numTriangles += 2;

                if (numTriangles * 3 > (MaxNumfontVertices - 6))
                {
                    // Unlock, render, and relock the vertex buffer
                    vertexBuffer.Unlock();
                    device.DrawPrimitives(PrimitiveType.TriangleList, 0, numTriangles);
                    strm         = vertexBuffer.Lock(0, 0, LockFlags.Discard);
                    numTriangles = 0;
                }
            }

            x += w - (2 * spacingPerChar) / 10.0f;
        }

        // Unlock and render the vertex buffer
        vertexBuffer.Unlock();
        if (numTriangles > 0)
        {
            device.DrawPrimitives(PrimitiveType.TriangleList, 0, numTriangles);
        }

        // Restore the modified renderstates
        savedStateBlock.Apply();
    }
Ejemplo n.º 15
0
    /// <summary>
    /// Draw some text on the screen
    /// </summary>
    public void DrawText(float xpos, float ypos, Color color, string text, RenderFlags flags)
    {
        if (text == null)
        {
            return;
        }

        // Setup renderstate
        savedStateBlock.Capture();
        drawTextStateBlock.Apply();
        device.SetTexture(0, fontTexture);
        device.VertexFormat = CustomVertex.TransformedColoredTextured.Format;
        device.PixelShader  = null;
        device.SetStreamSource(0, vertexBuffer, 0);

        // Set filter states
        if ((flags & RenderFlags.Filtered) != 0)
        {
            samplerState0.MinFilter = TextureFilter.Linear;
            samplerState0.MagFilter = TextureFilter.Linear;
        }

        // Adjust for character spacing
        xpos -= spacingPerChar;
        float fStartX = xpos;

        // Fill vertex buffer
        int iv             = 0;
        int dwNumTriangles = 0;

        foreach (char c in text)
        {
            if (c == '\n')
            {
                xpos  = fStartX;
                ypos += (textureCoords[0, 3] - textureCoords[0, 1]) * textureHeight;
            }

            if ((c - 32) < 0 || (c - 32) >= 128 - 32)
            {
                continue;
            }

            float tx1 = textureCoords[c - 32, 0];
            float ty1 = textureCoords[c - 32, 1];
            float tx2 = textureCoords[c - 32, 2];
            float ty2 = textureCoords[c - 32, 3];

            float w = (tx2 - tx1) * textureWidth / textureScale;
            float h = (ty2 - ty1) * textureHeight / textureScale;

            int intColor = color.ToArgb();
            if (c != ' ')
            {
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + 0 - 0.5f, ypos + h - 0.5f, 0.9f, 1.0f), intColor, tx1, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + 0 - 0.5f, ypos + 0 - 0.5f, 0.9f, 1.0f), intColor, tx1, ty1);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + w - 0.5f, ypos + h - 0.5f, 0.9f, 1.0f), intColor, tx2, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + w - 0.5f, ypos + 0 - 0.5f, 0.9f, 1.0f), intColor, tx2, ty1);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + w - 0.5f, ypos + h - 0.5f, 0.9f, 1.0f), intColor, tx2, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + 0 - 0.5f, ypos + 0 - 0.5f, 0.9f, 1.0f), intColor, tx1, ty1);
                dwNumTriangles    += 2;

                if (dwNumTriangles * 3 > (MaxNumfontVertices - 6))
                {
                    // Set the data for the vertexbuffer
                    vertexBuffer.SetData(fontVertices, 0, LockFlags.Discard);
                    device.DrawPrimitives(PrimitiveType.TriangleList, 0, dwNumTriangles);
                    dwNumTriangles = 0;
                    iv             = 0;
                }
            }

            xpos += w - (2 * spacingPerChar);
        }

        // Set the data for the vertex buffer
        vertexBuffer.SetData(fontVertices, 0, LockFlags.Discard);
        if (dwNumTriangles > 0)
        {
            device.DrawPrimitives(PrimitiveType.TriangleList, 0, dwNumTriangles);
        }

        // Restore the modified renderstates
        savedStateBlock.Apply();
    }
Ejemplo n.º 16
0
        void RenderGraphObject(GraphObject graphObject, RenderFlags renderFlags)
        {
            // visibility check
            if (!graphObject.Visible)
            {
                return;
            }

            // render-flag check
            if (!renderFlags.HasFlag(RenderFlags.Ceilings) && graphObject.HasRenderFlag(GraphObjectRenderFlags.Ceiling))
            {
                return;
            }
            if (!renderFlags.HasFlag(RenderFlags.FourthWalls) && graphObject.HasRenderFlag(GraphObjectRenderFlags.FourthWall))
            {
                return;
            }

            // matrix transformations
            GL.PushMatrix();
            TransformMatrix(graphObject.Position, graphObject.Rotation, graphObject.Scale);

            // bounding box
            if (renderFlags.HasFlag(RenderFlags.BoundingBox))
            {
                GL.Disable(EnableCap.Lighting);
                GL.Disable(EnableCap.Texture2D);
                GL.Color3(Color.Yellow);
                GLUtility.WireCube(graphObject.BoundingBox * GlobalScaleReciprocal);
                GL.Color3(Color.White);
                GL.Enable(EnableCap.Texture2D);
                GL.Enable(EnableCap.Lighting);
            }

            if (graphObject.HasRenderFlag(GraphObjectRenderFlags.FullBright))
            {
                GL.Disable(EnableCap.Lighting);
            }

            // Render parts.
            foreach (var part in graphObject)
            {
                if (shaders[part.ShaderIndex].Tint.A > 0 && ((shaders[part.ShaderIndex].Tint.A == Color.Opaque && renderFlags.HasFlag(RenderFlags.Opaque)) || (shaders[part.ShaderIndex].Tint.A < Color.Opaque && renderFlags.HasFlag(RenderFlags.Translucent))))
                {
                    RenderPart(part, renderFlags);
                }
            }

            GL.Enable(EnableCap.Lighting);

            // Render children.
            for (int childIndex = graphObject.ChildIndex; childIndex >= 0; childIndex = graphObjects[childIndex].NextIndex)
            {
                RenderGraphObject(graphObjects[childIndex], renderFlags);
            }

            GL.PopMatrix();
        }
        /// <summary>
        /// <see cref="ISceneRenderer.Render"/>
        /// </summary>
        public void Render(ICameraController cam, Dictionary <Node, List <Mesh> > visibleMeshesByNode,
                           bool visibleSetChanged,
                           bool texturesChanged,
                           RenderFlags flags,
                           Renderer renderer)
        {
            GL.Disable(EnableCap.Texture2D);
            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
            GL.Enable(EnableCap.DepthTest);

            if (flags.HasFlag(RenderFlags.Wireframe))
            {
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            }
            var tmp = InitposeMax.X - InitposeMin.X;

            tmp = Math.Max(InitposeMax.Y - InitposeMin.Y, tmp);
            tmp = Math.Max(InitposeMax.Z - InitposeMin.Z, tmp);
            int   logScale = (int)Math.Truncate(Math.Log10(tmp * 10 / 50)); //  Up to 50units max size = 50m: keep scale (for smaller scenes).
            float scale    = 1;

            for (int i = 0; i < logScale; i++)
            {
                scale = scale / 10;
            }
            Owner.Scale = scale;
            if (cam != null)
            {
                //       cam.SetPivot(Owner.Pivot * (float)scale); this does nothing (?) only makes controller dirty
            }
            var view = cam == null?Matrix4.LookAt(0, 10, 5, 0, 0, 0, 0, 1, 0) : cam.GetView();

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadMatrix(ref view);
            GL.Scale(scale, scale, scale);
            Owner.MaterialMapper.BeginScene(renderer, flags.HasFlag(RenderFlags.UseSceneLights)); //here we switch on lights

            if (flags.HasFlag(RenderFlags.ShowLightDirection))                                    //switch off for video??
            {
                var dir = new Vector3(1, 1, 0);
                var mat = renderer.LightRotation;
                Vector3.TransformNormal(ref dir, ref mat, out dir);
                OverlayLightSource.DrawLightSource(dir);
            }

            // If textures changed, we may need to upload some of them to VRAM.
            // it is important this happens here and not accidentially while
            // compiling a displist.
            if (texturesChanged)
            {
                UploadTextures();
            }
            UploadDynamicTextures();

            GL.PushMatrix();

            // Build and cache Gl displaylists and update only when the scene changes.
            // when the scene is being animated, this changes each frame
            var animated = Owner.SceneAnimator.IsAnimationActive;

            if (visibleSetChanged || texturesChanged || flags != _lastFlags || (animated && (Owner.NewFrame) || wasAnimated))
            {
                int startList = 4; //we update only 4 animation displists
                if (visibleSetChanged || texturesChanged || flags != _lastFlags)
                {
                    startList = 0;
                }
                _lastFlags = flags;

                // handle opaque geometry
                for (int currDispList = startList; currDispList < _displayListCount; currDispList++)
                {
                    if (_displayList[currDispList, 0] == 0)
                    {
                        _displayList[currDispList, 0] = GL.GenLists(1);
                    }
                    GL.NewList(_displayList[currDispList, 0], ListMode.Compile);
                    var needAlpha = RecursiveRender(Owner.Raw.RootNode, visibleMeshesByNode, flags, animated, currDispList);
                    if (flags.HasFlag(RenderFlags.ShowSkeleton))
                    {
                        RecursiveRenderNoScale(Owner.Raw.RootNode, visibleMeshesByNode, flags, 1.0f / scale, animated, currDispList);
                    }
                    if (flags.HasFlag(RenderFlags.ShowNormals))
                    {
                        RecursiveRenderNormals(Owner.Raw.RootNode, visibleMeshesByNode, flags, 1.0f / scale, animated, Matrix4.Identity, currDispList);
                    }
                    GL.EndList();
                    if (needAlpha)
                    {
                        // handle semi-transparent geometry
                        if (_displayList[currDispList, 1] == 0)
                        {
                            _displayList[currDispList, 1] = GL.GenLists(1);
                        }
                        GL.NewList(_displayList[currDispList, 1], ListMode.Compile);
                        RecursiveRenderWithAlpha(Owner.Raw.RootNode, visibleMeshesByNode, flags, animated, currDispList);
                        GL.EndList();
                    }
                    else if (_displayList[currDispList, 1] != 0)
                    {
                        GL.DeleteLists(_displayList[currDispList, 1], 1);
                        _displayList[currDispList, 1] = 0;
                    }
                }
            }

            Owner.NewFrame = false;
            wasAnimated    = animated;

            /* display lists:
             * 0: Background;
             * 1: Else (always visible);
             * 2: Foreground;
             * 3: GreenScreen;
             * 4: BackgroundAnimated;
             * 5: ElseAnimated (always visible);
             * 6: ForegroundAnimated;
             * 7: GreenScreenAnimated;
             * Animated - list is refreshed each frame
             */
            switch (cam.GetScenePartMode())
            {
            case ScenePartMode.Background:
                if (_displayList[0, 0] != 0)
                {
                    GL.CallList(_displayList[0, 0]);
                }
                if (_displayList[4, 0] != 0)
                {
                    GL.CallList(_displayList[4, 0]);
                }
                if (_displayList[0, 1] != 0)
                {
                    GL.CallList(_displayList[0, 1]);
                }
                if (_displayList[4, 1] != 0)
                {
                    GL.CallList(_displayList[4, 1]);
                }
                break;

            case ScenePartMode.Foreground:
                if (_displayList[2, 0] != 0)
                {
                    GL.CallList(_displayList[2, 0]);
                }
                if (_displayList[6, 0] != 0)
                {
                    GL.CallList(_displayList[6, 0]);
                }
                if (_displayList[2, 1] != 0)
                {
                    GL.CallList(_displayList[2, 1]);
                }
                if (_displayList[6, 1] != 0)
                {
                    GL.CallList(_displayList[6, 1]);
                }
                break;

            case ScenePartMode.Others:
                if (_displayList[1, 0] != 0)
                {
                    GL.CallList(_displayList[1, 0]);
                }
                if (_displayList[5, 0] != 0)
                {
                    GL.CallList(_displayList[5, 0]);
                }
                if (_displayList[1, 1] != 0)
                {
                    GL.CallList(_displayList[1, 1]);
                }
                if (_displayList[5, 1] != 0)
                {
                    GL.CallList(_displayList[5, 1]);
                }
                break;

            case ScenePartMode.GreenScreen:
                if (_displayList[3, 0] != 0)
                {
                    GL.CallList(_displayList[3, 0]);
                }
                if (_displayList[7, 0] != 0)
                {
                    GL.CallList(_displayList[7, 0]);
                }
                if (_displayList[3, 1] != 0)
                {
                    GL.CallList(_displayList[3, 1]);
                }
                if (_displayList[7, 1] != 0)
                {
                    GL.CallList(_displayList[7, 1]);
                }
                break;

            case ScenePartMode.All:
                for (int currDispList = 0; currDispList < _displayListCount; currDispList++)
                {
                    if (_displayList[currDispList, 0] != 0)
                    {
                        GL.CallList(_displayList[currDispList, 0]);
                    }
                    if (_displayList[currDispList, 1] != 0)
                    {
                        GL.CallList(_displayList[currDispList, 1]);
                    }
                }
                break;

            default: break;    //at other modes we do not render anything
            }

            GL.PopMatrix();
            // always switch back to FILL
            Owner.MaterialMapper.EndScene(renderer);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.Disable(EnableCap.DepthTest);

#if TEST
            GL.Enable(EnableCap.ColorMaterial);


            // TEST CODE to visualize mid point (pivot) and origin
            GL.LoadMatrix(ref view);
            GL.Begin(BeginMode.Lines);

            GL.Vertex3((InitposeMin + InitposeMax) * 0.5f * (float)scale);
            GL.Color3(0.0f, 1.0f, 0.0f);
            GL.Vertex3(0, 0, 0);
            GL.Color3(0.0f, 1.0f, 0.0f);
            GL.Vertex3((InitposeMin + InitposeMax) * 0.5f * (float)scale);
            GL.Color3(0.0f, 1.0f, 0.0f);

            GL.Vertex3(10, 10, 10);
            GL.Color3(0.0f, 1.0f, 0.0f);
            GL.End();
#endif
            GL.Disable(EnableCap.Texture2D);
        }
Ejemplo n.º 18
0
        public static uint CreateClipmap(
            MatrixD worldMatrix,
            Vector3I sizeLod0,
            MyClipmapScaleEnum scaleGroup,
            Vector3D position,
            float atmosphereRadius = 0.0f,
            float planetRadius = 0.0f,
            bool hasAtmosphere = false,
            Vector3? atmosphereWaveLenghts = null,
            bool spherizeWithDistance = true,
			RenderFlags additionalFlags = 0,
            VRage.Voxels.MyClipmap.PruningFunc prunningFunc = null)
        {
            var message = MessagePool.Get<MyRenderMessageCreateClipmap>(MyRenderMessageEnum.CreateClipmap);

            uint clipmapId = GetMessageId();
            message.ClipmapId = clipmapId;
            message.WorldMatrix = worldMatrix;
            message.SizeLod0 = sizeLod0;
            message.ScaleGroup = scaleGroup;
            message.AtmosphereRadius = atmosphereRadius;
            message.PlanetRadius = planetRadius;
            message.HasAtmosphere = hasAtmosphere;
            message.Position = position;
            message.AtmosphereWaveLenghts = atmosphereWaveLenghts;
            message.SpherizeWithDistance = spherizeWithDistance;
			message.AdditionalRenderFlags = additionalFlags;
            message.PrunningFunc = prunningFunc;
            EnqueueMessage(message);

            return clipmapId;
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Convert operator to text.
 /// </summary>
 protected virtual void AsTextOperator(CodeWriter writer, RenderFlags flags)
 {
     writer.Write(Symbol);
 }
Ejemplo n.º 20
0
        public static uint CreateRenderEntity(
            string debugName,
            string model,
            MatrixD worldMatrix,
            MyMeshDrawTechnique technique,
            RenderFlags flags,
            CullingOptions cullingOptions,
            Color diffuseColor,
            Vector3 colorMaskHsv,
            float dithering = 0,
            float maxViewDistance = float.MaxValue,
            byte depthBias = 0
            )
        {
            var message = MessagePool.Get<MyRenderMessageCreateRenderEntity>(MyRenderMessageEnum.CreateRenderEntity);

            uint id = GetMessageId();
            message.ID = id;
            message.DebugName = debugName;
            message.Model = model;
            message.WorldMatrix = worldMatrix;
            message.Technique = technique;
            message.Flags = flags;
            message.CullingOptions = cullingOptions;
            message.MaxViewDistance = maxViewDistance;
            message.DepthBias = depthBias;

            EnqueueMessage(message);

            UpdateRenderEntity(id, diffuseColor, colorMaskHsv, dithering);

            return id;
        }
Ejemplo n.º 21
0
        public static uint CreateRenderBatch(
            string debugName,
            MatrixD worldMatrix,
            RenderFlags flags,
            List<MyRenderBatchPart> batchParts)
        {
            var message = MessagePool.Get<MyRenderMessageCreateRenderBatch>(MyRenderMessageEnum.CreateRenderBatch);

            uint id = GetMessageId();
            message.ID = id;
            message.DebugName = debugName;
            message.WorldMatrix = worldMatrix;
            message.Flags = flags;
            message.RenderBatchParts.Clear();
            message.RenderBatchParts.AddList(batchParts);

            EnqueueMessage(message);

            return id;
        }
Ejemplo n.º 22
0
        public static uint CreateRenderEntityAtmosphere(
          string debugName,
          string model,
          MatrixD worldMatrix,
          MyMeshDrawTechnique technique,
          RenderFlags flags,
          CullingOptions cullingOptions,
          float atmosphereRadius,
          float planetRadius,
          Vector3 atmosphereWavelengths,
          float dithering = 0,
          float maxViewDistance = float.MaxValue
          )
        {
            var message = MessagePool.Get<MyRenderMessageCreateRenderEntityAtmosphere>(MyRenderMessageEnum.CreateRenderEntityAtmosphere);

            uint id = GetMessageId();
            message.ID = id;
            message.DebugName = debugName;
            message.Model = model;
            message.WorldMatrix = worldMatrix;
            message.Technique = technique;
            message.Flags = flags;
            message.CullingOptions = cullingOptions;
            message.MaxViewDistance = maxViewDistance;
            message.AtmosphereRadius = atmosphereRadius;
            message.PlanetRadius = planetRadius;
            message.AtmosphereWavelengths = atmosphereWavelengths;

            EnqueueMessage(message);

            UpdateRenderEntity(id, Vector3.Zero, Vector3.Zero, dithering);

            return id;
        }
Ejemplo n.º 23
0
		public static uint CreateRenderEntityCloudLayer(
			string debugName,
			string model,
            List<string> textures,
			Vector3D centerPoint,
			double altitude,
			double minScaledAltitude,
			bool scalingEnabled,
			double fadeOutRelativeAltitudeStart,
			double fadeOutRelativeAltitudeEnd,
			float applyFogRelativeDistance,
			double maxPlanetHillRadius,
			MyMeshDrawTechnique technique,
			RenderFlags flags,
			CullingOptions cullingOptions,
			Vector3D rotationAxis,
			float angularVelocity,
			float initialRotation
			)
		{
			var message = MessagePool.Get<MyRenderMessageCreateRenderEntityClouds>(MyRenderMessageEnum.CreateRenderEntityClouds);

			uint id = GetMessageId();
			message.ID = id;
			message.Model = model;
		    message.Textures = textures;
			message.CenterPoint = centerPoint;
			message.Altitude = altitude;
			message.MinScaledAltitude = minScaledAltitude;
			message.ScalingEnabled = scalingEnabled;
			message.DebugName = debugName;
			message.Technique = technique;
			message.RotationAxis = rotationAxis;
			message.AngularVelocity = angularVelocity;
			message.InitialRotation = initialRotation;
			message.MaxPlanetHillRadius = maxPlanetHillRadius;
			message.FadeOutRelativeAltitudeStart = fadeOutRelativeAltitudeStart;
			message.FadeOutRelativeAltitudeEnd = fadeOutRelativeAltitudeEnd;
			message.ApplyFogRelativeDistance = applyFogRelativeDistance;

			EnqueueMessage(message);

			UpdateRenderEntity(id, null, null);

			return id;
		}
Ejemplo n.º 24
0
        public static uint CreateRenderCharacter(
         string debugName,
         string lod0,
         MatrixD worldMatrix,
         Color? diffuseColor,
         Vector3? colorMaskHSV,
         RenderFlags flags
         )
        {
            var message = MessagePool.Get<MyRenderMessageCreateRenderCharacter>(MyRenderMessageEnum.CreateRenderCharacter);

            uint id = GetMessageId();
            message.ID = id;
            message.DebugName = debugName;
            message.Model = lod0;
            message.WorldMatrix = worldMatrix;
            message.DiffuseColor = diffuseColor;
            message.ColorMaskHSV = colorMaskHSV;
            message.Flags = flags;

            EnqueueMessage(message);

            UpdateRenderEntity(id, diffuseColor, colorMaskHSV);

            return id;
        }
Ejemplo n.º 25
0
 public MyRenderEntity(uint id, string debugName, MatrixD worldMatrix, MyMeshDrawTechnique drawTechnique, RenderFlags renderFlags)
     : base(id, debugName, worldMatrix, renderFlags)
 {
     m_drawTechnique = drawTechnique;
     m_isDataSet     = false;
 }
 public MyRenderAtmosphere(uint id, string debugName, MatrixD worldMatrix, MyMeshDrawTechnique drawTechnique, RenderFlags renderFlags)
     : base(id, debugName, worldMatrix,drawTechnique, renderFlags)
 {
 }
        internal MyClipmapCellProxy(MyCellCoord cellCoord, ref MatrixD worldMatrix, Vector3D massiveCenter, float massiveRadius, RenderFlags additionalFlags = 0, bool mergedMesh = false)
        {
            m_worldMatrix = worldMatrix;

            m_actor = MyActorFactory.CreateVoxelCell();
            m_actor.SetMatrix(ref worldMatrix);

            m_lod = cellCoord.Lod;

            MyVoxelRenderableComponent renderableComponent = m_actor.GetRenderable() as MyVoxelRenderableComponent;

            m_mesh = !mergedMesh ? MyMeshes.CreateVoxelCell(cellCoord.CoordInLod, cellCoord.Lod) : MyMeshes.CreateMergedVoxelCell(cellCoord.CoordInLod, cellCoord.Lod);
            renderableComponent.SetVoxelLod(m_lod, ScaleGroup);
            renderableComponent.SetModel(m_mesh);
            renderableComponent.m_massiveCenter = massiveCenter;
            renderableComponent.m_massiveRadius = massiveRadius;
            renderableComponent.m_additionalFlags = MyProxiesFactory.GetRenderableProxyFlags(additionalFlags);
        }
Ejemplo n.º 28
0
 private unsafe void UpdateRenderEntitiesInstanceData(RenderFlags renderFlags, uint parentCullObject)
 {
     foreach (KeyValuePair <MyInstanceBucket, MyRenderInstanceInfo> pair in this.m_instanceInfo)
     {
         uint num;
         bool inScene;
         int  num1;
         bool flag = this.m_instanceGroupRenderObjects.TryGetValue(pair.Key, out num);
         if (pair.Value.InstanceCount <= 0)
         {
             inScene = false;
         }
         else
         {
             IMyEntity entity = this.m_gridRenderComponent.Entity;
             if (entity != null)
             {
                 inScene = entity.InScene;
             }
             else
             {
                 IMyEntity local1 = entity;
                 inScene = false;
             }
         }
         bool        flag2 = (bool)num1;
         RenderFlags flags = renderFlags;
         if (!(!flag & flag2))
         {
             if (flag && !flag2)
             {
                 uint renderObjectId = this.m_instanceGroupRenderObjects[pair.Key];
                 this.RemoveRenderObjectId(!MyFakes.MANUAL_CULL_OBJECTS, ref renderObjectId, MyRenderProxy.ObjectType.Entity);
                 this.m_instanceGroupRenderObjects.Remove(pair.Key);
                 continue;
             }
         }
         else
         {
             uint *   numPtr1;
             object[] objArray1 = new object[] { "CubeGridRenderCell ", this.m_gridRenderComponent.Container.Entity.DisplayName, " ", this.m_gridRenderComponent.Container.Entity.EntityId, ", part: ", pair.Key };
             this.AddRenderObjectId(!MyFakes.MANUAL_CULL_OBJECTS, out (uint)ref numPtr1, MyRenderProxy.CreateRenderEntity(string.Concat(objArray1), MyModel.GetById(pair.Key.ModelId), this.m_gridRenderComponent.Container.Entity.PositionComp.WorldMatrix, MyMeshDrawTechnique.MESH, flags, CullingOptions.Default, this.m_gridRenderComponent.GetDiffuseColor(), Vector3.Zero, this.m_gridRenderComponent.Transparency, pair.Value.MaxViewDistance, 0, this.m_gridRenderComponent.CubeGrid.GridScale, (this.m_gridRenderComponent.Transparency == 0f) && this.m_gridRenderComponent.FadeIn));
             if (pair.Key.SkinSubtypeId != MyStringHash.NullOrEmpty)
             {
                 Dictionary <string, MyTextureChange> assetModifierDefinitionForRender = MyDefinitionManager.Static.GetAssetModifierDefinitionForRender(pair.Key.SkinSubtypeId);
                 if (assetModifierDefinitionForRender != null)
                 {
                     numPtr1 = (uint *)ref num;
                     MyRenderProxy.ChangeMaterialTexture(num, assetModifierDefinitionForRender);
                 }
             }
             this.m_instanceGroupRenderObjects[pair.Key] = num;
             if (MyFakes.MANUAL_CULL_OBJECTS)
             {
                 MyRenderProxy.SetParentCullObject(num, parentCullObject, new Matrix?(Matrix.Identity));
             }
         }
         if (flag2)
         {
             MyRenderProxy.SetInstanceBuffer(num, pair.Value.InstanceBufferId, pair.Value.InstanceStart, pair.Value.InstanceCount, this.m_boundingBox, null);
         }
     }
 }
Ejemplo n.º 29
0
 public void RebuildDirtyCells(RenderFlags renderFlags)
 {
     ++m_rebuildDirtyCounter;
     if (m_rebuildDirtyCounter < m_nextRebuildDirtyCount || m_dirtyCells.Count == 0)
         return;
     m_nextRebuildDirtyCount = m_rebuildDirtyCounter + 10; // change if stuttering is still noticable
     foreach (var cell in m_dirtyCells)
     {
         ProfilerShort.Begin("Cell rebuild");
         cell.RebuildInstanceParts(renderFlags);
         ProfilerShort.End();
     }
     m_dirtyCells.Clear();
 }
Ejemplo n.º 30
0
        private void UpdateRenderInstanceData(Dictionary <MyInstanceBucket, Tuple <List <MyCubeInstanceMergedData>, Sandbox.Game.Entities.Cube.MyInstanceInfo> > instanceParts, RenderFlags renderFlags)
        {
            if (this.m_parentCullObject == uint.MaxValue)
            {
                object[] objArray1 = new object[] { this.m_gridRenderComponent.Container.Entity.DisplayName, " ", this.m_gridRenderComponent.Container.Entity.EntityId, ", cull object" };
                this.AddRenderObjectId(true, out this.m_parentCullObject, MyRenderProxy.CreateManualCullObject(string.Concat(objArray1), this.m_gridRenderComponent.Container.Entity.PositionComp.WorldMatrix));
            }
            if (this.m_instanceBufferId == uint.MaxValue)
            {
                object[] objArray2 = new object[] { this.m_gridRenderComponent.Container.Entity.DisplayName, " ", this.m_gridRenderComponent.Container.Entity.EntityId, ", instance buffer ", this.DebugName };
                this.AddRenderObjectId(false, out this.m_instanceBufferId, MyRenderProxy.CreateRenderInstanceBuffer(string.Concat(objArray2), MyRenderInstanceBufferType.Cube, this.m_gridRenderComponent.GetRenderObjectID()));
            }
            this.m_instanceInfo.Clear();
            m_tmpDecalData.AssertEmpty <MyCubeInstanceDecalData>();
            m_tmpInstanceData.AssertEmpty <MyCubeInstanceData>();
            int num = -1;

            foreach (KeyValuePair <MyInstanceBucket, Tuple <List <MyCubeInstanceMergedData>, Sandbox.Game.Entities.Cube.MyInstanceInfo> > pair in instanceParts)
            {
                MyInstanceBucket key = pair.Key;
                Tuple <List <MyCubeInstanceMergedData>, Sandbox.Game.Entities.Cube.MyInstanceInfo> tuple = pair.Value;
                this.m_instanceInfo.Add(key, new MyRenderInstanceInfo(this.m_instanceBufferId, m_tmpInstanceData.Count, tuple.Item1.Count, tuple.Item2.MaxViewDistance, tuple.Item2.Flags));
                List <MyCubeInstanceMergedData> list = tuple.Item1;
                for (int i = 0; i < list.Count; i++)
                {
                    num++;
                    m_tmpInstanceData.Add(list[i].CubeInstanceData);
                    ConcurrentDictionary <uint, bool> decals = list[i].Decals;
                    if (decals != null)
                    {
                        foreach (uint num3 in decals.Keys)
                        {
                            MyCubeInstanceDecalData item = new MyCubeInstanceDecalData {
                                DecalId       = num3,
                                InstanceIndex = num
                            };
                            m_tmpDecalData.Add(item);
                        }
                    }
                }
            }
            if (m_tmpInstanceData.Count > 0)
            {
                MyRenderProxy.UpdateRenderCubeInstanceBuffer(this.m_instanceBufferId, ref m_tmpInstanceData, (int)(m_tmpInstanceData.Count * 1.2f), ref m_tmpDecalData);
            }
            m_tmpDecalData.AssertEmpty <MyCubeInstanceDecalData>();
            m_tmpInstanceData.AssertEmpty <MyCubeInstanceData>();
            this.UpdateRenderEntitiesInstanceData(renderFlags, this.m_parentCullObject);
        }
Ejemplo n.º 31
0
        public void Render(RenderFlags renderFlags)
        {
            GL.PushMatrix();

            // Render all root graph objects.
            for (int index = 0; index >= 0; index = graphObjects[index].NextIndex)
            {
                RenderGraphObject(graphObjects[index], renderFlags);
            }

            GL.PopMatrix();
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Process existing pages
        /// </summary>
        /// <returns>Null if page still painting, PdfBitmap object if page successfully rendered.</returns>
        private bool ProcessExisting(PdfBitmap bitmap, PdfPage page, Int32Rect pageRect, PageRotate pageRotate, RenderFlags renderFlags)
        {
            switch (this[page].status)
            {
            case ProgressiveRenderingStatuses.RenderReader:
                this[page].status = page.StartProgressiveRender(bitmap, pageRect.X, pageRect.Y, pageRect.Width, pageRect.Height, pageRotate, renderFlags, null);
                if (this[page].status == ProgressiveRenderingStatuses.RenderDone)
                {
                    return(true);
                }
                return(false);                        //Start rendering. Return nothing.

            case ProgressiveRenderingStatuses.RenderDone:
                page.CancelProgressiveRender();
                this[page].status = ProgressiveRenderingStatuses.RenderDone + 2;
                return(true);                        //Stop rendering. Return image.

            case ProgressiveRenderingStatuses.RenderDone + 2:
                return(true);                        //Rendering already stoped. return image

            case ProgressiveRenderingStatuses.RenderDone + 3:
                this[page].status = ProgressiveRenderingStatuses.RenderDone + 2;
                page.RenderEx(bitmap, pageRect.X, pageRect.Y, pageRect.Width, pageRect.Height, pageRotate, renderFlags);
                return(true);                        //Rendering in non progressive mode

            case ProgressiveRenderingStatuses.RenderDone + 4:
                this[page].status = ProgressiveRenderingStatuses.RenderDone + 2;
                DrawThumbnail(bitmap, page, pageRect, pageRotate, renderFlags);
                return(true);                        //Rendering thumbnails

            case ProgressiveRenderingStatuses.RenderTobeContinued:
                this[page].status = page.ContinueProgressiveRender();
                return(false);                        //Continue rendering. Return nothing.

            case ProgressiveRenderingStatuses.RenderFailed:
            default:
                bitmap.FillRectEx(pageRect.X, pageRect.Y, pageRect.Width, pageRect.Height, Helpers.ToArgb(Colors.Red));
                bitmap.FillRectEx(pageRect.X + 5, pageRect.Y + 5, pageRect.Width - 10, pageRect.Height - 10, Helpers.ToArgb(Colors.White));
                page.CancelProgressiveRender();
                this[page].status = ProgressiveRenderingStatuses.RenderDone + 2;
                return(true);                        //An error has occurred. Stop rendering. return special image
            }
        }
Ejemplo n.º 33
0
        void RenderPart(Part part, RenderFlags renderFlags)
        {
            GL.Material(MaterialFace.Front, MaterialParameter.Diffuse, shaders[part.ShaderIndex].Tint.ToColor4());
            var batch = batches[part.BatchIndex];

            if (batch.UseNBT) // Render with bump map.
            {
                int binormalAttribute = GL.GetAttribLocation(Program.EmbossProgram, "inBinormal");
                int tangentAttribute = GL.GetAttribLocation(Program.EmbossProgram, "inTangent");
                int diffuseMap = GL.GetUniformLocation(Program.EmbossProgram, "diffuseMap");
                int bumpMap = GL.GetUniformLocation(Program.EmbossProgram, "bumpMap");
                int embossFactor = GL.GetUniformLocation(Program.EmbossProgram, "embossScale");

                Program.EmbossProgram.Use();

                GL.ActiveTexture(TextureUnit.Texture0 + 0);
                GL.Enable(EnableCap.Texture2D);
                GL.BindTexture(TextureTarget.Texture2D, glTextures[materials[shaders[part.ShaderIndex].MaterialIndex[0]].textureIndex]);
                GLUtility.SetTexture2DWrapModeS(materials[shaders[part.ShaderIndex].MaterialIndex[0]].wrapS);
                GLUtility.SetTexture2DWrapModeT(materials[shaders[part.ShaderIndex].MaterialIndex[0]].wrapT);
                GL.Uniform1(diffuseMap, 0);

                GL.ActiveTexture(TextureUnit.Texture0 + 1);
                GL.Enable(EnableCap.Texture2D);
                GL.BindTexture(TextureTarget.Texture2D, glTextures[materials[shaders[part.ShaderIndex].MaterialIndex[1]].textureIndex]);
                GLUtility.SetTexture2DWrapModeS(materials[shaders[part.ShaderIndex].MaterialIndex[1]].wrapS);
                GLUtility.SetTexture2DWrapModeT(materials[shaders[part.ShaderIndex].MaterialIndex[1]].wrapT);
                GL.Uniform1(bumpMap, 1);

                GL.Uniform1(embossFactor, 2.0f);

                foreach (var primitive in batch)
                {
                    GL.Begin(primitive.GLType);

                    foreach (var vertex in primitive)
                    {
                        GL.MultiTexCoord2(TextureUnit.Texture0 + 0, ref texCoord0s[vertex.UVIndex[0].Value]);
                        GL.MultiTexCoord2(TextureUnit.Texture0 + 1, ref texCoord1s[vertex.UVIndex[1].Value]);
                        GL.Normal3(normals[vertex.NormalIndex.Value]);
                        GL.VertexAttrib3(tangentAttribute, ref normals[vertex.BinormalIndex.Value + 1]);
                        GL.VertexAttrib3(binormalAttribute, ref normals[vertex.TangentIndex.Value + 2]);
                        GL.Vertex3(positions[vertex.PositionIndex.Value]);
                    }

                    GL.End();
                }

                GL.UseProgram(0);
            }
            else // Render without bump map.
            {
                for (int texUnit = 0; texUnit < 8; texUnit++)
                {
                    if (shaders[part.ShaderIndex].MaterialIndex[texUnit] < 0)
                    {
                        continue;
                    }

                    var material = materials[shaders[part.ShaderIndex].MaterialIndex[texUnit]];
                    GL.ActiveTexture(TextureUnit.Texture0 + texUnit);
                    GL.Enable(EnableCap.Texture2D);
                    GL.BindTexture(TextureTarget.Texture2D, glTextures[material.textureIndex]);
                    GLUtility.SetTexture2DWrapModeS(material.wrapS);
                    GLUtility.SetTexture2DWrapModeT(material.wrapT);
                }

                foreach (var primitive in batch)
                {
                    GL.Begin(primitive.GLType);

                    foreach (var vertex in primitive)
                    {
                        if (vertex.UVIndex[0] != null)
                        {
                            GL.MultiTexCoord2(TextureUnit.Texture0, ref texCoord0s[vertex.UVIndex[0].Value]);
                        }

                        if (vertex.NormalIndex != null)
                        {
                            GL.Normal3(normals[vertex.NormalIndex.Value]);
                        }

                        GL.Vertex3(positions[vertex.PositionIndex.Value]);
                    }

                    GL.End();
                }
            }

            GLUtility.DisableTexture2D();

            // normals
            if (renderFlags.HasFlag(RenderFlags.NBT))
            {
                const float normalLength = 0.0625f;

                GL.Disable(EnableCap.Lighting);
                GL.Begin(BeginMode.Lines);

                foreach (var primitive in batch)
                {
                    foreach (var vertex in primitive)
                    {
                        if (vertex.NormalIndex != null)
                        {
                            GL.Color4(Color.Red.ToColor4());
                            GL.Vertex3(positions[vertex.PositionIndex.Value]);
                            GL.Vertex3(positions[vertex.PositionIndex.Value] + normals[vertex.NormalIndex.Value] * normalLength);
                        }

                        if (vertex.TangentIndex != null)
                        {
                            GL.Color4(Color.Green.ToColor4());
                            GL.Vertex3(positions[vertex.PositionIndex.Value]);
                            GL.Vertex3(positions[vertex.PositionIndex.Value] + normals[vertex.TangentIndex.Value + 2] * normalLength);
                        }

                        if (vertex.BinormalIndex != null)
                        {
                            GL.Color4(Color.Blue.ToColor4());
                            GL.Vertex3(positions[vertex.PositionIndex.Value]);
                            GL.Vertex3(positions[vertex.PositionIndex.Value] + normals[vertex.BinormalIndex.Value + 1] * normalLength);
                        }
                    }
                }

                GL.End();
                GL.Enable(EnableCap.Lighting);
            }
        }
Ejemplo n.º 34
0
        void RenderPart(Part part, RenderFlags renderFlags)
        {
            GL.Material(MaterialFace.Front, MaterialParameter.Diffuse, shaders[part.ShaderIndex].Tint.ToColor4());
            var batch = batches[part.BatchIndex];

            if (batch.UseNBT)             // Render with bump map.
            {
                int binormalAttribute = GL.GetAttribLocation(Program.EmbossProgram, "inBinormal");
                int tangentAttribute  = GL.GetAttribLocation(Program.EmbossProgram, "inTangent");
                int diffuseMap        = GL.GetUniformLocation(Program.EmbossProgram, "diffuseMap");
                int bumpMap           = GL.GetUniformLocation(Program.EmbossProgram, "bumpMap");
                int embossFactor      = GL.GetUniformLocation(Program.EmbossProgram, "embossScale");

                Program.EmbossProgram.Use();

                GL.ActiveTexture(TextureUnit.Texture0 + 0);
                GL.Enable(EnableCap.Texture2D);
                GL.BindTexture(TextureTarget.Texture2D, glTextures[materials[shaders[part.ShaderIndex].MaterialIndex[0]].textureIndex]);
                GLUtility.SetTexture2DWrapModeS(materials[shaders[part.ShaderIndex].MaterialIndex[0]].wrapS);
                GLUtility.SetTexture2DWrapModeT(materials[shaders[part.ShaderIndex].MaterialIndex[0]].wrapT);
                GL.Uniform1(diffuseMap, 0);

                GL.ActiveTexture(TextureUnit.Texture0 + 1);
                GL.Enable(EnableCap.Texture2D);
                GL.BindTexture(TextureTarget.Texture2D, glTextures[materials[shaders[part.ShaderIndex].MaterialIndex[1]].textureIndex]);
                GLUtility.SetTexture2DWrapModeS(materials[shaders[part.ShaderIndex].MaterialIndex[1]].wrapS);
                GLUtility.SetTexture2DWrapModeT(materials[shaders[part.ShaderIndex].MaterialIndex[1]].wrapT);
                GL.Uniform1(bumpMap, 1);

                GL.Uniform1(embossFactor, 2.0f);

                foreach (var primitive in batch)
                {
                    GL.Begin(primitive.GLType);

                    foreach (var vertex in primitive)
                    {
                        GL.MultiTexCoord2(TextureUnit.Texture0 + 0, ref texCoord0s[vertex.UVIndex[0].Value]);
                        GL.MultiTexCoord2(TextureUnit.Texture0 + 1, ref texCoord1s[vertex.UVIndex[1].Value]);
                        GL.Normal3(normals[vertex.NormalIndex.Value]);
                        GL.VertexAttrib3(tangentAttribute, ref normals[vertex.BinormalIndex.Value + 1]);
                        GL.VertexAttrib3(binormalAttribute, ref normals[vertex.TangentIndex.Value + 2]);
                        GL.Vertex3(positions[vertex.PositionIndex.Value]);
                    }

                    GL.End();
                }

                GL.UseProgram(0);
            }
            else             // Render without bump map.
            {
                for (int texUnit = 0; texUnit < 8; texUnit++)
                {
                    if (shaders[part.ShaderIndex].MaterialIndex[texUnit] < 0)
                    {
                        continue;
                    }

                    var material = materials[shaders[part.ShaderIndex].MaterialIndex[texUnit]];
                    GL.ActiveTexture(TextureUnit.Texture0 + texUnit);
                    GL.Enable(EnableCap.Texture2D);
                    GL.BindTexture(TextureTarget.Texture2D, glTextures[material.textureIndex]);
                    GLUtility.SetTexture2DWrapModeS(material.wrapS);
                    GLUtility.SetTexture2DWrapModeT(material.wrapT);
                }

                foreach (var primitive in batch)
                {
                    GL.Begin(primitive.GLType);

                    foreach (var vertex in primitive)
                    {
                        if (vertex.UVIndex[0] != null)
                        {
                            GL.MultiTexCoord2(TextureUnit.Texture0, ref texCoord0s[vertex.UVIndex[0].Value]);
                        }

                        if (vertex.NormalIndex != null)
                        {
                            GL.Normal3(normals[vertex.NormalIndex.Value]);
                        }

                        GL.Vertex3(positions[vertex.PositionIndex.Value]);
                    }

                    GL.End();
                }
            }

            GLUtility.DisableTexture2D();

            // normals
            if (renderFlags.HasFlag(RenderFlags.NBT))
            {
                const float normalLength = 0.0625f;

                GL.Disable(EnableCap.Lighting);
                GL.Begin(BeginMode.Lines);

                foreach (var primitive in batch)
                {
                    foreach (var vertex in primitive)
                    {
                        if (vertex.NormalIndex != null)
                        {
                            GL.Color4(Color.Red.ToColor4());
                            GL.Vertex3(positions[vertex.PositionIndex.Value]);
                            GL.Vertex3(positions[vertex.PositionIndex.Value] + normals[vertex.NormalIndex.Value] * normalLength);
                        }

                        if (vertex.TangentIndex != null)
                        {
                            GL.Color4(Color.Green.ToColor4());
                            GL.Vertex3(positions[vertex.PositionIndex.Value]);
                            GL.Vertex3(positions[vertex.PositionIndex.Value] + normals[vertex.TangentIndex.Value + 2] * normalLength);
                        }

                        if (vertex.BinormalIndex != null)
                        {
                            GL.Color4(Color.Blue.ToColor4());
                            GL.Vertex3(positions[vertex.PositionIndex.Value]);
                            GL.Vertex3(positions[vertex.PositionIndex.Value] + normals[vertex.BinormalIndex.Value + 1] * normalLength);
                        }
                    }
                }

                GL.End();
                GL.Enable(EnableCap.Lighting);
            }
        }
 public MyRenderEntity(uint id, string debugName, MatrixD worldMatrix, MyMeshDrawTechnique drawTechnique, RenderFlags renderFlags)
     : base(id, debugName, worldMatrix, renderFlags)
 {
     m_drawTechnique = drawTechnique;
     m_isDataSet = false;
 }
Ejemplo n.º 36
0
        protected override bool DrawMesh(Node node, bool animated, bool showGhost, int index, Mesh mesh, RenderFlags flags)
        {
            if (_meshes[index] == null)
            {
                _meshes[index] = new RenderMesh(mesh);
            }

            _meshes[index].Render(flags);

            return(true);
        }
Ejemplo n.º 37
0
    /// <summary>
    /// Draws scaled 2D text.  Note that x and y are in viewport coordinates
    /// (ranging from -1 to +1).  fXScale and fYScale are the size fraction
    /// relative to the entire viewport.  For example, a fXScale of 0.25 is
    /// 1/8th of the screen width.  This allows you to output text at a fixed
    /// fraction of the viewport, even if the screen or window size changes.
    /// </summary>
    public void DrawTextScaled(float x, float y, float z,
                               float fXScale, float fYScale,
                               System.Drawing.Color color,
                               string text, RenderFlags flags)
    {
        if (device == null)
        {
            throw new System.ArgumentNullException();
        }

        // Set up renderstate
        savedStateBlock.Capture();
        drawTextStateBlock.Apply();
        device.VertexFormat = CustomVertex.TransformedColoredTextured.Format;
        device.PixelShader  = null;
        device.SetStreamSource(0, vertexBuffer, 0);

        // Set filter states
        if ((flags & RenderFlags.Filtered) != 0)
        {
            samplerState0.MinFilter = TextureFilter.Linear;
            samplerState0.MagFilter = TextureFilter.Linear;
        }

        Viewport vp          = device.Viewport;
        float    xpos        = (x + 1.0f) * vp.Width / 2;
        float    ypos        = (y + 1.0f) * vp.Height / 2;
        float    sz          = z;
        float    rhw         = 1.0f;
        float    fLineHeight = (textureCoords[0, 3] - textureCoords[0, 1]) * textureHeight;

        // Adjust for character spacing
        xpos -= spacingPerChar * (fXScale * vp.Height) / fLineHeight;
        float fStartX = xpos;

        // Fill vertex buffer
        int numTriangles = 0;
        int realColor    = color.ToArgb();
        int iv           = 0;

        foreach (char c in text)
        {
            if (c == '\n')
            {
                xpos  = fStartX;
                ypos += fYScale * vp.Height;
            }

            if ((c - 32) < 0 || (c - 32) >= 128 - 32)
            {
                continue;
            }

            float tx1 = textureCoords[c - 32, 0];
            float ty1 = textureCoords[c - 32, 1];
            float tx2 = textureCoords[c - 32, 2];
            float ty2 = textureCoords[c - 32, 3];

            float w = (tx2 - tx1) * textureWidth;
            float h = (ty2 - ty1) * textureHeight;

            w *= (fXScale * vp.Height) / fLineHeight;
            h *= (fYScale * vp.Height) / fLineHeight;

            if (c != ' ')
            {
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + 0 - 0.5f, ypos + h - 0.5f, sz, rhw), realColor, tx1, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + 0 - 0.5f, ypos + 0 - 0.5f, sz, rhw), realColor, tx1, ty1);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + w - 0.5f, ypos + h - 0.5f, sz, rhw), realColor, tx2, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + w - 0.5f, ypos + 0 - 0.5f, sz, rhw), realColor, tx2, ty1);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + w - 0.5f, ypos + h - 0.5f, sz, rhw), realColor, tx2, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos + 0 - 0.5f, ypos + 0 - 0.5f, sz, rhw), realColor, tx1, ty1);
                numTriangles      += 2;

                if (numTriangles * 3 > (MaxNumfontVertices - 6))
                {
                    // Unlock, render, and relock the vertex buffer
                    vertexBuffer.SetData(fontVertices, 0, LockFlags.Discard);
                    device.DrawPrimitives(PrimitiveType.TriangleList, 0, numTriangles);
                    numTriangles = 0;
                    iv           = 0;
                }
            }

            xpos += w - (2 * spacingPerChar) * (fXScale * vp.Height) / fLineHeight;
        }

        // Unlock and render the vertex buffer
        vertexBuffer.SetData(fontVertices, 0, LockFlags.Discard);
        if (numTriangles > 0)
        {
            device.DrawPrimitives(PrimitiveType.TriangleList, 0, numTriangles);
        }

        // Restore the modified renderstates
        savedStateBlock.Apply();
    }
Ejemplo n.º 38
0
 public override void AsTextExpression(CodeWriter writer, RenderFlags flags)
 {
     // Suppress empty brackets (they'll be included as a part of the type)
     base.AsTextExpression(writer, flags | RenderFlags.NoParensIfEmpty);
 }
 protected virtual string ToStringDirective(RenderFlags flags)
 {
     return(DirectiveKeyword);
 }
Ejemplo n.º 40
0
 public bool HasRenderFlag(GraphObjectRenderFlags renderFlag)
 {
     return(RenderFlags.HasFlag(renderFlag));
 }
Ejemplo n.º 41
0
        public MyRenderEntity(uint id, string debugName, string model, MatrixD worldMatrix, MyMeshDrawTechnique drawTechnique, RenderFlags renderFlags)
            : base(id, debugName, worldMatrix, renderFlags)
        {
            System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(model));

            var renderModel = AddLODs(model);

            if (renderModel != null)
            {
                m_localAABB         = (BoundingBoxD)renderModel.BoundingBox;
                m_localVolume       = (BoundingSphereD)renderModel.BoundingSphere;
                m_localVolumeOffset = (Vector3D)renderModel.BoundingSphere.Center;
            }

            m_drawTechnique = drawTechnique;
            m_isDataSet     = true;
        }
    /// <summary>
    /// Draws scaled 2D text.  Note that x and y are in viewport coordinates
    /// (ranging from -1 to +1).  fXScale and fYScale are the size fraction 
    /// relative to the entire viewport.  For example, a fXScale of 0.25 is
    /// 1/8th of the screen width.  This allows you to output text at a fixed
    /// fraction of the viewport, even if the screen or window size changes.
    /// </summary>
    public void DrawTextScaled(float x, float y, float z, 
        float fXScale, float fYScale,
        System.Drawing.Color color,
        string text, RenderFlags flags)
    {
        if (device == null)
            throw new System.ArgumentNullException();

        // Set up renderstate
        savedStateBlock.Capture();
        drawTextStateBlock.Apply();
        device.VertexFormat = CustomVertex.TransformedColoredTextured.Format;
        device.PixelShader = null;
        device.SetStreamSource(0, vertexBuffer, 0);

        // Set filter states
        if ((flags & RenderFlags.Filtered) != 0) {
            samplerState0.MinFilter = TextureFilter.Linear;
            samplerState0.MagFilter = TextureFilter.Linear;
        }

        Viewport vp = device.Viewport;
        float xpos = (x+1.0f)*vp.Width/2;
        float ypos = (y+1.0f)*vp.Height/2;
        float sz = z;
        float rhw = 1.0f;
        float fLineHeight = (textureCoords[0,3] - textureCoords[0,1]) * textureHeight;

        // Adjust for character spacing
        xpos -= spacingPerChar * (fXScale*vp.Height)/fLineHeight;
        float fStartX = xpos;

        // Fill vertex buffer
        int numTriangles = 0;
        int realColor = color.ToArgb();
        int iv = 0;

        foreach (char c in text) {
            if (c == '\n') {
                xpos  = fStartX;
                ypos += fYScale*vp.Height;
            }

            if ((c-32) < 0 || (c-32) >= 128-32)
                continue;

            float tx1 = textureCoords[c-32,0];
            float ty1 = textureCoords[c-32,1];
            float tx2 = textureCoords[c-32,2];
            float ty2 = textureCoords[c-32,3];

            float w = (tx2-tx1)*textureWidth;
            float h = (ty2-ty1)*textureHeight;

            w *= (fXScale*vp.Height)/fLineHeight;
            h *= (fYScale*vp.Height)/fLineHeight;

            if (c != ' ') {
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+0-0.5f,ypos+h-0.5f,sz,rhw), realColor, tx1, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+0-0.5f,ypos+0-0.5f,sz,rhw), realColor, tx1, ty1);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+w-0.5f,ypos+h-0.5f,sz,rhw), realColor, tx2, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+w-0.5f,ypos+0-0.5f,sz,rhw), realColor, tx2, ty1);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+w-0.5f,ypos+h-0.5f,sz,rhw), realColor, tx2, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+0-0.5f,ypos+0-0.5f,sz,rhw), realColor, tx1, ty1);
                numTriangles += 2;

                if (numTriangles*3 > (MaxNumfontVertices-6)) {
                    // Unlock, render, and relock the vertex buffer
                    vertexBuffer.SetData(fontVertices, 0, LockFlags.Discard);
                    device.DrawPrimitives(PrimitiveType.TriangleList , 0, numTriangles);
                    numTriangles = 0;
                    iv = 0;
                }
            }

            xpos += w - (2 * spacingPerChar) * (fXScale*vp.Height)/fLineHeight;
        }

        // Unlock and render the vertex buffer
        vertexBuffer.SetData(fontVertices, 0, LockFlags.Discard);
        if (numTriangles > 0)
            device.DrawPrimitives(PrimitiveType.TriangleList , 0, numTriangles);

        // Restore the modified renderstates
        savedStateBlock.Apply();
    }
Ejemplo n.º 43
0
        private void DrawThumbnail(PdfBitmap bitmap, PdfPage page, Int32Rect pageRect, PageRotate pageRotate, RenderFlags renderFlags)
        {
            int pw = (int)page.Width;
            int ph = (int)page.Height;
            int w  = Math.Max(pw, (renderFlags & RenderFlags.FPDF_HQTHUMBNAIL) == RenderFlags.FPDF_HQTHUMBNAIL ? pageRect.Width : pw);
            int h  = Math.Max(ph, (renderFlags & RenderFlags.FPDF_HQTHUMBNAIL) == RenderFlags.FPDF_HQTHUMBNAIL ? pageRect.Height : ph);

            using (var bmp = new PdfBitmap(w, h, true))
            {
                page.RenderEx(bmp, 0, 0, w, h, pageRotate, renderFlags);

                using (var g = System.Drawing.Graphics.FromImage(bitmap.Image))
                {
                    g.DrawImage(bmp.Image, pageRect.X, pageRect.Y, pageRect.Width, pageRect.Height);
                }
            }
        }
Ejemplo n.º 44
0
        internal MyClipmapHandler(uint id, MyClipmapScaleEnum scaleGroup, MatrixD worldMatrix, Vector3I sizeLod0, Vector3D massiveCenter, float massiveRadius, bool spherize, RenderFlags additionalFlags, MyClipmap.PruningFunc prunningFunc)
        {
            m_clipmapBase   = new MyClipmap(id, scaleGroup, worldMatrix, sizeLod0, this, massiveCenter, massiveRadius, prunningFunc);
            m_massiveCenter = massiveCenter;
            m_renderFlags   = additionalFlags;
            m_mergeHandler  = null;

            if (spherize)
            {
                m_massiveRadius = massiveRadius;
            }

            if (MyLodMeshMergeHandler.ShouldAllocate(m_mergeHandler))
            {
                m_mergeHandler = AllocateMergeHandler();
            }

            MyClipmap.AddToUpdate(MyRender11.Environment.Matrices.CameraPosition, Base);
        }
Ejemplo n.º 45
0
 /// <summary>
 /// Enables debugging flags. No debug flags are active by default
 /// </summary>
 public void SetFlags(RenderFlags flags)
 {
     Noesis_View_SetFlags(CPtr, (int)flags);
 }
Ejemplo n.º 46
0
        /// <summary>
        /// Start/Continue progressive rendering for specified page
        /// </summary>
        /// <param name="page">Pdf page object</param>
        /// <param name="pageRect">Actual page's rectangle. </param>
        /// <param name="pageRotate">Page orientation: 0 (normal), 1 (rotated 90 degrees clockwise), 2 (rotated 180 degrees), 3 (rotated 90 degrees counter-clockwise).</param>
        /// <param name="renderFlags">0 for normal display, or combination of flags defined above.</param>
        /// <param name="useProgressiveRender">True for use progressive render</param>
        /// <returns>Null if page still painting, PdfBitmap object if page successfully rendered.</returns>
        internal bool RenderPage(PdfPage page, Int32Rect pageRect, PageRotate pageRotate, RenderFlags renderFlags, bool useProgressiveRender)
        {
            if (!this.ContainsKey(page))
            {
                ProcessNew(page); //Add new page into collection
                if (PaintBackground != null)
                {
                    PaintBackground(this, new EventArgs <Int32Rect>(pageRect));
                }
            }

            if ((renderFlags & (RenderFlags.FPDF_THUMBNAIL | RenderFlags.FPDF_HQTHUMBNAIL)) != 0)
            {
                this[page].status = ProgressiveRenderingStatuses.RenderDone + 4;
            }
            else if (!useProgressiveRender)
            {
                this[page].status = ProgressiveRenderingStatuses.RenderDone + 3;
            }

            PdfBitmap bitmap = this[page].Bitmap;
            bool      ret    = ProcessExisting(bitmap ?? CanvasBitmap, page, pageRect, pageRotate, renderFlags);

            if (bitmap != null)
            {
                Pdfium.FPDFBitmap_CompositeBitmap(CanvasBitmap.Handle, pageRect.X, pageRect.Y, pageRect.Width, pageRect.Height, bitmap.Handle, pageRect.X, pageRect.Y, BlendTypes.FXDIB_BLEND_NORMAL);
            }
            return(ret);
        }
Ejemplo n.º 47
0
        /// <summary>
        /// <see cref="ISceneRenderer.Render"/>
        /// </summary>
        public void Render(ICameraController cam, Dictionary <Node, List <Mesh> > visibleMeshesByNode,
                           bool visibleSetChanged,
                           bool texturesChanged,
                           RenderFlags flags,
                           Renderer renderer)
        {
            GL.Disable(EnableCap.Texture2D);
            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
            GL.Enable(EnableCap.DepthTest);

            // set fixed-function lighting parameters
            GL.ShadeModel(ShadingModel.Smooth);
            GL.LightModel(LightModelParameter.LightModelAmbient, new[] { 0.3f, 0.3f, 0.3f, 1 });
            GL.Enable(EnableCap.Lighting);
            GL.Enable(EnableCap.Light0);


            if (flags.HasFlag(RenderFlags.Wireframe))
            {
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            }

            var tmp = InitposeMax.X - InitposeMin.X;

            tmp = Math.Max(InitposeMax.Y - InitposeMin.Y, tmp);
            tmp = Math.Max(InitposeMax.Z - InitposeMin.Z, tmp);
            var scale = 2.0f / tmp;

            // TODO: migrate general scale and this snippet to camcontroller code
            if (cam != null)
            {
                cam.SetPivot(Owner.Pivot * (float)scale);
            }
            var view = cam == null?Matrix4.LookAt(0, 10, 5, 0, 0, 0, 0, 1, 0) : cam.GetView();

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadMatrix(ref view);

            // light direction
            var dir = new Vector3(1, 1, 0);
            var mat = renderer.LightRotation;

            Vector3.TransformNormal(ref dir, ref mat, out dir);
            GL.Light(LightName.Light0, LightParameter.Position, new float[] { dir.X, dir.Y, dir.Z, 0 });

            // light color
            var col = new Vector3(1, 1, 1);

            col *= (0.25f + 1.5f * GraphicsSettings.Default.OutputBrightness / 100.0f) * 1.5f;

            GL.Light(LightName.Light0, LightParameter.Diffuse, new float[] { col.X, col.Y, col.Z, 1 });
            GL.Light(LightName.Light0, LightParameter.Specular, new float[] { col.X, col.Y, col.Z, 1 });

            if (flags.HasFlag(RenderFlags.Shaded))
            {
                OverlayLightSource.DrawLightSource(dir);
            }


            GL.Scale(scale, scale, scale);


            // If textures changed, we may need to upload some of them to VRAM.
            // it is important this happens here and not accidentially while
            // compiling a displist.
            if (texturesChanged)
            {
                UploadTextures();
            }

            GL.PushMatrix();

            // Build and cache Gl displaylists and update only when the scene changes.
            // when the scene is being animated, this is bad because it changes every
            // frame anyway. In this case  we don't use a displist.
            var animated = Owner.SceneAnimator.IsAnimationActive;

            if (_displayList == 0 || visibleSetChanged || texturesChanged || flags != _lastFlags || animated)
            {
                _lastFlags = flags;

                // handle opaque geometry
                if (!animated)
                {
                    if (_displayList == 0)
                    {
                        _displayList = GL.GenLists(1);
                    }

                    GL.NewList(_displayList, ListMode.Compile);
                }

                var needAlpha = RecursiveRender(Owner.Raw.RootNode, visibleMeshesByNode, flags, animated);

                if (flags.HasFlag(RenderFlags.ShowSkeleton) || flags.HasFlag(RenderFlags.ShowNormals))
                {
                    RecursiveRenderNoScale(Owner.Raw.RootNode, visibleMeshesByNode, flags, 1.0f / scale, animated);
                }

                if (!animated)
                {
                    GL.EndList();
                }

                if (needAlpha)
                {
                    // handle semi-transparent geometry
                    if (!animated)
                    {
                        if (_displayListAlpha == 0)
                        {
                            _displayListAlpha = GL.GenLists(1);
                        }
                        GL.NewList(_displayListAlpha, ListMode.Compile);
                    }
                    RecursiveRenderWithAlpha(Owner.Raw.RootNode, visibleMeshesByNode, flags, animated);

                    if (!animated)
                    {
                        GL.EndList();
                    }
                }
                else if (_displayListAlpha != 0)
                {
                    GL.DeleteLists(_displayListAlpha, 1);
                    _displayListAlpha = 0;
                }
            }

            if (!animated)
            {
                GL.CallList(_displayList);
                if (_displayListAlpha != 0)
                {
                    GL.CallList(_displayListAlpha);
                }
            }

            GL.PopMatrix();

            // always switch back to FILL
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.Disable(EnableCap.DepthTest);

#if TEST
            GL.Enable(EnableCap.ColorMaterial);


            // TEST CODE to visualize mid point (pivot) and origin
            GL.LoadMatrix(ref view);
            GL.Begin(BeginMode.Lines);

            GL.Vertex3((InitposeMin + InitposeMax) * 0.5f * (float)scale);
            GL.Color3(0.0f, 1.0f, 0.0f);
            GL.Vertex3(0, 0, 0);
            GL.Color3(0.0f, 1.0f, 0.0f);
            GL.Vertex3((InitposeMin + InitposeMax) * 0.5f * (float)scale);
            GL.Color3(0.0f, 1.0f, 0.0f);

            GL.Vertex3(10, 10, 10);
            GL.Color3(0.0f, 1.0f, 0.0f);
            GL.End();
#endif

            GL.Disable(EnableCap.Texture2D);
            GL.Disable(EnableCap.Lighting);
        }
        internal override void AsTextName(CodeWriter writer, RenderFlags flags)
        {
            RenderFlags passFlags = (flags & RenderFlags.PassMask);

            _returnType.AsText(writer, passFlags);
        }
Ejemplo n.º 49
0
 protected override void AsTextStartArguments(CodeWriter writer, RenderFlags flags)
 {
     writer.Write(ParseTokenStart);
 }
Ejemplo n.º 50
0
    /// <summary>
    /// Draw some text on the screen.
    /// </summary>
    /// <param name="xpos">The X position.</param>
    /// <param name="ypos">The Y position.</param>
    /// <param name="color">The font color.</param>
    /// <param name="text">The actual text.</param>
    /// <param name="flags">Font render flags.</param>
    protected void DrawText(float xpos, float ypos, Color color, string text, RenderFlags flags, int maxWidth)
    {
      lock (GUIFontManager.Renderlock)
      {
        if (text == null)
        {
          return;
        }
        if (text.Length == 0)
        {
          return;
        }
        if (xpos <= 0)
        {
          return;
        }
        if (ypos <= 0)
        {
          return;
        }
        if (maxWidth < -1)
        {
          return;
        }


        text = GetRTLText(text);

        if (ID >= 0)
        {
          if (containsOutOfBoundsChar(text))
          {
            GUIFontManager.DrawText(_d3dxFont, xpos, ypos, color, text, maxWidth, _fontHeight);
            return;
          }

          int intColor = color.ToArgb();
          unsafe
          {
            float[,] matrix = GUIGraphicsContext.GetFinalMatrix();

            IntPtr ptrStr = Marshal.StringToCoTaskMemUni(text); //SLOW
            DXNative.FontEngineDrawText3D(ID, (void*)(ptrStr.ToPointer()), (int)xpos, (int)ypos, (uint)intColor, maxWidth,
                                                 matrix);
            Marshal.FreeCoTaskMem(ptrStr);
            return;
          }
        }
      }
    }
    /// <summary>
    /// Draw some text on the screen
    /// </summary>
    public void DrawText(float xpos, float ypos, Color color, string text, RenderFlags flags)
    {
        if (text == null)
            return;

        // Setup renderstate
        savedStateBlock.Capture();
        drawTextStateBlock.Apply();
        device.SetTexture(0, fontTexture);
        device.VertexFormat = CustomVertex.TransformedColoredTextured.Format;
        device.PixelShader = null;
        device.SetStreamSource(0, vertexBuffer, 0);

        // Set filter states
        if ((flags & RenderFlags.Filtered) != 0) {
            samplerState0.MinFilter = TextureFilter.Linear;
            samplerState0.MagFilter = TextureFilter.Linear;
        }

        // Adjust for character spacing
        xpos -= spacingPerChar;
        float fStartX = xpos;

        // Fill vertex buffer
        int iv = 0;
        int dwNumTriangles = 0;

        foreach (char c in text) {
            if (c == '\n') {
                xpos = fStartX;
                ypos += (textureCoords[0,3]-textureCoords[0,1])*textureHeight;
            }

            if ((c-32) < 0 || (c-32) >= 128-32)
                continue;

            float tx1 = textureCoords[c-32,0];
            float ty1 = textureCoords[c-32,1];
            float tx2 = textureCoords[c-32,2];
            float ty2 = textureCoords[c-32,3];

            float w = (tx2-tx1) *  textureWidth / textureScale;
            float h = (ty2-ty1) * textureHeight / textureScale;

            int intColor = color.ToArgb();
            if (c != ' ') {
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+0-0.5f,ypos+h-0.5f,0.9f,1.0f), intColor, tx1, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+0-0.5f,ypos+0-0.5f,0.9f,1.0f), intColor, tx1, ty1);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+w-0.5f,ypos+h-0.5f,0.9f,1.0f), intColor, tx2, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+w-0.5f,ypos+0-0.5f,0.9f,1.0f), intColor, tx2, ty1);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+w-0.5f,ypos+h-0.5f,0.9f,1.0f), intColor, tx2, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+0-0.5f,ypos+0-0.5f,0.9f,1.0f), intColor, tx1, ty1);
                dwNumTriangles += 2;

                if (dwNumTriangles*3 > (MaxNumfontVertices-6)) {
                    // Set the data for the vertexbuffer
                    vertexBuffer.SetData(fontVertices, 0, LockFlags.Discard);
                    device.DrawPrimitives(PrimitiveType.TriangleList, 0, dwNumTriangles);
                    dwNumTriangles = 0;
                    iv = 0;
                }
            }

            xpos += w - (2 * spacingPerChar);
        }

        // Set the data for the vertex buffer
        vertexBuffer.SetData(fontVertices, 0, LockFlags.Discard);
        if (dwNumTriangles > 0)
            device.DrawPrimitives(PrimitiveType.TriangleList, 0, dwNumTriangles);

        // Restore the modified renderstates
        savedStateBlock.Apply();
    }
Ejemplo n.º 52
0
        public static void AsTextPropertyInfo(CodeWriter writer, PropertyInfo propertyInfo, RenderFlags flags)
        {
            RenderFlags passFlags = flags & ~RenderFlags.Description;

            if (!flags.HasFlag(RenderFlags.NoPreAnnotations))
            {
                Attribute.AsTextAttributes(writer, propertyInfo);
            }
            writer.Write(ModifiersHelpers.AsString(GetPropertyModifiers(propertyInfo)));
            Type propertyType = propertyInfo.PropertyType;

            TypeRefBase.AsTextType(writer, propertyType, passFlags);
            writer.Write(" ");
            TypeRefBase.AsTextType(writer, propertyInfo.DeclaringType, passFlags);
            Dot.AsTextDot(writer);

            if (PropertyInfoUtil.IsIndexed(propertyInfo))
            {
                // Display the actual name instead of 'this' - it will usually be 'Item', but not always,
                // plus it might have a prefix (if it's an explicit interface implementation).
                writer.Write(propertyInfo.Name + IndexerDecl.ParseTokenStart);
                MethodRef.AsTextParameters(writer, propertyInfo.GetIndexParameters(), flags);
                writer.Write(IndexerDecl.ParseTokenEnd);
            }
            else
            {
                writer.Write(propertyInfo.Name);
            }
        }
    /// <summary>
    /// Renders 3D text
    /// </summary>
    public void Render3DText(string text, RenderFlags flags)
    {
        if (device == null)
            throw new System.ArgumentNullException();

        // Set up renderstate
        savedStateBlock.Capture();
        drawTextStateBlock.Apply();
        device.VertexFormat = CustomVertex.PositionNormalTextured.Format;
        device.PixelShader = null;
        device.SetStreamSource(0, vertexBuffer, 0, VertexInformation.GetFormatSize(CustomVertex.PositionNormalTextured.Format));

        // Set filter states
        if ((flags & RenderFlags.Filtered) != 0) {
            samplerState0.MinFilter = TextureFilter.Linear;
            samplerState0.MagFilter = TextureFilter.Linear;
        }

        // Position for each text element
        float x = 0.0f;
        float y = 0.0f;

        // Center the text block at the origin
        if ((flags & RenderFlags.Centered) != 0) {
            System.Drawing.SizeF sz = GetTextExtent(text);
            x = -(((float)sz.Width)/10.0f)/2.0f;
            y = -(((float)sz.Height)/10.0f)/2.0f;
        }

        // Turn off culling for two-sided text
        if ((flags & RenderFlags.TwoSided) != 0)
            renderState.CullMode = Cull.None;

        // Adjust for character spacing
        x -= spacingPerChar / 10.0f;
        float fStartX = x;

        // Fill vertex buffer
        GraphicsStream strm = vertexBuffer.Lock(0, 0, LockFlags.Discard);
        int numTriangles = 0;

        foreach (char c in text) {
            if (c == '\n') {
                x = fStartX;
                y -= (textureCoords[0,3]-textureCoords[0,1])*textureHeight/10.0f;
            }

            if ((c-32) < 0 || (c-32) >= 128-32)
                continue;

            float tx1 = textureCoords[c-32,0];
            float ty1 = textureCoords[c-32,1];
            float tx2 = textureCoords[c-32,2];
            float ty2 = textureCoords[c-32,3];

            float w = (tx2-tx1) * textureWidth  / (10.0f * textureScale);
            float h = (ty2-ty1) * textureHeight / (10.0f * textureScale);

            if (c != ' ') {
                strm.Write(new CustomVertex.PositionNormalTextured(new Vector3(x+0,y+0,0), new Vector3(0,0,-1), tx1, ty2));
                strm.Write(new CustomVertex.PositionNormalTextured(new Vector3(x+0,y+h,0), new Vector3(0,0,-1), tx1, ty1));
                strm.Write(new CustomVertex.PositionNormalTextured(new Vector3(x+w,y+0,0), new Vector3(0,0,-1), tx2, ty2));
                strm.Write(new CustomVertex.PositionNormalTextured(new Vector3(x+w,y+h,0), new Vector3(0,0,-1), tx2, ty1));
                strm.Write(new CustomVertex.PositionNormalTextured(new Vector3(x+w,y+0,0), new Vector3(0,0,-1), tx2, ty2));
                strm.Write(new CustomVertex.PositionNormalTextured(new Vector3(x+0,y+h,0), new Vector3(0,0,-1), tx1, ty1));
                numTriangles += 2;

                if (numTriangles*3 > (MaxNumfontVertices-6)) {
                    // Unlock, render, and relock the vertex buffer
                    vertexBuffer.Unlock();
                    device.DrawPrimitives(PrimitiveType.TriangleList , 0, numTriangles);
                    strm = vertexBuffer.Lock(0, 0, LockFlags.Discard);
                    numTriangles = 0;
                }
            }

            x += w - (2 * spacingPerChar) / 10.0f;
        }

        // Unlock and render the vertex buffer
        vertexBuffer.Unlock();
        if (numTriangles > 0)
            device.DrawPrimitives(PrimitiveType.TriangleList , 0, numTriangles);

        // Restore the modified renderstates
        savedStateBlock.Apply();
    }
        /// <summary>
        /// Recursive render function for drawing opaque geometry with no scaling
        /// in the transformation chain. This is used for overlays, such as drawing
        /// the skeleton.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="visibleMeshesByNode"></param>
        /// <param name="flags"></param>
        /// <param name="invGlobalScale"></param>
        /// <param name="animated"></param>
        private void RecursiveRenderNoScale(Node node, Dictionary <Node, List <Mesh> > visibleMeshesByNode, RenderFlags flags,
                                            float invGlobalScale,
                                            bool animated, int currDispList)
        {
            // TODO unify our use of OpenTK and Assimp matrices
            Matrix4x4 m;
            Matrix4   mConv;

            if (animated)
            {
                Owner.SceneAnimator.GetLocalTransform(node, out mConv);
                OpenTkToAssimp.FromMatrix(ref mConv, out m);
            }
            else
            {
                m = node.Transform;
            }

            // get rid of the scaling part of the matrix
            // TODO this can be done faster and Decompose() doesn't handle
            // non positively semi-definite matrices correctly anyway.

            Vector3D scaling;

            Assimp.Quaternion rotation;
            Vector3D          translation;

            m.Decompose(out scaling, out rotation, out translation);

            rotation.Normalize();

            m     = new Matrix4x4(rotation.GetMatrix()) * Matrix4x4.FromTranslation(translation);
            mConv = AssimpToOpenTk.FromMatrix(ref m);
            mConv.Transpose();

            if (flags.HasFlag(RenderFlags.ShowSkeleton))
            {
                var highlight = false;
                if (visibleMeshesByNode != null)
                {
                    List <Mesh> meshList;
                    if (visibleMeshesByNode.TryGetValue(node, out meshList) && meshList == null)
                    {
                        // If the user hovers over a node in the tab view, all of its descendants
                        // are added to the visible set as well. This is not the intended
                        // behavior for skeleton joints, though! Here we only want to show the
                        // joint corresponding to the node being hovered over.

                        // Therefore, only highlight nodes whose parents either don't exist
                        // or are not in the visible set.
                        if (node.Parent == null || !visibleMeshesByNode.TryGetValue(node.Parent, out meshList) || meshList != null)
                        {
                            highlight = true;
                        }
                    }
                }
                OverlaySkeleton.DrawSkeletonBone(node, invGlobalScale, highlight);
            }

            GL.PushMatrix();
            GL.MultMatrix(ref mConv);
            for (int i = 0; i < node.ChildCount; i++)
            {
                RecursiveRenderNoScale(node.Children[i], visibleMeshesByNode, flags, invGlobalScale, animated, currDispList);
            }
            GL.PopMatrix();
        }
        /// <summary>
        /// Draw a mesh using either its given material or a transparent "ghost" material.
        /// </summary>
        /// <param name="node">Current node</param>
        /// <param name="animated">Specifies whether animations should be played</param>
        /// <param name="showGhost">Indicates whether to substitute the mesh' material with a
        /// "ghost" surrogate material that allows looking through the geometry.</param>
        /// <param name="index">Mesh index in the scene</param>
        /// <param name="mesh">Mesh instance</param>
        /// <param name="flags"> </param>
        /// <returns></returns>
        protected override bool InternDrawMesh(Node node, bool animated, bool showGhost, int index, Mesh mesh, RenderFlags flags)
        {
            if (showGhost)
            {
                Owner.MaterialMapper.ApplyGhostMaterial(mesh, Owner.Raw.Materials[mesh.MaterialIndex],
                                                        flags.HasFlag(RenderFlags.Shaded), flags.HasFlag(RenderFlags.ForceTwoSidedLighting));
            }
            else
            {
                Owner.MaterialMapper.ApplyMaterial(mesh, Owner.Raw.Materials[mesh.MaterialIndex],
                                                   flags.HasFlag(RenderFlags.Textured),
                                                   flags.HasFlag(RenderFlags.Shaded), flags.HasFlag(RenderFlags.ForceTwoSidedLighting));
            }

            if (GraphicsSettings.Default.BackFaceCulling)
            {
                GL.FrontFace(FrontFaceDirection.Ccw);
                GL.CullFace(CullFaceMode.Back);
                GL.Enable(EnableCap.CullFace);
            }
            else
            {
                GL.Disable(EnableCap.CullFace);
            }

            var hasColors    = mesh.HasVertexColors(0);
            var hasTexCoords = mesh.HasTextureCoords(0);

            var skinning = mesh.HasBones && animated;

            foreach (var face in mesh.Faces)
            {
                BeginMode faceMode;
                switch (face.IndexCount)
                {
                case 1:
                    faceMode = BeginMode.Points;
                    break;

                case 2:
                    faceMode = BeginMode.Lines;
                    break;

                case 3:
                    faceMode = BeginMode.Triangles;
                    break;

                default:
                    faceMode = BeginMode.Polygon;
                    break;
                }

                GL.Begin(faceMode);
                for (var i = 0; i < face.IndexCount; i++)
                {
                    var indice = face.Indices[i];
                    if (hasColors)
                    {
                        var vertColor = AssimpToOpenTk.FromColor(mesh.VertexColorChannels[0][indice]);
                        GL.Color4(vertColor);
                    }
                    if (mesh.HasNormals)
                    {
                        Vector3 normal;
                        if (skinning)
                        {
                            Skinner.GetTransformedVertexNormal(node, mesh, (uint)indice, out normal);
                        }
                        else
                        {
                            normal = AssimpToOpenTk.FromVector(mesh.Normals[indice]);
                        }

                        GL.Normal3(normal);
                    }
                    if (hasTexCoords)
                    {
                        var uvw = AssimpToOpenTk.FromVector(mesh.TextureCoordinateChannels[0][indice]);
                        GL.TexCoord2(uvw.X, 1 - uvw.Y);
                    }

                    Vector3 pos;
                    if (skinning)
                    {
                        Skinner.GetTransformedVertexPosition(node, mesh, (uint)indice, out pos);
                    }
                    else
                    {
                        pos = AssimpToOpenTk.FromVector(mesh.Vertices[indice]);
                    }
                    GL.Vertex3(pos);
                }
                GL.End();
            }
            GL.Disable(EnableCap.CullFace);
            return(skinning);
        }
Ejemplo n.º 56
0
 public override void AsTextExpression(CodeWriter writer, RenderFlags flags)
 {
     UpdateLineCol(writer, flags);
     writer.Write(Keyword);
 }
        /// <summary>
        /// Recursive render function for drawing normals with a constant size.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="visibleMeshesByNode"></param>
        /// <param name="flags"></param>
        /// <param name="invGlobalScale"></param>
        /// <param name="animated"></param>
        /// <param name="transform"></param>
        private void RecursiveRenderNormals(Node node, Dictionary <Node, List <Mesh> > visibleMeshesByNode, RenderFlags flags,
                                            float invGlobalScale,
                                            bool animated,
                                            Matrix4 transform, int currDispList)
        {
            // TODO unify our use of OpenTK and Assimp matrices
            Matrix4 mConv;

            if (animated)
            {
                Owner.SceneAnimator.GetLocalTransform(node, out mConv);
            }
            else
            {
                Matrix4x4 m = node.Transform;
                mConv = AssimpToOpenTk.FromMatrix(ref m);
            }

            mConv.Transpose();

            // The normal's position and direction are transformed differently, so we manually track the transform.
            transform = mConv * transform;

            if (flags.HasFlag(RenderFlags.ShowNormals))
            {
                List <Mesh> meshList = null;
                if (node.HasMeshes &&
                    (visibleMeshesByNode == null || visibleMeshesByNode.TryGetValue(node, out meshList)))
                {
                    foreach (var index in node.MeshIndices)
                    {
                        var mesh = Owner.Raw.Meshes[index];
                        if (meshList != null && !meshList.Contains(mesh))
                        {
                            continue;
                        }
                        if (currDispList == GetDispList(node.Name))
                        {
                            OverlayNormals.DrawNormals(node, index, mesh, mesh.HasBones && animated ? Skinner : null, invGlobalScale, transform);
                        }
                    }
                }
            }

            for (int i = 0; i < node.ChildCount; i++)
            {
                RecursiveRenderNormals(node.Children[i], visibleMeshesByNode, flags, invGlobalScale, animated, transform, currDispList);
            }
        }
        internal MyLodMeshMergeHandler(MyClipmap parentClipmap, int lodCount, int lodDivisions, ref MatrixD worldMatrix, ref Vector3D massiveCenter, float massiveRadius, RenderFlags renderFlags)
        {
            if (!MyRenderProxy.Settings.EnableVoxelMerging)
                return;

            m_mergesPerLod = new MyLodMeshMerge[lodCount];

            for(int lodIndex = 0; lodIndex < m_mergesPerLod.Length; ++lodIndex)
            {
                int divisions = NUM_DIVISIONS_PER_LOD[lodIndex];
                m_mergesPerLod[lodIndex] = new MyLodMeshMerge(parentClipmap, lodIndex, divisions, ref worldMatrix, ref massiveCenter, massiveRadius, renderFlags);
                m_dirtyLodMergeIndices.Add(lodIndex);
            }
        }
Ejemplo n.º 59
0
            internal MyLodMeshMerge(MyClipmap parentClipmap, int lod, int lodDivisions, ref MatrixD worldMatrix, ref Vector3D massiveCenter, float massiveRadius, RenderFlags renderFlags)
            {
                Debug.Assert(parentClipmap != null, "Parent clipmap cannot be null");
                Debug.Assert(lod >= 0, "Lod level must be non-negative");
                Debug.Assert(lodDivisions >= 0, "Invalid number of lod divisions");
                m_parentClipmap = parentClipmap;
                m_lod           = lod;
                m_lodDivisions  = lodDivisions;

                if (!IsUsed())
                {
                    return;
                }

                m_dirtyProxyIndices    = new HashSet <int>();
                m_cellProxyToAabbProxy = new Dictionary <MyClipmapCellProxy, int>();
                m_boundingBoxes        = new MyDynamicAABBTreeD(Vector3D.Zero);

                int cellCount = lodDivisions * lodDivisions * lodDivisions;

                m_mergeJobs            = new MergeJobInfo[cellCount];
                m_mergedLodMeshProxies = new MyClipmapCellProxy[cellCount];
                m_trackedActors        = new HashSet <MyActor> [cellCount];

                for (int divideIndex = 0; divideIndex < cellCount; ++divideIndex)
                {
                    m_mergedLodMeshProxies[divideIndex] = new MyClipmapCellProxy(new MyCellCoord(Lod, GetCellFromDivideIndex(divideIndex)), ref worldMatrix, massiveCenter, massiveRadius, renderFlags, true);
                    m_mergeJobs[divideIndex]            = new MergeJobInfo {
                        CurrentWorkId = 0, LodMeshesBeingMerged = new List <LodMeshId>(), NextPossibleMergeStartTime = MyCommon.FrameCounter
                    };
                    m_trackedActors[divideIndex] = new HashSet <MyActor>();
                    m_dirtyProxyIndices.Add(divideIndex);
                }
            }
Ejemplo n.º 60
0
        internal MyLodMeshMergeHandler(MyClipmap parentClipmap, int lodCount, int lodDivisions, ref MatrixD worldMatrix, ref Vector3D massiveCenter, float massiveRadius, RenderFlags renderFlags)
        {
            Debug.Assert(lodCount <= NUM_DIVISIONS_PER_LOD.Length, "Only " + NUM_DIVISIONS_PER_LOD.Length + " lods allowed, " + lodCount + " requested. Consider adding elements to NUM_DIVISIONS_PER_LOD.");
            Debug.Assert(parentClipmap != null, "Parent clipmap of merge handler cannot be null!");
            m_mergesPerLod = new MyLodMeshMerge[lodCount];

            for (int lodIndex = 0; lodIndex < m_mergesPerLod.Length; ++lodIndex)
            {
                int divisions = NUM_DIVISIONS_PER_LOD[lodIndex];
                m_mergesPerLod[lodIndex] = new MyLodMeshMerge(parentClipmap, lodIndex, divisions, ref worldMatrix, ref massiveCenter, massiveRadius, renderFlags);
                m_dirtyLodMergeIndices.Add(lodIndex);
            }

            m_parentClipmap = parentClipmap;
        }