Skip to content

Commit

Permalink
Merge branch 'kimkulling/fix_2d_coords' of https://github.com/kimkull…
Browse files Browse the repository at this point in the history
…ing/osre into kimkulling/fix_2d_coords
  • Loading branch information
kimkulling committed Nov 11, 2024
2 parents 5bbcacf + 7678db4 commit 7023c4e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 99 deletions.
73 changes: 0 additions & 73 deletions src/Engine/RenderBackend/2D/CanvasRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,63 +179,6 @@ void CanvasRenderer::preRender(RenderBackendService *rbSrv) {
rbSrv->setMatrix(MatrixType::Projection, m);
}


/* static bool hasTexts(const CanvasRenderer::DrawCmdArray &drawCmdArray) {
if (drawCmdArray.isEmpty()) {
return true;
}
for (size_t i = 0; i < drawCmdArray.size(); ++i) {
if (drawCmdArray[i]->UseFont != nullptr) {
return true;
}
}
return false;
}*/

/* static void createFontMeshes(CanvasRenderer::DrawCmdArray &drawCmdArray, CanvasRenderer::Font2MeshMap &font2MeshMap, MeshInfoArray &meshInfoArray) {
if (hasTexts(drawCmdArray)) {
for (size_t i = 0; i < drawCmdArray.size(); ++i) {
const auto &dc = drawCmdArray[i];
if (dc->UseFont == nullptr) {
continue;
}
const String &keyName = dc->UseFont->Name;
const String meshName = "text." + keyName;
Material *matFont = MaterialBuilder::createTextMaterial(keyName);
Mesh *fontMesh = new Mesh(meshName, VertexType::RenderVertex, IndexType::UnsignedShort);
meshInfoArray.add({fontMesh, PrimitiveType::TriangleList, 0, 0});
fontMesh->setMaterial(matFont);
font2MeshMap[keyName] = fontMesh;
}
}
}
bool getMeshInfo(Mesh *mesh, MeshInfoArray &meshInfoArray, MeshInfo &info) {
if (nullptr == mesh) {
return false;
}
for (size_t i = 0; i < meshInfoArray.size(); ++i) {
if (meshInfoArray[i].mMesh == mesh) {
info = meshInfoArray[i];
return true;
}
}
return false;
}*/

/*void addFontMeshes(CanvasRenderer::Font2MeshMap &font2MeshMap, MeshInfoArray &meshInfoArray, RenderBackendService *rbSrv) {
for (size_t i = 0; i < meshInfoArray.size(); ++i) {
MeshInfo &info = meshInfoArray[i];
rbSrv->addMesh(info.mMesh, 0);
info.mMesh->addPrimitiveGroup(info.mNumIndices, info.mPrim, 0);
}
}*/

void CanvasRenderer::render(RenderBackendService *rbSrv) {
if (rbSrv == nullptr) {
return;
Expand All @@ -244,13 +187,10 @@ void CanvasRenderer::render(RenderBackendService *rbSrv) {
if (!isDirty()) {
return;
}

//MeshInfoArray meshInfoArray;

// Create not textured geometry
if (mMesh == nullptr) {
mMesh = new Mesh("2d", VertexType::RenderVertex, IndexType::UnsignedShort);
//meshInfoArray.add({mMesh, PrimitiveType::TriangleList, 0, 0});
Material *mat2D = MaterialBuilder::create2DMaterial();
if (mat2D == nullptr) {
osre_debug(Tag, "Invalid material instance detected.");
Expand All @@ -259,11 +199,6 @@ void CanvasRenderer::render(RenderBackendService *rbSrv) {
mMesh->setMaterial(mat2D);
}

// Load all font-meshes
/* if (mFont2MeshMap.empty()) {
createFontMeshes(mDrawCmdArray, mFont2MeshMap, meshInfoArray);
}*/

PrimitiveType prim = PrimitiveType::TriangleList;
size_t numVertices = 0l, numIndices = 0l;
for (size_t i=0; i<mDrawCmdArray.size(); ++i) {
Expand All @@ -273,15 +208,9 @@ void CanvasRenderer::render(RenderBackendService *rbSrv) {
continue;
}

/* if (dc.UseFont != nullptr) {
renderFontMesh(dc, mFont2MeshMap, meshInfoArray);
continue;
}*/

const ui32 lastIndex = mMesh->getLastIndex();
renumberIndices(dc, numVertices);

//Debugging::MeshDiagnostic::dumpVertices(dc.Vertices, dc.NumVertices);
mMesh->attachVertices(dc.Vertices, dc.NumVertices * sizeof(RenderVert));
mMesh->attachIndices(dc.Indices, dc.NumIndices * sizeof(ui16));
prim = dc.PrimType;
Expand All @@ -293,8 +222,6 @@ void CanvasRenderer::render(RenderBackendService *rbSrv) {

rbSrv->addMesh(mMesh, 0);

//addFontMeshes(mFont2MeshMap, meshInfoArray, rbSrv);

mDrawCmdArray.resize(0);
setClean();
}
Expand Down
4 changes: 0 additions & 4 deletions src/Engine/RenderBackend/2D/CanvasRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#include "Common/osre_common.h"
#include "RenderBackend/RenderCommon.h"
#include <cppcore/Container/THashMap.h>

#include <map>

namespace OSRE {
namespace RenderBackend {
Expand Down Expand Up @@ -166,7 +163,6 @@ class OSRE_EXPORT CanvasRenderer : public IRenderPath {
i32 mNumLayers;
Font *mFont;
Mesh *mMesh;
//Font2MeshMap mFont2MeshMap;
};

inline void CanvasRenderer::setDirty() {
Expand Down
39 changes: 17 additions & 22 deletions src/Engine/RenderBackend/Text/TextRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
#include "RenderBackend/Text/TextRenderer.h"
#include "RenderBackend/RenderBackendService.h"
#include "RenderBackend/FontService.h"

namespace OSRE {
namespace RenderBackend {

static constexpr c8 Tag[] = "TextRenderer";

/* static void createFontMeshes(DrawCmdArray &drawCmdArray, Font2MeshMap &font2MeshMap, MeshInfoArray &meshInfoArray) {
if (hasTexts(drawCmdArray)) {
for (size_t i = 0; i < drawCmdArray.size(); ++i) {
const auto &dc = drawCmdArray[i];
if (dc->UseFont == nullptr) {
continue;
}
const String &keyName = dc->UseFont->Name;
const String meshName = "text." + keyName;
Material *matFont = MaterialBuilder::createTextMaterial(keyName);
Mesh *fontMesh = new Mesh(meshName, VertexType::RenderVertex, IndexType::UnsignedShort);
meshInfoArray.add({ fontMesh, PrimitiveType::TriangleList, 0, 0 });
fontMesh->setMaterial(matFont);
font2MeshMap[keyName] = fontMesh;
}
}
}*/
bool getMeshInfo(Mesh *mesh, MeshInfoArray &meshInfoArray, MeshInfo &info) {
if (nullptr == mesh) {
return false;
Expand All @@ -40,7 +23,7 @@ bool getMeshInfo(Mesh *mesh, MeshInfoArray &meshInfoArray, MeshInfo &info) {
}


void renderFontMesh(const DrawCmd &dc, Font2MeshMap &font2MeshMap, MeshInfoArray &meshInfoArray) {
void renderFontMesh(const DrawCmd &dc, Font2MeshMap &font2MeshMap, MeshInfoArray &meshInfoArray) {
MeshInfo info;
const String &fontKey = dc.UseFont->Name;
Mesh *textMesh = nullptr;
Expand Down Expand Up @@ -89,16 +72,29 @@ void TextRenderer::addText(i32 x, i32 y, Font *font, const String &text) {
} else {
textMesh = it->second;
}


}

void TextRenderer::preRender(RenderBackendService* rbSrv) {
if (rbSrv == nullptr) {
return;
}

glm::mat4 m(1);
rbSrv->setMatrix(MatrixType::Model, m);
rbSrv->setMatrix(MatrixType::View, m);
rbSrv->setMatrix(MatrixType::Projection, m);
}

void TextRenderer::render(RenderBackendService* rbSrv) {
if (rbSrv == nullptr) {
return;
}

for (auto &it : mFont2MeshMap) {
if (it.second != nullptr) {
rbSrv-
}
}
}

void TextRenderer::postRender(RenderBackendService* rbSrv) {
Expand All @@ -111,6 +107,5 @@ bool TextRenderer::onCreate() {
return (mDefaultFont != nullptr);
}


} // namespace RenderBackend
} // namespace OSRE
1 change: 1 addition & 0 deletions src/Engine/RenderBackend/Text/TextRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class TextRenderer : public IRenderPath {
private:
Font2MeshMap mFont2MeshMap;
Font *mDefaultFont;
MeshInfoArray mMeshInfoArray;
};

} // namespace RenderBackend
Expand Down

0 comments on commit 7023c4e

Please sign in to comment.