Ejemplo n.º 1
0
        /// <summary>
        /// Create OpenGL object specifying the referenced scene objects directly.
        /// </summary>
        /// <param name="block"></param>
        /// <param name="scene"></param>
        /// <param name="glbuff"></param>
        /// <param name="glimg"></param>
        public GLTexture(Compiler.Block block, Dict scene, GLBuffer glbuff, GLImage glimg)
            : base(block.Name, block.Anno)
        {
            var err = new CompileException($"texture '{name}'");

            // PARSE ARGUMENTS
            Cmds2Fields(block, err);

            // set name
            glBuff = glbuff;
            glImg = glimg;

            // GET REFERENCES
            if (Buff != null)
                scene.TryGetValue(Buff, out glBuff, block, err);
            if (Img != null)
                scene.TryGetValue(Img, out glImg, block, err);
            if (glBuff != null && glImg != null)
                err.Add("Only an image or a buffer can be bound to a texture object.", block);
            if (glBuff == null && glImg == null)
                err.Add("Ether an image or a buffer has to be bound to a texture object.", block);

            // IF THERE ARE ERRORS THROW AND EXCEPTION
            if (err.HasErrors())
                throw err;

            // INCASE THIS IS A TEXTURE OBJECT
            Link(block.Filename, block.LineInFile, err);
            if (HasErrorOrGlError(err, block))
                throw err;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// (Re)initialize the debugger. This method must
        /// be called whenever a program is compiled.
        /// </summary>
        /// <param name="scene"></param>
        public static void Initilize(Dict scene)
        {
            // allocate GPU resources
            buf = new GLBuffer(DbgBufKey, "dbg", BufferUsageHint.DynamicRead, stage_size * 6 * 16);
            tex = new GLTexture(DbgTexKey, "dbg", GpuFormat.Rgba32f, buf, null);

#if DEBUG   // add to scene for debug inspection
            scene.Add(DbgBufKey, buf);
            scene.Add(DbgTexKey, tex);
#endif
            passes.Clear();
            // reset watch count for indexing in debug mode
            dbgVarCount = 0;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create OpenGL object specifying the texture
        /// format and referenced scene objects directly.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="anno"></param>
        /// <param name="format"></param>
        /// <param name="glbuff"></param>
        /// <param name="glimg"></param>
        public GLTexture(string name, string anno, GpuFormat format, GLBuffer glbuff, GLImage glimg)
            : base(name, anno)
        {
            var err = new CompileException($"texture '{name}'");

            // set name
            Format = format;
            glBuff = glbuff;
            glImg = glimg;

            // INCASE THIS IS A TEXTURE OBJECT
            Link("", -1, err);
            if (HasErrorOrGlError(err, "", -1))
                throw err;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create OpenGL object specifying the texture
        /// format and referenced scene objects directly.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="anno"></param>
        /// <param name="format"></param>
        /// <param name="glbuff"></param>
        /// <param name="glimg"></param>
        public GLTexture(string name, string anno, GpuFormat format, GLBuffer glbuff, GLImage glimg)
            : base(name, anno)
        {
            var err = new CompileException($"texture '{name}'");

            // set name
            Format = format;
            glBuff = glbuff;
            glImg  = glimg;

            // INCASE THIS IS A TEXTURE OBJECT
            Link("", -1, err);
            if (HasErrorOrGlError(err, "", -1))
            {
                throw err;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create OpenGL object specifying the referenced scene objects directly.
        /// </summary>
        /// <param name="block"></param>
        /// <param name="scene"></param>
        /// <param name="glbuff"></param>
        /// <param name="glimg"></param>
        public GLTexture(Compiler.Block block, Dict scene, GLBuffer glbuff, GLImage glimg)
            : base(block.Name, block.Anno)
        {
            var err = new CompileException($"texture '{Name}'");

            // PARSE ARGUMENTS
            Cmds2Fields(block, err);

            // set name
            glBuff = glbuff;
            glImg  = glimg;

            // GET REFERENCES
            if (Buff != null)
            {
                scene.TryGetValue(Buff, out glBuff, block, err);
            }
            if (Img != null)
            {
                scene.TryGetValue(Img, out glImg, block, err);
            }
            if (glBuff != null && glImg != null)
            {
                err.Add("Only an image or a buffer can be bound to a texture object.", block);
            }
            if (glBuff == null && glImg == null)
            {
                err.Add("Ether an image or a buffer has to be bound to a texture object.", block);
            }

            // IF THERE ARE ERRORS THROW AND EXCEPTION
            if (err.HasErrors)
            {
                throw err;
            }

            // INCASE THIS IS A TEXTURE OBJECT
            Link(block.Filename, block.LineInFile, err);
            if (HasErrorOrGlError(err, block))
            {
                throw err;
            }
        }
Ejemplo n.º 6
0
 public MultiDrawCall(
     DrawFunc drawfunc,
     GLVertinput vertexin,
     GLVertoutput vertout,
     GLBuffer indexbuf,
     GLBuffer indirect)
 {
     vertin        = vertexin;
     indbuf        = indexbuf;
     this.cmd      = new List <DrawCall>();
     this.drawfunc = drawfunc;
     this.vertexin = vertexin != null ? vertexin.glname : 0;
     this.indexbuf = indexbuf != null ? indexbuf.glname : 0;
     this.vertout  = vertout != null ? vertout.glname : 0;
     this.indirect = indirect != null ? indirect.glname : 0;
     if (drawfunc == DrawFunc.ArraysIndirect)
     {
         this.indirect = this.indexbuf;
         this.indexbuf = 0;
     }
 }
Ejemplo n.º 7
0
Archivo: App.cs Proyecto: h3tch/ProtoFX
        /// <summary>
        /// Run or debug the currently active tab.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="ev"></param>
        private void ToolBtnRunDebug_Click(object s, EventArgs ev)
        {
            // if no tab page is selected nothing needs to be compiled
            if (SelectedTab == null)
            {
                return;
            }
            CompiledEditor = (CodeEditor)SelectedTab.Controls[0];

            // save code
            ToolBtnSave_Click(s, null);

            // clear scene and output
            output.Rows.Clear();
            glControl.ClearScene();
            glControl.RemoveEvents();

            // get include directory
            var includeDir = (CompiledEditor.Filename != null
                ? Path.GetDirectoryName(CompiledEditor.Filename)
                : Directory.GetCurrentDirectory()) + Path.DirectorySeparatorChar;

            // get code text form tab page
            // generate debug information?
            var debugging = s == toolBtnDbg;

            // COMPILE THE CURRENTLY SELECTED FILE
            var root        = Compiler.Compile(CompiledEditor.Filename);
            var shaderLines = from x in root where x.Type == "shader" select new[] { x.Line, x.LineCount };

            CompiledEditor.RemoveInvalidBreakpoints(shaderLines);

            // INSTANTIATE THE CLASS WITH THE SPECIFIED ARGUMENTS (collect all errors)
            var ex = root.Catch(x => glControl.AddObject(x, debugging)).ToArray();

            // add events to the end of the event list
            glControl.AddEvents(output);
            glControl.MouseUp += new MouseEventHandler(GlControl_MouseUp);

            // show errors
            var exc = from x in ex
                      where x is CompileException || x.InnerException is CompileException
                      select(x is CompileException?x : x.InnerException) as CompileException;

            var err  = from x in exc from y in x select y;
            var line = from x in err select x.Line;

            err.ForEach(line, (e, l) => AddOutputItem(includeDir, e.File, l + 1, e.Msg));

            // underline all debug errors
            var ranges = line.Select(x => new[] {
                CompiledEditor.Lines[x].Position,
                CompiledEditor.Lines[x].EndPosition
            });

            CompiledEditor.ClearIndicators(CodeEditor.DebugIndicatorIndex);
            CompiledEditor.AddIndicators(CodeEditor.DebugIndicatorIndex, ranges);

            // SHOW SCENE
            DebugRender(debugging);

            // add externally created textures to the scene
            var existing = glControl.Scene.Values.ToArray();

            GLImage.FindTextures(existing).ForEach(x => glControl.Scene.Add(x.Name, x));

            // add externally created buffers to the scene
            GLBuffer.FindBuffers(existing).ForEach(x => glControl.Scene.Add(x.Name, x));

            // UPDATE DEBUG DATA
            comboBuf.Items.Clear();
            comboImg.Items.Clear();
            comboProp.Items.Clear();
            glControl.Scene.Where(x => x.Value is GLBuffer).ForEach(x => comboBuf.Items.Add(x.Value));
            glControl.Scene.Where(x => x.Value is GLImage).ForEach(x => comboImg.Items.Add(x.Value));
            glControl.Scene.Where(x => x.Value is GLInstance).ForEach(x => comboProp.Items.Add(x.Value));

            // SHOW DEBUG BUTTONS IF NECESSARY
            toolBtnDbgStepBreakpoint.Enabled = debugging;
            toolBtnDbgStepInto.Enabled       = debugging;
            toolBtnDbgStepOver.Enabled       = debugging;
            toolBtnDbgStepBack.Enabled       = debugging;
            debugListView.Visible            = debugging;
        }
Ejemplo n.º 8
0
        private void ParseDrawCall(Compiler.Command cmd, Dict classes, CompileException err)
        {
            var          args      = new List <int>();
            GLVertinput  vertexin  = null;
            GLVertoutput vertout   = null;
            GLBuffer     indexbuf  = null;
            GLBuffer     indirect  = null;
            bool         modeIsSet = false;
            bool         typeIsSet = false;
            PrimType     primitive = 0;
            ElementType  indextype = 0;

            // parse draw call arguments
            foreach (var arg in cmd)
            {
                if (classes.TryGetValue(arg.Text, ref vertexin))
                {
                    continue;
                }
                if (classes.TryGetValue(arg.Text, ref vertout))
                {
                    continue;
                }
                if (classes.TryGetValue(arg.Text, ref indexbuf))
                {
                    continue;
                }
                if (classes.TryGetValue(arg.Text, ref indirect))
                {
                    continue;
                }
                if (int.TryParse(arg.Text, out int val))
                {
                    args.Add(val);
                }
                else if (typeIsSet == false && Enum.TryParse(arg.Text, true, out indextype))
                {
                    typeIsSet = true;
                }
                else if (modeIsSet == false && Enum.TryParse(arg.Text, true, out primitive))
                {
                    modeIsSet = true;
                }
                else
                {
                    err.Add($"Unable to process argument '{arg.Text}'.", cmd);
                }
            }

            if (err.HasErrors)
            {
                return;
            }

            // a draw call must specify a primitive type
            if (modeIsSet == false)
            {
                err.Add("Draw call must specify a primitive type (e.g. triangles, "
                        + "trianglefan, lines, points, ...).", cmd);
                return;
            }

            // determine the right draw call function
            int bits = (vertout != null ? 1 : 0)
                       | (indexbuf != null ? 2 : 0)
                       | (indirect != null ? 4 : 0)
                       | (typeIsSet ? 8 : 0);

            if (!Enum.IsDefined(typeof(DrawFunc), bits))
            {
                err.Add("Draw call function not recognized or ambiguous.", cmd);
                return;
            }

            var drawfunc = (DrawFunc)bits;

            // get index buffer object (if present) and find existing MultiDraw class
            var multidrawcall = drawcalls.Find(
                x => x.vertexin == (vertexin != null ? vertexin.glname : 0) &&
                x.indexbuf == (indexbuf != null ? indexbuf.glname : 0) &&
                x.vertout == (vertout != null ? vertout.glname : 0) &&
                x.indirect == (indirect != null ? indirect.glname : 0))
                                ?? new MultiDrawCall(drawfunc, vertexin, vertout, indexbuf, indirect);

            // add new draw command to the MultiDraw class
            multidrawcall.cmd.Add(new DrawCall(drawfunc, primitive, indextype, args));

            drawcalls.Add(multidrawcall);
        }