|
@@ -23,12 +23,13 @@
|
|
|
#include "PolyScreenMesh.h"
|
|
#include "PolyScreenMesh.h"
|
|
|
#include "PolyCoreServices.h"
|
|
#include "PolyCoreServices.h"
|
|
|
#include "PolyMaterialManager.h"
|
|
#include "PolyMaterialManager.h"
|
|
|
|
|
+#include "PolyResourceManager.h"
|
|
|
#include "PolyMesh.h"
|
|
#include "PolyMesh.h"
|
|
|
#include "PolyRenderer.h"
|
|
#include "PolyRenderer.h"
|
|
|
|
|
|
|
|
using namespace Polycode;
|
|
using namespace Polycode;
|
|
|
|
|
|
|
|
-ScreenMesh::ScreenMesh(Mesh *mesh) : ScreenEntity(), texture(NULL) {
|
|
|
|
|
|
|
+ScreenMesh::ScreenMesh(Mesh *mesh) : ScreenEntity(), texture(NULL), material(NULL) {
|
|
|
this->mesh = mesh;
|
|
this->mesh = mesh;
|
|
|
lineSmooth = false;
|
|
lineSmooth = false;
|
|
|
lineWidth = 1.0;
|
|
lineWidth = 1.0;
|
|
@@ -36,14 +37,14 @@ ScreenMesh::ScreenMesh(Mesh *mesh) : ScreenEntity(), texture(NULL) {
|
|
|
updateHitBox();
|
|
updateHitBox();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-ScreenMesh::ScreenMesh(const String& fileName) : ScreenEntity(), texture(NULL) {
|
|
|
|
|
|
|
+ScreenMesh::ScreenMesh(const String& fileName) : ScreenEntity(), texture(NULL), material(NULL) {
|
|
|
mesh = new Mesh(fileName);
|
|
mesh = new Mesh(fileName);
|
|
|
lineSmooth = false;
|
|
lineSmooth = false;
|
|
|
lineWidth = 1.0;
|
|
lineWidth = 1.0;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-ScreenMesh::ScreenMesh(int meshType) : ScreenEntity(), texture(NULL) {
|
|
|
|
|
|
|
+ScreenMesh::ScreenMesh(int meshType) : ScreenEntity(), texture(NULL), material(NULL){
|
|
|
mesh = new Mesh(meshType);
|
|
mesh = new Mesh(meshType);
|
|
|
lineSmooth = false;
|
|
lineSmooth = false;
|
|
|
lineWidth = 1.0;
|
|
lineWidth = 1.0;
|
|
@@ -77,11 +78,53 @@ void ScreenMesh::setTexture(Texture *texture) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void ScreenMesh::loadTexture(const String& fileName) {
|
|
void ScreenMesh::loadTexture(const String& fileName) {
|
|
|
- texture = CoreServices::getInstance()->getMaterialManager()->createTextureFromFile(fileName, false, true);
|
|
|
|
|
|
|
+ texture = CoreServices::getInstance()->getMaterialManager()->createTextureFromFile(fileName, false, false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void ScreenMesh::loadTexture(Image *image) {
|
|
void ScreenMesh::loadTexture(Image *image) {
|
|
|
- texture = CoreServices::getInstance()->getMaterialManager()->createTextureFromImage(image, false, true);
|
|
|
|
|
|
|
+ texture = CoreServices::getInstance()->getMaterialManager()->createTextureFromImage(image, false, false);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void ScreenMesh::clearMaterial() {
|
|
|
|
|
+ if(localShaderOptions)
|
|
|
|
|
+ delete localShaderOptions;
|
|
|
|
|
+ localShaderOptions = NULL;
|
|
|
|
|
+ this->material = NULL;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void ScreenMesh::setMaterial(Material *material) {
|
|
|
|
|
+
|
|
|
|
|
+ if(this->material)
|
|
|
|
|
+ clearMaterial();
|
|
|
|
|
+
|
|
|
|
|
+ if(!material)
|
|
|
|
|
+ return;
|
|
|
|
|
+
|
|
|
|
|
+ if(material->getNumShaders() == 0)
|
|
|
|
|
+ return;
|
|
|
|
|
+
|
|
|
|
|
+ this->material = material;
|
|
|
|
|
+ localShaderOptions = material->getShader(0)->createBinding();
|
|
|
|
|
+ if(texture) {
|
|
|
|
|
+ localShaderOptions->clearTexture("diffuse");
|
|
|
|
|
+ localShaderOptions->addTexture("diffuse", texture);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+Material *ScreenMesh::getMaterial() {
|
|
|
|
|
+ return material;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+ShaderBinding *ScreenMesh::getLocalShaderOptions() {
|
|
|
|
|
+ return localShaderOptions;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void ScreenMesh::setMaterialByName(const String& materialName) {
|
|
|
|
|
+ Material *material = (Material*)CoreServices::getInstance()->getResourceManager()->getResource(Resource::RESOURCE_MATERIAL, materialName);
|
|
|
|
|
+ if(!material)
|
|
|
|
|
+ return;
|
|
|
|
|
+ setMaterial(material);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void ScreenMesh::Render() {
|
|
void ScreenMesh::Render() {
|
|
@@ -90,7 +133,12 @@ void ScreenMesh::Render() {
|
|
|
renderer->setLineSize(lineWidth);
|
|
renderer->setLineSize(lineWidth);
|
|
|
renderer->setLineSmooth(lineSmooth);
|
|
renderer->setLineSmooth(lineSmooth);
|
|
|
|
|
|
|
|
- renderer->setTexture(texture);
|
|
|
|
|
|
|
+ if(material) {
|
|
|
|
|
+ renderer->applyMaterial(material, localShaderOptions,0);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ renderer->setTexture(texture);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if(mesh->useVertexColors) {
|
|
if(mesh->useVertexColors) {
|
|
|
renderer->pushDataArrayForMesh(mesh, RenderDataArray::COLOR_DATA_ARRAY);
|
|
renderer->pushDataArrayForMesh(mesh, RenderDataArray::COLOR_DATA_ARRAY);
|
|
|
}
|
|
}
|