<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>graphics.gd:Go 语言的跨平台 2D/3D 图形运行时</title>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style>
/* 独立的名空间样式 */
.graphics-gd-poster {
width: 960px;
min-height: 3000px;
margin: 0 auto;
font-family: 'Noto Sans SC', sans-serif;
background-color: #f8f9fa;
color: #333;
overflow-x: hidden;
box-sizing: border-box;
padding: 40px;
position: relative;
}
.graphics-gd-poster * {
box-sizing: border-box;
}
.graphics-gd-poster h1 {
font-size: 48px;
color: #00add8;
margin-bottom: 20px;
text-align: center;
font-weight: 700;
}
.graphics-gd-poster h2 {
font-size: 32px;
color: #00add8;
margin-top: 40px;
margin-bottom: 20px;
padding-bottom: 10px;
border-bottom: 2px solid #e0e0e0;
}
.graphics-gd-poster h3 {
font-size: 24px;
color: #3788d8;
margin-top: 30px;
margin-bottom: 15px;
}
.graphics-gd-poster p {
font-size: 18px;
line-height: 1.6;
margin-bottom: 20px;
}
.graphics-gd-poster .intro {
background-color: #e6f7ff;
padding: 25px;
border-radius: 8px;
margin-bottom: 40px;
border-left: 5px solid #00add8;
}
.graphics-gd-poster .feature-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 20px;
margin-bottom: 40px;
}
.graphics-gd-poster .feature-card {
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
transition: transform 0.3s ease;
}
.graphics-gd-poster .feature-card:hover {
transform: translateY(-5px);
}
.graphics-gd-poster .feature-card h3 {
margin-top: 0;
display: flex;
align-items: center;
}
.graphics-gd-poster .feature-card .material-icons {
margin-right: 10px;
color: #00add8;
}
.graphics-gd-poster .code-block {
background-color: #2d2d2d;
color: #f8f8f2;
padding: 20px;
border-radius: 8px;
margin-bottom: 30px;
overflow-x: auto;
font-family: 'Consolas', 'Monaco', monospace;
}
.graphics-gd-poster .code-block pre {
margin: 0;
white-space: pre-wrap;
}
.graphics-gd-poster .code-block .code-language {
color: #6272a4;
font-size: 14px;
margin-bottom: 10px;
}
.graphics-gd-poster .platform-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 15px;
margin-bottom: 30px;
}
.graphics-gd-poster .platform-card {
background-color: white;
padding: 15px;
border-radius: 8px;
text-align: center;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.graphics-gd-poster .platform-card .material-icons {
font-size: 36px;
color: #00add8;
margin-bottom: 10px;
}
.graphics-gd-poster .platform-card h4 {
margin: 0 0 5px 0;
font-size: 18px;
}
.graphics-gd-poster .platform-card p {
margin: 0;
font-size: 14px;
}
.graphics-gd-poster .logo-container {
display: flex;
justify-content: center;
margin: 30px 0;
}
.graphics-gd-poster .logo-container img {
height: 80px;
margin: 0 20px;
}
.graphics-gd-poster .architecture-diagram {
background-color: white;
padding: 20px;
border-radius: 8px;
margin-bottom: 30px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.graphics-gd-poster .architecture-diagram h3 {
text-align: center;
margin-bottom: 20px;
}
.graphics-gd-poster .architecture-layers {
display: flex;
flex-direction: column;
gap: 10px;
}
.graphics-gd-poster .architecture-layer {
padding: 15px;
border-radius: 5px;
text-align: center;
font-weight: 500;
}
.graphics-gd-poster .layer-app {
background-color: #e6f7ff;
border: 1px solid #91d5ff;
}
.graphics-gd-poster .layer-gd {
background-color: #bae7ff;
border: 1px solid #69c0ff;
}
.graphics-gd-poster .layer-gdextension {
background-color: #91d5ff;
border: 1px solid #40a9ff;
}
.graphics-gd-poster .layer-godot {
background-color: #69c0ff;
border: 1px solid #1890ff;
}
.graphics-gd-poster .performance-list {
list-style-type: none;
padding: 0;
}
.graphics-gd-poster .performance-list li {
background-color: white;
padding: 15px;
margin-bottom: 10px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
display: flex;
align-items: center;
}
.graphics-gd-poster .performance-list .material-icons {
margin-right: 15px;
color: #52c41a;
}
.graphics-gd-poster .community-section {
background-color: #f0f5ff;
padding: 25px;
border-radius: 8px;
margin-top: 40px;
}
.graphics-gd-poster .community-links {
display: flex;
justify-content: space-around;
margin-top: 20px;
}
.graphics-gd-poster .community-link {
display: flex;
flex-direction: column;
align-items: center;
text-decoration: none;
color: #333;
}
.graphics-gd-poster .community-link .material-icons {
font-size: 36px;
color: #00add8;
margin-bottom: 10px;
}
.graphics-gd-poster .highlight {
background-color: #fffbe6;
padding: 2px 5px;
border-radius: 3px;
font-weight: 500;
}
</style>
</head>
<body>
<div class="graphics-gd-poster">
<h1>graphics.gd:Go 语言的跨平台 2D/3D 图形运行时</h1>
<div class="logo-container">
<img src="https://sfile.chatglm.cn/moeSlide/image/b7/b789060d.jpg" alt="Go Logo">
<img src="https://sfile.chatglm.cn/moeSlide/image/94/94654def.jpg" alt="Godot Engine Logo">
</div>
<div class="intro">
<p><strong>graphics.gd</strong> 是一个专为 Go 语言设计的跨平台 2D/3D 图形运行时,它基于 Godot Engine 和 GDExtension 构建,适用于开发原生移动应用、游戏、多媒体应用等多种场景。与传统的 Godot 脚本语言(如 GDScript)不同,graphics.gd 提供了类型安全的 API,使开发者能够使用 Go 的强大功能来构建高性能的图形应用程序。</p>
</div>
<h2>原理与架构</h2>
<div class="architecture-diagram">
<h3>graphics.gd 架构层次</h3>
<div class="architecture-layers">
<div class="architecture-layer layer-app">应用层 (Go 代码)</div>
<div class="architecture-layer layer-gd">graphics.gd 层 (Go 包装器)</div>
<div class="architecture-layer layer-gdextension">GDExtension 层 (C 接口)</div>
<div class="architecture-layer layer-godot">Godot Engine 层 (C++ 核心)</div>
</div>
</div>
<p>graphics.gd 的设计思想是将 Godot Engine 的强大功能与 Go 语言的简洁性、高效性和类型安全性相结合。它不仅仅是一个简单的 GDExtension 包装器,而是经过精心设计的工具包,为 Go 开发者提供了在 Godot 生态系统中的无缝体验。</p>
<p>在架构设计上,graphics.gd 采用了分层结构:</p>
<ul>
<li><strong>应用层</strong>:开发者使用 Go 语言编写的应用程序代码,通过 graphics.gd 提供的 API 与 Godot Engine 交互。</li>
<li><strong>graphics.gd 层</strong>:提供 Go 语言的 API 包装器,将 Godot 的功能暴露给 Go 开发者,同时保持类型安全和 Go 的编程习惯。</li>
<li><strong>GDExtension 层</strong>:作为 Godot Engine 和 graphics.gd 之间的桥梁,提供了 C 语言接口,使得 Go 代码能够调用 Godot 的核心功能。</li>
<li><strong>Godot Engine 层</strong>:提供底层的 2D/3D 渲染、物理模拟、音频处理等核心功能。</li>
</ul>
<p>graphics.gd 的设计理念是让 Go 开发者能够充分利用 Godot Engine 的功能,同时保持 Go 语言的类型安全性和高性能。通过精心设计的 API,graphics.gd 将 Godot 的面向对象模型转换为 Go 的接口和结构体,使得 Go 开发者能够以自然的方式使用 Godot 的功能。</p>
<h2>核心特性</h2>
<div class="feature-grid">
<div class="feature-card">
<h3><i class="material-icons">code</i>用 Go 编写着色器</h3>
<p>graphics.gd 允许开发者使用熟悉的 Go 语法来编写复杂的图形逻辑,而不需要学习传统的着色器语言。这使得着色器开发更加直观和易于维护。</p>
</div>
<div class="feature-card">
<h3><i class="material-icons">security</i>类型安全优先</h3>
<p>与 GDScript 不同,graphics.gd 中的 RIDs、Callables 和字典参数都是强类型的,这有助于在编译时捕获错误,而不是在运行时才发现问题。</p>
</div>
<div class="feature-card">
<h3><i class="material-icons">speed</i>性能导向</h3>
<p>graphics.gd 在设计上平衡了性能和便利性,通过最小化频繁调用函数的内存分配,确保应用程序能够高效运行。</p>
</div>
<div class="feature-card">
<h3><i class="material-icons">autorenew</i>快速迭代</h3>
<p>首次构建后,重新编译的速度非常快,提供了类似于脚本语言的开发体验,使开发者能够快速迭代和测试他们的想法。</p>
</div>
<div class="feature-card">
<h3><i class="material-icons">devices</i>跨平台支持</h3>
<p>可以从任何开发平台交叉编译到 Windows、Linux、macOS、Android、iOS 和 Web,极大地简化了多平台开发流程。</p>
</div>
<div class="feature-card">
<h3><i class="material-icons">package</i>纯 Go 包</h3>
<p>提供了通用的 "variant" 包,可以在游戏开发之外的任何 Go 项目中重用,增加了代码的可复用性。</p>
</div>
</div>
<h2>使用示例</h2>
<p>下面是一个简单的 Hello World 示例,展示了如何使用 graphics.gd 创建一个基本的图形应用程序:</p>
<div class="code-block">
<div class="code-language">go</div>
<pre>// 这个文件是你开始一个项目所需的全部内容
// 将它保存在某处,安装 `gd` 命令并使用 `gd run` 开始
package main
import (
"graphics.gd/startup"
"graphics.gd/classdb/Control"
"graphics.gd/classdb/GUI"
"graphics.gd/classdb/Label"
"graphics.gd/classdb/SceneTree"
)
func main() {
startup.LoadingScene() // 设置 SceneTree 并等待直到我们可以访问引擎功能
hello := Label.New()
hello.AsControl().SetAnchorsPreset(Control.PresetFullRect) // 扩展标签以占据整个屏幕
hello.SetHorizontalAlignment(GUI.HorizontalAlignmentCenter)
hello.SetVerticalAlignment(GUI.VerticalAlignmentCenter)
hello.SetText("Hello, World!")
SceneTree.Add(hello)
startup.Scene() // 启动场景并阻塞直到引擎关闭
}</pre>
</div>
<p>graphics.gd 的 API 设计遵循 Go 的命名约定,将 Godot 的下划线命名法转换为 PascalCase。例如,Godot 中的 <span class="highlight">set_text</span> 方法在 graphics.gd 中变为 <span class="highlight">SetText</span>。这使得 Go 开发者能够以更自然的方式使用 API。</p>
<p>每个引擎类都在 <span class="highlight">classdb</span> 下作为一个包提供。要导入 <span class="highlight">Node</span> 类,可以导入 <span class="highlight">"graphics.gd/classdb/Node"</span>。graphics.gd 中没有继承,所以要访问"超"类,需要在扩展类上调用 <span class="highlight">AsClassName()</span>。所有引擎类都有方法可以转换到它们扩展的任何类,例如 <span class="highlight">AsObject()</span> 或 <span class="highlight">AsNode2D()</span>。</p>
<h2>性能特点</h2>
<p>graphics.gd 从设计之初就注重性能,通过多种策略确保应用程序能够高效运行:</p>
<ul class="performance-list">
<li><i class="material-icons">memory</i><strong>零分配方法调用</strong>:使用 Advanced 实例时,Go 到引擎的方法调用实际上不分配内存,这使得频繁调用的函数能够保持高性能。</li>
<li><i class="material-icons">sync</i><strong>虚拟方法重写</strong>:Ready、Process 和其他虚拟方法完全避免内存分配,减少了垃圾收集的压力。</li>
<li><i class="material-icons">autorenew</i><strong>基于帧的内存管理</strong>:自动垃圾收集确保内存安全,无需手动管理,同时优化了内存使用模式。</li>
<li><i class="material-icons">settings</i><strong>细粒度控制</strong>:Advanced 实例为每个类提供更精细的内存分配控制,使开发者能够根据需要优化性能。</li>
</ul>
<p>为了获得最佳性能,graphics.gd 推荐以下实践:</p>
<ul>
<li>尽可能使用引擎类型,而不是自定义类型</li>
<li>在热路径中避免堆内存分配</li>
<li>对于精细控制,优先使用 Advanced 方法</li>
<li>使用服务器和系统而不是大量对象</li>
</ul>
<h2>平台支持</h2>
<p>graphics.gd 支持多种主流平台,使开发者能够轻松地将应用程序部署到不同的设备和操作系统:</p>
<div class="platform-grid">
<div class="platform-card">
<i class="material-icons">computer</i>
<h4>Windows</h4>
<p>稳定支持</p>
</div>
<div class="platform-card">
<i class="material-icons">desktop_linux</i>
<h4>Linux</h4>
<p>稳定支持</p>
</div>
<div class="platform-card">
<i class="material-icons">laptop_mac</i>
<h4>macOS</h4>
<p>稳定支持</p>
</div>
<div class="platform-card">
<i class="material-icons">android</i>
<h4>Android</h4>
<p>稳定支持</p>
</div>
<div class="platform-card">
<i class="material-icons">phone_iphone</i>
<h4>iiOS</h4>
<p>稳定支持</p>
</div>
<div class="platform-card">
<i class="material-icons">language</i>
<h4>Web</h4>
<p>稳定支持</p>
</div>
</div>
<p><strong>平台限制:</strong></p>
<ul>
<li>仅支持 64 位系统(arm64、amd64 和 wasm)</li>
<li>目前不支持 PlayStation/Xbox/Switch 游戏主机(未来可能通过 WASI、wasm2c 或 hitsumabushi 实现)</li>
</ul>
<h2>社区与贡献</h2>
<div class="community-section">
<p>graphics.gd 是一个开源项目,欢迎社区参与和贡献。无论你是报告问题、提交代码、编写文档还是分享使用经验,你的贡献都将帮助 graphics.gd 变得更好。</p>
<p>参与社区的最佳方式是尝试使用 graphics.gd,并告诉我们什么有效,什么无效。任何你能贡献的示例都是受欢迎的。</p>
<p>如果你喜欢寻找内存安全问题,我们非常欢迎你的帮助。graphics.gd 还需要更多的测试来确保一切正常工作,你能为 graphics.gd 提供稳定性的最好方式是贡献测试,覆盖你需要的任何功能!</p>
<div class="community-links">
<a href="https://github.com/quaadgras/graphics.gd/discussions" class="community-link">
<i class="material-icons">forum</i>
<span>社区讨论</span>
</a>
<a href="https://github.com/quaadgras/graphics.gd/issues" class="community-link">
<i class="material-icons">bug_report</i>
<span>报告问题</span>
</a>
<a href="https://github.com/quaadgras/graphics.gd" class="community-link">
<i class="material-icons">code</i>
<span>查看源码</span>
</a>
<a href="https://github.com/sponsors/Splizard" class="community-link">
<i class="material-icons">favorite</i>
<span>赞助项目</span>
</a>
</div>
</div>
</div>
</body>
</html>
登录后可参与表态