public override void InitializeOverrides(CodegenOverrideTracker overrides)
        {
            overrides.RegisterArgumentTypeReadOverride(ResourceHandleType, async(context, function, arg) =>
            {
                await context.EmitLine($"{ResourceHandleType} {arg.Name}Handle = {DataBuffer}.read<{ResourceHandleType}>();");
                await context.EmitLine($"auto& {arg.Name} = *{Resources}.get({arg.Name}Handle);");
            });

            overrides.RegisterOverride($"glCreate{ResourceType}s",
                                       overrideEntry: (fn) => {
                fn.Name = "glCreate" + ResourceType;
                fn.Type.Arguments.Clear();
                fn.Type.ReturnType = ResourceHandleType;
            },
                                       modifyReadFunc: async(context, defaultRead, entry) => {
                await context.EmitLine($"auto handle = {DataBuffer}.read<{ResourceHandleType}>();");
                await context.EmitLine($"auto& target = *{Resources}.get(handle);");
                await context.EmitLine($"glCreate{ResourceType}s(1, &target);");
            },
                                       modifyWriteFunc: async(context, defaultWrite, entry) => {
                context.EmitLine();
                await context.EmitLine($"auto handle = {Resources}.create(0);");
                await context.EmitLine($"{DataBuffer}.write<{ResourceHandleType}>(handle);");
                await context.EmitLine($"return handle;");
            }
                                       );

            overrides.RegisterOverride($"glGen{ResourceType}s",
                                       overrideEntry: (fn) => {
                fn.Name = "glGen" + ResourceType;
                fn.Type.Arguments.Clear();
                fn.Type.ReturnType = ResourceHandleType;
            },
                                       modifyReadFunc: async(context, defaultRead, entry) => {
                await context.EmitLine($"auto handle = {DataBuffer}.read<{ResourceHandleType}>();");
                await context.EmitLine($"auto& target = *{Resources}.get(handle);");
                await context.EmitLine($"glGen{ResourceType}s(1, &target);");
            },
                                       modifyWriteFunc: async(context, defaultWrite, entry) => {
                context.EmitLine();
                await context.EmitLine($"auto handle = {Resources}.create(0);");
                await context.EmitLine($"{DataBuffer}.write<{ResourceHandleType}>(handle);");
                await context.EmitLine($"return handle;");
            }
                                       );

            foreach (var kv in overrides.Registry.Functions)
            {
                foreach (var arg in kv.Value.Type.Arguments)
                {
                    if (arg.Name == "buffer")
                    {
                        arg.Type = ResourceHandleType;
                    }
                }
            }
        }
        public override void InitializeOverrides(CodegenOverrideTracker overrides)
        {
            overrides.RegisterArgumentTypeReadOverride(ResourceHandleType, async(context, function, arg) =>
            {
                await context.EmitLine($"{ResourceHandleType} {arg.Name}Handle = {DataBuffer}.read<{ResourceHandleType}>();");
                await context.EmitLine($"auto& {arg.Name} = *{Resources}.get({arg.Name}Handle);");
            });

            overrides.RegisterOverride("glCreateShader",
                                       overrideEntry: (fn) => {
                fn.Type.ReturnType = ResourceHandleType;
            },
                                       modifyReadFunc: async(context, defaultRead, entry) => {
                await context.EmitLine($"auto handle = {DataBuffer}.read<{ResourceHandleType}>();");
                await context.EmitLine($"auto& target = *{Resources}.get(handle);");
                await EmitArgumentReads(context, entry);
                await context.EmitLine($"target = glCreateShader({GenerateTypelessArgumentList(entry)});");
            },
                                       modifyWriteFunc: async(context, defaultWrite, entry) => {
                context.EmitLine();
                await context.EmitLine($"auto handle = {Resources}.create(0);");
                await context.EmitLine($"{DataBuffer}.write(handle);");
                await EmitArgumentWrites(context, entry);

                await context.EmitLine($"return handle;");
            }
                                       );

            overrides.RegisterOverride("glShaderSource",
                                       overrideEntry: (fn) => {
                var args     = fn.Type.Arguments;
                args[0].Type = ResourceHandleType;
                args.RemoveAt(1);
                args[1].Type = "const GLchar*";
                args[2].Type = "GLint";
            },
                                       modifyReadFunc: async(context, defaultRead, entry) => {
                var args = entry.Type.Arguments;
                await defaultRead();
                await context.EmitLine($"glShaderSource({args[0].Name}, 1, &{args[1].Name}, &{args[2].Name});");
            }
                                       );

            foreach (var kv in overrides.Registry.Functions)
            {
                foreach (var arg in kv.Value.Type.Arguments)
                {
                    if (arg.Name == "shader")
                    {
                        arg.Type = ResourceHandleType;
                    }
                }
            }
        }
示例#3
0
        public override void InitializeOverrides(CodegenOverrideTracker overrides)
        {
            overrides.RegisterArgumentTypeReadOverride(ResourceHandleType, async(context, function, arg) =>
            {
                await context.EmitLine($"{ResourceHandleType} {arg.Name}Handle = {DataBuffer}.read<{ResourceHandleType}>();");
                await context.EmitLine($"auto& {arg.Name} = *{Resources}.get({arg.Name}Handle);");
            });

            overrides.RegisterOverride("glCreateProgram",
                                       overrideEntry: (fn) => {
                fn.Type.ReturnType = ResourceHandleType;
            },
                                       modifyReadFunc: async(context, defaultRead, entry) => {
                await context.EmitLine($"auto handle = {DataBuffer}.read<{ResourceHandleType}>();");
                await context.EmitLine($"auto& target = *{Resources}.get(handle);");
                await context.EmitLine($"target = glCreateProgram();");
            },
                                       modifyWriteFunc: async(context, defaultWrite, entry) => {
                context.EmitLine();
                await context.EmitLine($"auto handle = {Resources}.create(0);");
                await context.EmitLine($"{DataBuffer}.write(handle);");
                await context.EmitLine($"return handle;");
            }
                                       );

            foreach (var kv in overrides.Registry.Functions)
            {
                if (kv.Key.StartsWith("glProgramUniform"))
                {
                    kv.Value.Type.Arguments[0].Type = ResourceHandleType;
                }

                foreach (var arg in kv.Value.Type.Arguments)
                {
                    if (arg.Name == "program")
                    {
                        arg.Type = ResourceHandleType;
                    }
                }
            }
        }
示例#4
0
        public override void InitializeOverrides(CodegenOverrideTracker overrides)
        {
            overrides.RegisterArgumentTypeReadOverride(ResourceHandleType, async(context, function, arg) =>
            {
                await context.EmitLine($"{ResourceHandleType} {arg.Name}Handle = {DataBuffer}.read<{ResourceHandleType}>();");
                await context.EmitLine($"auto& {arg.Name} = *{Resources}.get({arg.Name}Handle);");
            });

            overrides.RegisterOverride("glCreateTextures",
                                       overrideEntry: (fn) => {
                fn.Name = "glCreateTexture";

                var args = fn.Type.Arguments;
                args.RemoveRange(1, 2);
                fn.Type.ReturnType = ResourceHandleType;
            },
                                       modifyWriteFunc: async(context, defaultWrite, entry) => {
                context.EmitLine();
                var arg = entry.Type.Arguments[0];
                await context.EmitLine($"{DataBuffer}.write({arg.Name});");
                await context.EmitLine($"auto handle = {Resources}.create(0);");
                await context.EmitLine($"{DataBuffer}.write(handle);");
                await context.EmitLine($"return handle;");
            },
                                       modifyReadFunc: async(context, defaultRead, entry) => {
                var arg = entry.Type.Arguments[0];
                await context.EmitLine($"auto {arg.Name} = {DataBuffer}.read<{arg.Type}>();");
                await context.EmitLine($"auto handle = {DataBuffer}.read<{ResourceHandleType}>();");
                await context.EmitLine($"auto& {ResourceType.ToLower()} = *{Resources}.get(handle);");
                await context.EmitLine($"glCreateTextures({arg .Name}, 1, &{ResourceType.ToLower()});");
            }
                                       );

            overrides.RegisterOverride("glGenTextures",
                                       overrideEntry: (fn) => {
                fn.Name = "glGenTexture";

                var args = fn.Type.Arguments;
                args.Clear();
                fn.Type.ReturnType = ResourceHandleType;
            },
                                       modifyWriteFunc: async(context, defaultWrite, entry) => {
                context.EmitLine();
                await context.EmitLine($"auto handle = {Resources}.create(0);");
                await context.EmitLine($"{DataBuffer}.write(handle);");
                await context.EmitLine($"return handle;");
            },
                                       modifyReadFunc: async(context, defaultRead, entry) => {
                await context.EmitLine($"auto handle = {DataBuffer}.read<{ResourceHandleType}>();");
                await context.EmitLine($"auto& {ResourceType.ToLower()} = *{Resources}.get(handle);");
                await context.EmitLine($"glGenTextures(1, &{ResourceType.ToLower()});");
            }
                                       );

            overrides.RegisterOverride("glActiveTexture",
                                       overrideEntry: (fn) => {
                var args           = fn.Type.Arguments;
                args[0].Name       = "textureSlot";
                args[0].Type       = "GLuint";
                args[0].IsEnumType = false;
            },
                                       modifyReadFunc: async(context, defaultRead, entry) => {
                await defaultRead();
                await context.EmitLine("GL_CHECK(glActiveTexture(GL_TEXTURE0 + textureSlot));");
            }
                                       );

            foreach (var kv in overrides.Registry.Functions)
            {
                foreach (var arg in kv.Value.Type.Arguments)
                {
                    if (arg.Name == "texture")
                    {
                        arg.Type = ResourceHandleType;
                    }
                }
            }
        }