Пример #1
0
void MFixedRenderer::drawDisplayTriangles(MSubMesh * subMesh, MDisplay * display, MVector3 * vertices)
{
    M_PROFILE_SCOPE(MFixedRenderer::drawDisplayTriangles);
	MRenderingContext * render = MEngine::getInstance()->getRenderingContext();
	
	// begin / size
	unsigned int begin = display->getBegin();
	unsigned int size = display->getSize();
	
	// display properties
	M_PRIMITIVE_TYPES primitiveType = display->getPrimitiveType();
	M_CULL_MODES cullMode = display->getCullMode();
	
	// cull mode
	if(cullMode == M_CULL_NONE){
		render->disableCullFace();
	}
	else{
		render->enableCullFace();
		render->setCullMode(cullMode);
	}
	
	// indices
	M_TYPES indicesType = subMesh->getIndicesType();
	void * indices = subMesh->getIndices();
	
	// FX
	render->bindFX(0);
	
	// Vertex
	render->enableVertexArray();
	render->setVertexPointer(M_FLOAT, 3, vertices);
	
	// draw
	if(indices)
	{
		switch(indicesType)
		{
			case M_USHORT:
				render->drawElement(primitiveType, size, indicesType, (unsigned short*)indices + begin);
				break;
			case M_UINT:
				render->drawElement(primitiveType, size, indicesType, (unsigned int*)indices + begin);
				break;
		}
	}
	else
		render->drawArray(primitiveType, begin, size);
	
	// disable vertex array
	render->disableVertexArray();
	
	// restore FX
	render->bindFX(0);
}
Пример #2
0
    void Flush()
    {
	g_CurrentColour.set(255, 255, 255, 255);
	if(g_Cnt == 0) return;

	MEngine* engine = MEngine::getInstance();
	MRenderingContext* render = engine->getRenderingContext();
	MSystemContext* system = engine->getSystemContext();
	
	unsigned int w, h;
	system->getScreenSize(&w, &h);
	
	// set up the "camera"
	render->setViewport(0, 0, w, h);
	render->setMatrixMode(M_MATRIX_PROJECTION);
	render->loadIdentity();
	render->setOrthoView(0, w, h, 0, 1.0f, -1.0f);
	render->setMatrixMode(M_MATRIX_MODELVIEW);
	render->loadIdentity();

	// set up arrays
	render->enableVertexArray();
	render->enableTexCoordArray();
	render->enableColorArray();

	render->setVertexPointer(M_FLOAT, 3, g_Vertices);
	render->setTexCoordPointer(M_FLOAT, 2, g_UVs);
	render->setColorPointer(M_UBYTE, 4, g_Colours);

	render->disableCullFace();
	render->disableDepthTest();

	render->drawArray(M_PRIMITIVE_TRIANGLES, 0, g_Cnt * 6);

	g_Cnt = 0;

	g_Selected = NULL;
    }
Пример #3
0
void MFixedRenderer::drawDisplay(MSubMesh * subMesh, MDisplay * display, MVector3 * vertices, MVector3 * normals, MColor * colors)
{
    M_PROFILE_SCOPE(MFixedRenderer::drawDisplay);
	MEngine * engine = MEngine::getInstance();
	MRenderingContext * render = engine->getRenderingContext();
	
	
	render->setColor4(MVector4(1, 1, 1, 1));
	

	// get material
	MMaterial * material = display->getMaterial();
	{
		float opacity = material->getOpacity();
		if(opacity <= 0.0f)
			return;
		
		// data
		M_TYPES indicesType = subMesh->getIndicesType();
		void * indices = subMesh->getIndices();
		MVector2 * texCoords = subMesh->getTexCoords();

		// begin / size
		unsigned int begin = display->getBegin();
		unsigned int size = display->getSize();
		
		// get properties
		M_PRIMITIVE_TYPES primitiveType = display->getPrimitiveType();
		M_BLENDING_MODES blendMode = material->getBlendMode();
		M_CULL_MODES cullMode = display->getCullMode();
		MVector3 * diffuse = material->getDiffuse();
		MVector3 * specular = material->getSpecular();
		MVector3 * emit = material->getEmit();
		float shininess = material->getShininess();
		
		// get current fog color
		MVector3 currentFogColor;
		render->getFogColor(&currentFogColor);
		
		// set cull mode
		if(cullMode == M_CULL_NONE){
			render->disableCullFace();
		}
		else{
			render->enableCullFace();
			render->setCullMode(cullMode);
		}
		
		// texture passes
		unsigned int texturesPassNumber = MIN(8, material->getTexturesPassNumber());
		
		// set blending mode
		render->setBlendingMode(blendMode);
		
		// alpha test
		if(blendMode != M_BLENDING_ALPHA && texturesPassNumber > 0)
		{
			MTexturePass * texturePass = material->getTexturePass(0);
			MTexture * texture = texturePass->getTexture();
			if(texture)
			{
				if(texture->getTextureRef()->getComponents() > 3)
					render->setAlphaTest(0.5f);
			}
		}
		
		// set fog color depending on blending
		switch(blendMode)
		{
			case M_BLENDING_ADD:
			case M_BLENDING_LIGHT:
				render->setFogColor(MVector3(0, 0, 0));
				break;
			case M_BLENDING_PRODUCT:
				render->setFogColor(MVector3(1, 1, 1));
				break;
		}
		
		// fixed pipeline
		{
			// no FX
			render->bindFX(0);
			
			// Vertex
			render->enableVertexArray();
			render->setVertexPointer(M_FLOAT, 3, vertices);
			
			// Normal
			if(normals)
			{
				render->enableNormalArray();
				render->setNormalPointer(M_FLOAT, normals);
			}
			
			// Color
			if(colors)
			{
				render->disableLighting();
				render->enableColorArray();
				render->setColorPointer(M_UBYTE, 4, colors);
			}
			
			// Material
			render->setMaterialDiffuse(MVector4(diffuse->x, diffuse->y, diffuse->z, opacity));
			render->setMaterialSpecular(MVector4(*specular));
			render->setMaterialAmbient(MVector4());
			render->setMaterialEmit(MVector4(*emit));
			render->setMaterialShininess(shininess);
			
			// switch to texture matrix mode
			if(texturesPassNumber > 0)
				render->setMatrixMode(M_MATRIX_TEXTURE);
			else
				render->disableTexture();
			
			// Textures
			int id = texturesPassNumber;
			for(unsigned int t=0; t<texturesPassNumber; t++)
			{
				MTexturePass * texturePass = material->getTexturePass(t);
				
				MTexture * texture = texturePass->getTexture();
				if((! texture) || (! texCoords))
				{
					render->bindTexture(0, t);
					render->disableTexture();
					render->disableTexCoordArray();
					continue;
				}
				
				// texCoords
				unsigned int offset = 0;
				if(subMesh->isMapChannelExist(texturePass->getMapChannel()))
					offset = subMesh->getMapChannelOffset(texturePass->getMapChannel());
				
				// texture id
				unsigned int textureId = 0;
				MTextureRef * texRef = texture->getTextureRef();
				if(texRef)
					textureId = texRef->getTextureId();
				
				// bind texture
				render->bindTexture(textureId, t);
				render->enableTexture();
				render->setTextureCombineMode(texturePass->getCombineMode());
				render->setTextureUWrapMode(texture->getUWrapMode());
				render->setTextureVWrapMode(texture->getVWrapMode());
				
				// texture matrix
				render->loadIdentity();
				render->translate(MVector2(0.5f, 0.5f));
				render->scale(*texture->getTexScale());
				render->rotate(MVector3(0, 0, -1), texture->getTexRotate());
				render->translate(MVector2(-0.5f, -0.5f));
				render->translate(*texture->getTexTranslate());
				
				// texture coords
				render->enableTexCoordArray();
				render->setTexCoordPointer(M_FLOAT, 2, texCoords + offset);
			}
			
			// switch back to modelview matrix mode
			if(texturesPassNumber > 0)
				render->setMatrixMode(M_MATRIX_MODELVIEW);
			
			// draw
			if(indices)
			{
				switch(indicesType)
				{
					case M_USHORT:
						render->drawElement(primitiveType, size, indicesType, (unsigned short*)indices + begin);
						break;
					case M_UINT:
						render->drawElement(primitiveType, size, indicesType, (unsigned int*)indices + begin);
						break;
				}
			}
			else{
				render->drawArray(primitiveType, begin, size);
			}
			
			
			// disable arrays
			render->disableVertexArray();
			if(normals)
				render->disableNormalArray();
			if(colors)
				render->disableColorArray();
			
			// restore textures
			for(int t=(int)(id-1); t>=0; t--)
			{
				render->bindTexture(0, t);
				render->disableTexture();
				render->disableTexCoordArray();
				render->setTextureCombineMode(M_TEX_COMBINE_MODULATE);
				
				render->setMatrixMode(M_MATRIX_TEXTURE);
				render->loadIdentity();
				render->setMatrixMode(M_MATRIX_MODELVIEW);
			}
		}

		// restore fog and alpha test
		render->setFogColor(currentFogColor);
		if(blendMode != M_BLENDING_ALPHA)
			render->setAlphaTest(0.0f);
		
		// restore lighting
		if(colors)
			render->enableLighting();
	}
}
Пример #4
0
void MFixedRenderer::drawText(MOText * textObj)
{
	MFont * font = textObj->getFont();
	const char * text = textObj->getText();
	vector <float> * linesOffset = textObj->getLinesOffset();

	if(! (strlen(text) > 0 && font))
		return;

	if(linesOffset->size() == 0)
		return;

	MRenderingContext * render = MEngine().getInstance()->getRenderingContext();


	render->enableBlending();
	render->enableTexture();
	render->disableLighting();
	render->disableCullFace();
	render->setDepthMask(0);

	render->setColor4(textObj->getColor());
	render->setBlendingMode(M_BLENDING_ALPHA);

	static MVector2 vertices[4];
	static MVector2 texCoords[4];

	render->disableNormalArray();
	render->disableColorArray();
	render->enableVertexArray();
	render->enableTexCoordArray();

	render->setVertexPointer(M_FLOAT, 2, vertices);
	render->setTexCoordPointer(M_FLOAT, 2, texCoords);

	render->bindTexture(font->getTextureId());

	unsigned int lineId = 0;
	float lineOffset = (*linesOffset)[0];

	float size = textObj->getSize();
	float tabSize = size*2;
	float fontSize = (float)font->getFontSize();
	float widthFactor = font->getTextureWith() / fontSize;
	float heightFactor = font->getTextureHeight() / fontSize;
	float xc = 0, yc = 0;

	unsigned int i;
	unsigned int textLen = strlen(text);
	for(i=0; i<textLen; i++)
	{
		if(text[i] == '\n') // return
		{
			if(((i+1) < textLen))
			{
				lineId++;
				lineOffset = (*linesOffset)[lineId];

				yc += size;
				xc = 0;
			}
			continue;
		}

		if(text[i] == '\t') // tab
		{
			int tab = (int)(xc / tabSize) + 1;
			xc = tab*tabSize;
			continue;
		}

		// get character
		unsigned int charCode = (unsigned int)((unsigned char)text[i]);
		MCharacter * character = font->getCharacter(charCode);
		if(! character)
			continue;

		MVector2 pos = character->getPos();
		MVector2 scale = character->getScale();
		MVector2 offset = character->getOffset() * size + MVector2(lineOffset, 0);

		float width = scale.x * widthFactor * size;
		float height = scale.y * heightFactor * size;

		// construct quad
		texCoords[0] = MVector2(pos.x, (pos.y + scale.y));
		vertices[0] = MVector2(xc, (yc + height)) + offset;

		texCoords[1] = MVector2((pos.x + scale.x), (pos.y + scale.y));
		vertices[1] = MVector2((xc + width), (yc + height)) + offset;

		texCoords[3] = MVector2((pos.x + scale.x), pos.y);
		vertices[3] = MVector2((xc + width), yc) + offset;

		texCoords[2] = MVector2(pos.x, pos.y);
		vertices[2] = MVector2(xc, yc) + offset;

		// draw quad
		render->drawArray(M_PRIMITIVE_TRIANGLE_STRIP, 0, 4);

		//move to next character
		xc += character->getXAdvance() * size;
	}
	
	render->setDepthMask(1);
}
Пример #5
0
void MGuiWindow::draw(void)
{
	MRenderingContext * render = MGui::getInstance()->getRenderingContext();

	if(! isVisible())
		return;
	
	MWindow * window = MWindow::getInstance();

	rescaleScrollingBar();
	render->enableScissorTest();
	render->setScissor((int)getPosition().x, window->getHeight() - (int)getPosition().y - (unsigned int)getScale().y, (unsigned int)getScale().x, (unsigned int)getScale().y);

	// normal clear
	if((getNormalColor().w >= 1.0f) && (! hasNormalTexture()))
	{
		render->setClearColor(getNormalColor());
		render->clear(M_BUFFER_COLOR);

		MGuiEvent guiEvent;
		guiEvent.type = MGUI_EVENT_DRAW;

		if(m_pointerEvent)
			m_pointerEvent(this, &guiEvent);

		// 2d mode
		set2dMode(render);
		render->disableDepthTest();
		render->disableCullFace();
		render->disableLighting();
		render->enableBlending();
		render->setBlendingMode(M_BLENDING_ALPHA);
		render->enableTexture();
	}
	else
	{
		// background
		set2dMode(render);
		render->disableDepthTest();
		render->disableCullFace();
		render->disableLighting();
		render->enableBlending();
		render->setBlendingMode(M_BLENDING_ALPHA);

		if(hasNormalTexture()) // texture clear
		{
			render->enableTexture();
			render->setColor4(getNormalColor());
			drawTexturedQuad(getNormalTexture());
		}
		else if(getNormalColor().w < 1.0f)
		{
			render->disableTexture();
			render->setColor4(getNormalColor());
			drawQuad();
		}

		if(m_pointerEvent)
		{
			MGuiEvent guiEvent;
			guiEvent.type = MGUI_EVENT_DRAW;
			m_pointerEvent(this, &guiEvent);

			// 2d mode
			set2dMode(render);
			render->disableDepthTest();
			render->disableCullFace();
			render->disableLighting();
			render->enableBlending();
			render->setBlendingMode(M_BLENDING_ALPHA);
			render->enableTexture();
		}
	}

	// gui
	render->pushMatrix();
	render->translate(MVector3(getPosition().x, getPosition().y, 0));

	render->pushMatrix();
	render->translate(MVector3(getScroll().x, getScroll().y, 0));

	// drawing
	unsigned int i;
	unsigned int oSize = m_objects.size();
	for(i=0; i<oSize; i++)
		m_objects[i]->draw();

	render->popMatrix();

	// draw shadows
	if(hasShadow())
	{
		render->disableScissorTest();
		drawShadow();
		render->enableScissorTest();
	}

	// scolling slides
	if(isHorizontalScroll())
		m_hScrollSlide.draw();

	if(isVerticalScroll())
		m_vScrollSlide.draw();

	render->popMatrix();
}