Skip to content

Commit 040df4b

Browse files
committed
Squash commits
1 parent a90a60c commit 040df4b

122 files changed

Lines changed: 6993 additions & 1031 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1k/build.profiles

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,5 @@ kcp=2.1.1
9999
lz4=v1.10.0
100100
sample-assets=master
101101
live2d-core=5.5
102+
openxr=release-1.1.60
102103
# --- endregion

1k/fetch.ps1

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,18 @@ if (!(Test-Path "$lib_src/.git" -PathType Container)) { $is_git_repo = $false }
207207

208208
# checkout revision for git repo
209209
if (!$revision) {
210-
# regard v as tag or doesn't ends with short git hash
211-
if ($version.StartsWith('v')) {
212-
$revision = $version
210+
# Treat versions ending with "-<git-hash>" as pinned commits, for example:
211+
# 1.2.3-a1b2c3d
212+
# release-1.2.3-a1b2c3d4e5f6
213+
# Other names, including "v1.2.3", "release-1.2.3" and custom tag/branch names,
214+
# are passed through as-is and resolved by git below.
215+
$match_info = [Regex]::Match($version, '^(.*)-([0-9a-fA-F]{7,40})$')
216+
if ($match_info.Success) {
217+
$version = $match_info.Groups[1].Value
218+
$revision = $match_info.Groups[2].Value
213219
}
214220
else {
215-
$ver_pair = [array]$version.Split('-')
216-
$use_hash = $ver_pair.Count -gt 1
217-
$revision = $ver_pair[$use_hash].Trim()
218-
$version = $ver_pair[0]
221+
$revision = $version
219222
}
220223
}
221224

1k/sources.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
"gitee": "https://gitee.com/simdsoft/lz4.git"
2929
}
3030
},
31+
"openxr": {
32+
"sources": { "origin": "https://github.com/KhronosGroup/OpenXR-SDK.git" }
33+
},
3134
"sample-assets": {
3235
"sources": {
3336
"origin": "https://github.com/axmolengine/axmol-sample-assets.git",

3rdparty/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ if(ANDROID)
140140
endif()
141141

142142
ax_add_3rd(fmt)
143+
if (TARGET fmt-c)
144+
set_target_properties(fmt-c PROPERTIES FOLDER "3rdparty")
145+
endif()
143146

144147
# bellow are non header only libs
145148

@@ -427,6 +430,12 @@ ax_add_3rd(yasio)
427430
# simdjson
428431
ax_add_3rd(simdjson)
429432

433+
# openxr
434+
if (AX_ENABLE_OPENXR)
435+
_1kfetch(openxr)
436+
ax_add_3rd(${openxr_SOURCE_DIR} TARGETS openxr_loader)
437+
endif()
438+
430439
if(ANDROID)
431440
function(config_android_shared_libs package_name target_folder)
432441
string(REPLACE "." "/" package_path ${package_name})

axmol/2d/Grid.cpp

Lines changed: 117 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,63 @@ THE SOFTWARE.
3131
#include "axmol/base/Utils.h"
3232
#include "axmol/scene/Node.h"
3333
#include "axmol/renderer/Renderer.h"
34+
#include "axmol/renderer/RenderTexturePass.h"
3435
#include "axmol/renderer/Texture2D.h"
3536
#include "axmol/renderer/Shaders.h"
3637
#include "axmol/rhi/ProgramState.h"
3738
#include "axmol/rhi/RenderTarget.h"
3839
#include "axmol/rhi/DriverContext.h"
3940
#include "axmol/scene/Camera.h"
41+
#include "axmol/math/Vec4.h"
42+
43+
#include <cmath>
4044

4145
namespace ax
4246
{
47+
48+
static constexpr float GRID_BLIT_ORDER = RT_PASS_END_ORDER - 1;
49+
50+
static bool projectGridPointToCanvas(const Mat4& projection, const Vec3& point, const Vec2& size, Vec2& out)
51+
{
52+
if (size.width <= 0.0f || size.height <= 0.0f)
53+
return false;
54+
55+
Vec4 clip(point.x, point.y, point.z, 1.0f);
56+
projection.transformVector(&clip);
57+
58+
if (std::abs(clip.w) <= 0.000001f)
59+
return false;
60+
61+
const float ndcX = clip.x / clip.w;
62+
const float ndcY = clip.y / clip.w;
63+
out.set((ndcX + 1.0f) * 0.5f * size.width, (ndcY + 1.0f) * 0.5f * size.height);
64+
return true;
65+
}
66+
67+
static Vec2 projectGridTexCoordToCanvas(const Mat4& projection,
68+
const Vec3& point,
69+
const Vec2& size,
70+
bool flipped,
71+
const Vec2& fallbackUV)
72+
{
73+
Vec2 projected;
74+
if (!projectGridPointToCanvas(projection, point, size, projected))
75+
return fallbackUV;
76+
77+
Vec2 uv(projected.x / size.width, projected.y / size.height);
78+
if (flipped)
79+
uv.y = 1.0f - uv.y;
80+
return uv;
81+
}
82+
83+
static Vec3 projectGridVertexToCanvas(const Mat4& projection, const Vec3& point, const Vec2& size)
84+
{
85+
Vec2 projected;
86+
if (projectGridPointToCanvas(projection, point, size, projected))
87+
return Vec3(projected.x, projected.y, 0.0f);
88+
89+
return point;
90+
}
4391
// implementation of GridBase
4492

4593
bool GridBase::initWithSize(const Vec2& gridSize)
@@ -157,40 +205,29 @@ void GridBase::setGridRect(const ax::Rect& rect)
157205

158206
void GridBase::beforeDraw()
159207
{
160-
Director* director = Director::getInstance();
161-
162-
auto* renderer = director->getRenderer();
163-
auto* groupCommand = renderer->getNextGroupCommand();
164-
groupCommand->init(0);
165-
renderer->addCommand(groupCommand);
166-
renderer->pushGroup(groupCommand->getRenderQueueID());
208+
AX_SAFE_RELEASE(_renderTarget);
209+
_renderTarget = axdrv->createRenderTarget(_texture->getRHITexture());
167210

168-
auto beforeDrawCommandFunc = [director, renderer, this]() -> void {
169-
Vec2 size = director->getCanvasSizeInPixels();
170-
renderer->setViewport(0, 0, (unsigned int)size.width, (unsigned int)size.height);
211+
if (!_renderTexturePass)
212+
{
213+
_renderTexturePass = RefPtr<RenderTexturePass>(RenderTexturePass::obtain(), tlx::adopt_object);
214+
_renderTexturePass->setCameraOverrideEnabled(false);
215+
}
171216

172-
_oldRenderTarget = renderer->getRenderTarget();
173-
AX_SAFE_RELEASE(_renderTarget);
174-
_renderTarget = axdrv->createRenderTarget(_texture->getRHITexture());
175-
renderer->setRenderTarget(_renderTarget);
176-
};
177-
renderer->addCallbackCommand(beforeDrawCommandFunc);
217+
_renderTexturePass->setTarget(_renderTarget);
218+
_renderTexturePass->setViewport(
219+
Viewport(0, 0, static_cast<int>(_texture->getWidth()), static_cast<int>(_texture->getHeight())));
220+
_renderTexturePass->begin();
178221

179-
// since we use clearCommand, should call at here to avoid iterator damage
180-
renderer->clear(TargetBufferFlags::COLOR, _clearColor, 1, 0, 0.0);
222+
_renderTexturePass->clear(ClearFlag::COLOR, {.color = _clearColor, .depth = 1.0f, .stencil = 0});
181223
}
182224

183225
void GridBase::afterDraw(ax::Node* /*target*/)
184226
{
185227
auto renderer = Director::getInstance()->getRenderer();
186228

187-
renderer->addCallbackCommand([renderer, this]() -> void {
188-
const auto& vp = Camera::getDefaultViewport();
189-
renderer->setViewport(vp.x, vp.y, vp.width, vp.height);
190-
renderer->setRenderTarget(_oldRenderTarget);
191-
});
192-
193-
renderer->popGroup();
229+
if (_renderTexturePass && _renderTexturePass->isActive())
230+
_renderTexturePass->end();
194231

195232
renderer->addCallbackCommand([this]() -> void { beforeBlit(); });
196233

@@ -199,6 +236,16 @@ void GridBase::afterDraw(ax::Node* /*target*/)
199236
renderer->addCallbackCommand([this]() -> void { afterBlit(); });
200237
}
201238

239+
void GridBase::setScreenProjectionForBlit(const Mat4* projection, const Vec2& size)
240+
{
241+
_screenProjectionForBlitEnabled = projection && size.width > 0.0f && size.height > 0.0f;
242+
if (_screenProjectionForBlitEnabled)
243+
{
244+
_screenProjectionForBlit = *projection;
245+
_screenProjectionForBlitSize = size;
246+
}
247+
}
248+
202249
// implementation of Grid3D
203250

204251
Grid3D* Grid3D::create(const Vec2& gridSize)
@@ -305,9 +352,10 @@ void Grid3D::afterBlit()
305352
void Grid3D::blit()
306353
{
307354
updateVertexBuffer();
308-
_drawCommand.init(0, _blendFunc);
355+
_drawCommand.init(GRID_BLIT_ORDER, _blendFunc);
309356
Director::getInstance()->getRenderer()->addCommand(&_drawCommand);
310-
ax::Mat4 projectionMat = Camera::getVisitingViewProjectionMatrix();
357+
auto camera = Camera::getVisitingCamera();
358+
ax::Mat4 projectionMat = camera ? camera->getVisitingViewProjectionMatrix() : Mat4::identity;
311359
auto programState = _drawCommand.unsafePS();
312360
programState->setUniform(_mvpMatrixLocation, projectionMat.m, sizeof(projectionMat.m));
313361
programState->setTexture(_textureLocation, 0, _texture->getRHITexture());
@@ -446,12 +494,28 @@ void Grid3D::reuse()
446494

447495
void Grid3D::updateVertexBuffer()
448496
{
449-
size_t numOfPoints = static_cast<size_t>((_gridSize.width + 1) * (_gridSize.height + 1));
450-
auto tempVecPointer = (Vec3*)_vertices;
497+
size_t numOfPoints = static_cast<size_t>((_gridSize.width + 1) * (_gridSize.height + 1));
498+
auto tempVecPointer = (Vec3*)_vertices;
499+
auto tempOriginalVecPointer = (Vec3*)_originalVertices;
500+
auto tempTexPointer = (Vec2*)_texCoordinates;
451501
for (size_t i = 0; i < numOfPoints; ++i)
452502
{
453503
auto offset = i * (sizeof(Vec3) + sizeof(Vec2));
454-
memcpy((char*)_vertexBuffer + offset, &tempVecPointer[i], sizeof(Vec3));
504+
if (_screenProjectionForBlitEnabled)
505+
{
506+
auto vertex =
507+
projectGridVertexToCanvas(_screenProjectionForBlit, tempVecPointer[i], _screenProjectionForBlitSize);
508+
auto texCoord =
509+
projectGridTexCoordToCanvas(_screenProjectionForBlit, tempOriginalVecPointer[i],
510+
_screenProjectionForBlitSize, _isTextureFlipped, tempTexPointer[i]);
511+
memcpy((char*)_vertexBuffer + offset, &vertex, sizeof(Vec3));
512+
memcpy((char*)_vertexBuffer + offset + sizeof(Vec3), &texCoord, sizeof(Vec2));
513+
}
514+
else
515+
{
516+
memcpy((char*)_vertexBuffer + offset, &tempVecPointer[i], sizeof(Vec3));
517+
memcpy((char*)_vertexBuffer + offset + sizeof(Vec3), &tempTexPointer[i], sizeof(Vec2));
518+
}
455519
}
456520
_drawCommand.updateVertexBuffer(_vertexBuffer,
457521
(unsigned int)(numOfPoints * sizeof(Vec3) + numOfPoints * sizeof(Vec2)));
@@ -561,9 +625,10 @@ TiledGrid3D* TiledGrid3D::create(const Vec2& gridSize, Texture2D* texture, bool
561625
void TiledGrid3D::blit()
562626
{
563627
updateVertexBuffer();
564-
_drawCommand.init(0, _blendFunc);
628+
_drawCommand.init(GRID_BLIT_ORDER, _blendFunc);
565629
Director::getInstance()->getRenderer()->addCommand(&_drawCommand);
566-
ax::Mat4 projectionMat = Camera::getVisitingViewProjectionMatrix();
630+
auto camera = Camera::getVisitingCamera();
631+
ax::Mat4 projectionMat = camera ? camera->getVisitingViewProjectionMatrix() : Mat4::identity;
567632
auto programState = _drawCommand.unsafePS();
568633
programState->setUniform(_mvpMatrixLocation, projectionMat.m, sizeof(projectionMat.m));
569634
programState->setTexture(_textureLocation, 0, _texture->getRHITexture());
@@ -700,13 +765,29 @@ void TiledGrid3D::reuse()
700765

701766
void TiledGrid3D::updateVertexBuffer()
702767
{
703-
size_t gradSize = static_cast<size_t>(_gridSize.width * _gridSize.height);
704-
size_t numOfPoints = gradSize * 4;
705-
auto tempVecPointer = (Vec3*)_vertices;
768+
size_t gradSize = static_cast<size_t>(_gridSize.width * _gridSize.height);
769+
size_t numOfPoints = gradSize * 4;
770+
auto tempVecPointer = (Vec3*)_vertices;
771+
auto tempOriginalVecPointer = (Vec3*)_originalVertices;
772+
auto tempTexPointer = (Vec2*)_texCoordinates;
706773
for (size_t i = 0; i < numOfPoints; ++i)
707774
{
708775
auto offset = i * (sizeof(Vec3) + sizeof(Vec2));
709-
memcpy((char*)_vertexBuffer + offset, &tempVecPointer[i], sizeof(Vec3));
776+
if (_screenProjectionForBlitEnabled)
777+
{
778+
auto vertex =
779+
projectGridVertexToCanvas(_screenProjectionForBlit, tempVecPointer[i], _screenProjectionForBlitSize);
780+
auto texCoord =
781+
projectGridTexCoordToCanvas(_screenProjectionForBlit, tempOriginalVecPointer[i],
782+
_screenProjectionForBlitSize, _isTextureFlipped, tempTexPointer[i]);
783+
memcpy((char*)_vertexBuffer + offset, &vertex, sizeof(Vec3));
784+
memcpy((char*)_vertexBuffer + offset + sizeof(Vec3), &texCoord, sizeof(Vec2));
785+
}
786+
else
787+
{
788+
memcpy((char*)_vertexBuffer + offset, &tempVecPointer[i], sizeof(Vec3));
789+
memcpy((char*)_vertexBuffer + offset + sizeof(Vec3), &tempTexPointer[i], sizeof(Vec2));
790+
}
710791
}
711792
_drawCommand.updateVertexBuffer(_vertexBuffer,
712793
(unsigned int)(numOfPoints * sizeof(Vec3) + numOfPoints * sizeof(Vec2)));

axmol/2d/Grid.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ THE SOFTWARE.
2828
#pragma once
2929

3030
#include "axmol/base/Object.h"
31+
#include "axmol/base/RefPtr.h"
3132
#include "axmol/base/Types.h"
3233
#include "axmol/base/Director.h"
3334
#include "axmol/renderer/GroupCommand.h"
@@ -39,6 +40,8 @@ namespace ax
3940

4041
class Texture2D;
4142
class Node;
43+
class NodeGrid;
44+
class RenderTexturePass;
4245

4346
namespace rhi
4447
{
@@ -134,6 +137,13 @@ class AX_DLL GridBase : public Object
134137
const Rect& getGridRect() const { return _gridRect; }
135138

136139
protected:
140+
friend class NodeGrid;
141+
142+
/** Internal NodeGrid hook: project uploaded blit vertices/UVs through
143+
* the capture camera while still drawing with the grid ortho camera.
144+
*/
145+
void setScreenProjectionForBlit(const Mat4* projection, const Vec2& size);
146+
137147
void updateBlendState();
138148

139149
bool _active = false;
@@ -152,16 +162,19 @@ class AX_DLL GridBase : public Object
152162
// CallbackCommand _beforeBlitCommand;
153163
// CallbackCommand _afterBlitCommand;
154164

155-
// New
156-
rhi::RenderTarget* _oldRenderTarget = nullptr;
157-
rhi::RenderTarget* _renderTarget = nullptr;
165+
rhi::RenderTarget* _renderTarget = nullptr;
166+
RefPtr<RenderTexturePass> _renderTexturePass;
158167

159168
rhi::UniformLocation _mvpMatrixLocation;
160169
rhi::UniformLocation _textureLocation;
161170
rhi::ProgramState* _programState = nullptr;
162171
rhi::VertexLayout* _vertexLayout = nullptr;
163172

164173
BlendFunc _blendFunc;
174+
175+
bool _screenProjectionForBlitEnabled = false;
176+
Mat4 _screenProjectionForBlit = Mat4::identity;
177+
Vec2 _screenProjectionForBlitSize;
165178
};
166179

167180
/**

0 commit comments

Comments
 (0)