Просмотр исходного кода

Changed vertex color to use a stack in the Renderer instead of multiplying up hierarchy tree, fixed rendering in the IDE asset browser

Ivan Safrin 12 лет назад
Родитель
Сommit
99513fa3a4

+ 1 - 1
Core/Contents/Include/PolyEntity.h

@@ -612,7 +612,7 @@ namespace Polycode {
 			bool depthTest;
 			
 			/**
-			* Entity blending mode. Possible values are Renderer::BLEND_MODE_NORMAL, Renderer::BLEND_MODE_LIGHTEN, Renderer::BLEND_MODE_COLOR, Renderer::BLEND_MODE_PREMULTIPLIED, Renderer::BLEND_MODE_MULTIPLY. See the Renderer class for details on individual blending modes.
+			* Entity blending mode. Possible values are Renderer::BLEND_MODE_NONE, Renderer::BLEND_MODE_NORMAL, Renderer::BLEND_MODE_LIGHTEN, Renderer::BLEND_MODE_COLOR, Renderer::BLEND_MODE_PREMULTIPLIED, Renderer::BLEND_MODE_MULTIPLY. See the Renderer class for details on individual blending modes.
 			*/
 			int blendingMode;	
 			

+ 8 - 0
Core/Contents/Include/PolyRenderer.h

@@ -28,6 +28,7 @@ THE SOFTWARE.
 #include "PolyShader.h"
 #include "PolyImage.h"
 #include "PolyRectangle.h"
+#include <stack>
 
 namespace Polycode {
 	
@@ -309,12 +310,19 @@ namespace Polycode {
         Number getBackingResolutionScaleX();
         Number getBackingResolutionScaleY();
         
+        void pushVertexColor();
+        void popVertexColor();
+        void multiplyVertexColor(const Color &color);
+        
 	protected:
 		virtual void initOSSpecific() {};
         
         Number backingResolutionScaleX;
         Number backingResolutionScaleY;
         
+        std::stack<Color> vertexColorStack;
+        Color currentVertexColor;
+        
 		bool scissorEnabled;
 		
 		Polycode::Rectangle scissorBox;

+ 4 - 3
Core/Contents/Source/PolyEntity.cpp

@@ -528,8 +528,8 @@ void Entity::transformAndRender() {
 		 
 	renderer->enableAlphaTest(alphaTest);
 	
-	Color combined = getCombinedColor();
-	renderer->setVertexColor(combined.r,combined.g,combined.b,combined.a);
+    renderer->pushVertexColor();
+	renderer->multiplyVertexColor(color);
 	
 	renderer->setBlendingMode(blendingMode);
 	renderer->enableBackfaceCulling(backfaceCulled);
@@ -554,7 +554,8 @@ void Entity::transformAndRender() {
 				
 	renderer->setRenderMode(mode);	
 	renderer->popMatrix();
-		
+    renderer->popVertexColor();
+	
 	if(!depthWrite)
 		renderer->enableDepthWrite(true);
 	

+ 14 - 0
Core/Contents/Source/PolyRenderer.cpp

@@ -67,6 +67,20 @@ bool Renderer::Init() {
 	return true;
 }
 
+void Renderer::pushVertexColor() {
+    vertexColorStack.push(currentVertexColor);
+}
+
+void Renderer::popVertexColor() {
+    currentVertexColor = vertexColorStack.top();
+    vertexColorStack.pop();
+}
+
+void Renderer::multiplyVertexColor(const Color &color) {
+    currentVertexColor = currentVertexColor * color;
+    setVertexColor(currentVertexColor.r, currentVertexColor.g, currentVertexColor.b, currentVertexColor.a);
+}
+
 void Renderer::enableShaders(bool flag) {
 	shadersEnabled = flag;
 }

+ 1 - 1
IDE/Contents/Include/PolycodeIDEApp.h

@@ -15,7 +15,7 @@
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR  OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
  */

+ 0 - 1
IDE/Contents/Include/TextureBrowser.h

@@ -68,7 +68,6 @@ class AssetList : public UIElement {
 		UIImageButton *reloadButton;
 	
 		String currentFolderPath;
-		UIRect *bgShape;
 	
 		AssetEntry *currentEntry;		
 		std::vector<AssetEntry*> assetEntries;

+ 11 - 13
IDE/Contents/Source/TextureBrowser.cpp

@@ -36,6 +36,7 @@ AssetEntry::AssetEntry(String assetPath, String assetName, String extension) : U
 	selectShape->processInputEvents = true;
 	selectShape->setColor(0.0, 0.0, 0.0, 0.5);
     selectShape->loadTexture("browserIcons/large_selector.png");
+    selectShape->setBlendingMode(Renderer::BLEND_MODE_NORMAL);
 
 	imageShape = new UIRect(64,64);
 	imageShape->setAnchorPoint(-1.0, -1.0, 0.0);
@@ -59,12 +60,16 @@ AssetEntry::AssetEntry(String assetPath, String assetName, String extension) : U
 
 	
 	imageShape->setPosition(28, 10);
-	
-	nameLabel = new UILabel(assetName, 12);
+    imageShape->setBlendingMode(Renderer::BLEND_MODE_NORMAL);
+    
+    String name = assetName;
+    if(name.length() > 15) {
+        name = name.substr(0, 15)+"...";
+    }
+	nameLabel = new UILabel(name, 11);
 	addChild(nameLabel);
-	nameLabel->color.a = 1.0;
-	nameLabel->setAnchorPoint(0.0, 0.0, 0.0);
-	nameLabel->setPosition(32-7, 80);
+    nameLabel->setPosition((120.0-nameLabel->getWidth())/2.0, 80);
+    
 }
 
 AssetEntry::~AssetEntry() {
@@ -74,12 +79,7 @@ AssetEntry::~AssetEntry() {
 }
 
 AssetList::AssetList() : UIElement() {
-	
-	bgShape = new UIRect(100,100);
-	bgShape->setAnchorPoint(-1.0, -1.0, 0.0);
-	bgShape->setColor(0.0, 0.0, 0.0, 0.4);
-	addChild(bgShape);
-	
+	    
 	reloadButton = new UIImageButton("browserIcons/reload_icon.png", 1.0, 20, 20);
 	reloadButton->addEventListener(this, UIEvent::CLICK_EVENT);
 	addChild(reloadButton);	
@@ -151,8 +151,6 @@ void AssetList::showFolder(String folderPath) {
 	}
 
 	
-	bgShape->Resize(getWidth(), getHeight());
-	bgShape->rebuildTransformMatrix();
 	rebuildTransformMatrix();	
 }