Compare commits

..

2 Commits

Author SHA1 Message Date
ChestnutYueyue e011cea090 style: 调整main.cpp的代码格式和include顺序
- 统一缩进为2个空格
- 调整头文件include顺序
- 移除多余的注释分隔线
2026-03-03 19:41:20 +08:00
ChestnutYueyue d5cb194552 refactor(shader): 移除实例化渲染相关的着色器文件
这些着色器文件用于已废弃的实例化渲染功能,现已被更高效的实现方式取代
2026-03-03 19:37:34 +08:00
3 changed files with 42 additions and 154 deletions

View File

@ -12,9 +12,9 @@
* - SpriteRenderer
*/
#include <extra2d.h>
#include "game_scene.h"
#include <cstdio>
#include <extra2d.h>
using namespace extra2d;
@ -22,58 +22,54 @@ using namespace extra2d;
* @brief
*/
int main(int argc, char **argv) {
// ========================================
// 1. 创建应用
// ========================================
auto app = Application::create();
// ========================================
// 1. 创建应用
// ========================================
auto app = Application::create();
AppConfig config;
config.title = "Scene Graph Demo - Extra2D";
config.width = 1280;
config.height = 720;
AppConfig config;
config.title = "Scene Graph Demo - Extra2D";
config.width = 1280;
config.height = 720;
if (!app->init(config)) {
printf("Failed to initialize application!\n");
return -1;
}
if (!app->init(config)) {
printf("Failed to initialize application!\n");
return -1;
}
// ========================================
// 2. 获取场景模块和导演
// ========================================
SceneModule *sceneModule = app->getModule<SceneModule>();
if (!sceneModule) {
printf("Failed to get SceneModule!\n");
return -1;
}
printf("Application initialized successfully\n");
printf("Window size: %dx%d\n", app->getWindowWidth(), app->getWindowHeight());
Director *director = sceneModule->getDirector();
if (!director) {
printf("Failed to get Director!\n");
return -1;
}
// ========================================
// 2. 获取场景模块和导演
// ========================================
SceneModule *sceneModule = app->getModule<SceneModule>();
if (!sceneModule) {
printf("Failed to get SceneModule!\n");
return -1;
}
printf("Scene module and director ready\n");
Director *director = sceneModule->getDirector();
if (!director) {
printf("Failed to get Director!\n");
return -1;
}
// ========================================
// 3. 创建并运行游戏场景
// ========================================
auto gameScene = makePtr<GameScene>();
director->runScene(gameScene);
printf("Scene module and director ready\n");
printf("Game scene started\n");
// ========================================
// 3. 创建并运行游戏场景
// ========================================
auto gameScene = makePtr<GameScene>();
director->runScene(gameScene);
// ========================================
// 4. 运行应用主循环
// ========================================
app->run();
printf("Game scene started\n");
// ========================================
// 5. 清理(自动进行)
// ========================================
printf("Application shutting down...\n");
// ========================================
// 4. 运行应用主循环
// ========================================
app->run();
// ========================================
// 5. 清理(自动进行)
// ========================================
printf("Application shutting down...\n");
return 0;
return 0;
}

View File

@ -1,73 +0,0 @@
#version 320 es
precision highp float;
// 全局 UBO (binding = 0) - 每帧更新一次
layout(std140, binding = 0) uniform GlobalUBO {
mat4 uViewProjection;
vec4 uCameraPosition;
float uTime;
float uDeltaTime;
vec2 uScreenSize;
};
// 材质 UBO (binding = 1) - 每批次更新
layout(std140, binding = 1) uniform MaterialUBO {
vec4 uColor;
vec4 uTintColor;
float uOpacity;
float uPadding[3]; // std140 对齐填充
};
// 顶点属性 (每个顶点)
layout(location = 0) in vec2 aPosition;
layout(location = 1) in vec2 aTexCoord;
layout(location = 2) in vec4 aColor;
// 实例属性 (每个实例) - 使用 location 3-6
layout(location = 3) in vec2 iPosition; // 实例位置
layout(location = 4) in float iRotation; // 实例旋转
layout(location = 5) in vec2 iScale; // 实例缩放
layout(location = 6) in vec4 iColor; // 实例颜色
// 输出到片段着色器
out vec2 vTexCoord;
out vec4 vColor;
out vec4 vTintColor;
out float vOpacity;
/**
* @brief 2D变换矩阵
* @param angle
* @return 2x2旋转矩阵
*/
mat2 rotate2D(float angle) {
float c = cos(angle);
float s = sin(angle);
return mat2(c, -s, s, c);
}
/**
* @brief
*
*
*
*
*/
void main() {
// 应用实例缩放和旋转
vec2 localPos = rotate2D(iRotation) * (aPosition * iScale);
// 应用实例位置偏移
vec2 worldPos = localPos + iPosition;
// 变换到裁剪空间
gl_Position = uViewProjection * vec4(worldPos, 0.0, 1.0);
vTexCoord = aTexCoord;
// 混合顶点颜色、实例颜色和材质颜色
vColor = aColor * iColor * uColor;
vTintColor = uTintColor;
vOpacity = uOpacity;
}

View File

@ -1,35 +0,0 @@
#version 320 es
precision highp float;
// 从顶点着色器输入
in vec2 vTexCoord;
in vec4 vColor;
// 纹理采样器
uniform sampler2D uTexture;
// 输出颜色
out vec4 fragColor;
/**
* @brief
*
*
*/
void main() {
// 采样纹理
vec4 texColor = texture(uTexture, vTexCoord);
// 如果纹理采样结果是黑色或透明,使用白色作为默认值
if (texColor.rgb == vec3(0.0) || texColor.a < 0.01) {
texColor = vec4(1.0, 1.0, 1.0, 1.0);
}
// 混合:纹理 * 顶点颜色
fragColor = texColor * vColor;
// Alpha 测试:丢弃几乎透明的像素
if (fragColor.a < 0.01) {
discard;
}
}