Beispiel #1
0
        public void DestroyShaderModule(IMgDevice device, IMgAllocationCallbacks allocator)
        {
            if (mIsDisposed)
            {
                return;
            }

            if (ShaderId.HasValue)
            {
                mEntrypoint.DeleteShaderModule(ShaderId.Value);
                //GL.DeleteShader(ShaderId.Value);
                ShaderId = null;
            }

            mIsDisposed = true;
        }
Beispiel #2
0
        internal static int CompileShader(IGLShaderModuleEntrypoint entrypoint, MgShaderStageFlagBits stage, string fileContents, string shaderPrefix, string functionName)
        {
            int retVal = entrypoint.CreateShaderModule(stage);
            // GL.CreateShader(type);
            //string includePath = ".";

            // GLSL has this annoying feature that the #version directive must appear first. But we
            // want to inject some #define shenanigans into the shader.
            // So to do that, we need to split for the part of the shader up to the end of the #version line,
            // and everything after that. We can then inject our defines right there.
            var    strTuple       = VersionSplit(fileContents);
            string versionStr     = strTuple.Item1;
            string shaderContents = strTuple.Item2;

            var builder = new StringBuilder();

            builder.AppendLine(versionStr);
            builder.AppendLine(shaderPrefix);
            builder.Append(shaderContents);

            // APPEND custom function name to replicate custom function name
            builder.Append("void main() { ");
            builder.Append(functionName);
            builder.Append("(); }");

            entrypoint.CompileShaderModule(retVal, builder.ToString());

            //GL.ShaderSource(retVal, builder.ToString());
            //GL.CompileShader(retVal);

            bool isCompiled = entrypoint.IsCompiled(retVal);

            //int compileStatus = 0;
            //GL.GetShader(retVal, ShaderParameter.CompileStatus, out compileStatus);
            //// if (compileStatus != (int)All.True)

            //int glinfoLogLength = 0;
            //GL.GetShader(retVal, ShaderParameter.InfoLogLength, out glinfoLogLength);
            //if (glinfoLogLength > 1)

            bool hasMessages = entrypoint.HasCompilerMessages(retVal);

            if (hasMessages)
            {
                string buffer = entrypoint.GetCompilerMessages(retVal);
                //	GL.GetShaderInfoLog(retVal);
                if (!isCompiled)
                {
                    throw new Exception("Shader Compilation failed for shader with the following errors: " + buffer);
                }
                //				else {
                //					Console.WriteLine("Shader Compilation succeeded for shader '{0}', with the following log:", _shaderFilename);
                //				}
                //
                //				Console.WriteLine(buffer);
            }

            if (!isCompiled)
            {
                entrypoint.DeleteShaderModule(retVal);
                retVal = 0;
            }

            return(retVal);
        }