Exemple #1
0
void EMIModel::prepare() {
	_mats = new Material*[_numTextures];
	for (uint32 i = 0; i < _numTextures; i++) {
		_mats[i] = g_resourceloader->loadMaterial(_texNames[i].c_str(), NULL);
	}
	prepareForRender();
}
Exemple #2
0
void EMIModel::draw() {
	prepareForRender();
	// We will need to add a call to the skeleton, to get the modified vertices, but for now,
	// I'll be happy with just static drawing
	for (uint32 i = 0; i < _numFaces; i++) {
		setTex(_faces[i]._texID);
		g_driver->drawEMIModelFace(this, &_faces[i]);
	}
}
Exemple #3
0
void EMIModel::prepare() {
	_mats = new Material*[_numTextures];
	for (uint32 i = 0; i < _numTextures; i++) {
		// HACK: As we dont know what specialty-textures are yet, we skip loading them
		if (!_texNames[i].contains("specialty"))
			_mats[i] = g_resourceloader->loadMaterial(_texNames[i].c_str(), NULL);
	}
	prepareForRender();
}
void RoughPlasticBsdf::fromJson(const rapidjson::Value &v, const Scene &scene)
{
    Bsdf::fromJson(v, scene);
    JsonUtils::fromJson(v, "ior", _ior);
    JsonUtils::fromJson(v, "distribution", _distributionName);
    JsonUtils::fromJson(v, "thickness", _thickness);
    JsonUtils::fromJson(v, "sigma_a", _sigmaA);
    scene.textureFromJsonMember(v, "roughness", TexelConversion::REQUEST_AVERAGE, _roughness);

    // Fail early in case of invalid distribution name
    prepareForRender();
}
void RoughConductorBsdf::fromJson(const rapidjson::Value &v, const Scene &scene)
{
    Bsdf::fromJson(v, scene);
    if (JsonUtils::fromJson(v, "eta", _eta) && JsonUtils::fromJson(v, "k", _k))
        _materialName.clear();
    JsonUtils::fromJson(v, "distribution", _distributionName);
    if (JsonUtils::fromJson(v, "material", _materialName))
        lookupMaterial();

    scene.textureFromJsonMember(v, "roughness", TexelConversion::REQUEST_AVERAGE, _roughness);

    // Fail early in case of invalid distribution name
    prepareForRender();
}
//----------------------------------------------------------------------------//
ModelIndex TreeView::indexAtWithAction(const glm::vec2& position,
    TreeViewItemAction action)
{
    if (d_itemModel == 0)
        return ModelIndex();

    //TODO: add prepareForLayout() as a cheaper operation alternative?
    prepareForRender();

    glm::vec2 window_position = CoordConverter::screenToWindow(*this, position);
    Rectf render_area(getViewRenderer()->getViewRenderArea());
    if (!render_area.isPointInRect(window_position))
        return ModelIndex();

    float cur_height = render_area.d_min.d_y - getVertScrollbar()->getScrollPosition();
    bool handled = false;
    return indexAtRecursive(d_rootItemState, cur_height, window_position,
        handled, action);
}
Exemple #7
0
void EMIModel::loadMesh(Common::SeekableReadStream *data) {
	//int strLength = 0; // Usefull for PS2-strings

	Common::String nameString = readLAString(data);

	_sphereData->readFromStream(data);

	_boxData->readFromStream(data);
	_boxData2->readFromStream(data);

	_numTexSets = data->readUint32LE();
	_setType = data->readUint32LE();
	_numTextures = data->readUint32LE();

	_texNames = new Common::String[_numTextures];

	for (uint32 i = 0; i < _numTextures; i++) {
		_texNames[i] = readLAString(data);
		// Every texname seems to be followed by 4 0-bytes (Ref mk1.mesh,
		// this is intentional)
		data->skip(4);
	}

	prepareTextures();

	int type = data->readUint32LE();
	// Check that it is one of the known types
	//3  is no texture vertecies
	//18 is no normals
	//19 is regular
	assert(type == 19 || type == 18 || type == 3);

	_numVertices = data->readUint32LE();

	// Vertices
	_vertices = new Math::Vector3d[_numVertices];
	_drawVertices = new Math::Vector3d[_numVertices];
	for (int i = 0; i < _numVertices; i++) {
		_vertices[i].readFromStream(data);
		_drawVertices[i] = _vertices[i];
	}
	_normals = new Math::Vector3d[_numVertices];
	if (type != 18) {
		for (int i = 0; i < _numVertices; i++) {
			_normals[i].readFromStream(data);
		}
	}
	_colorMap = new EMIColormap[_numVertices];
	for (int i = 0; i < _numVertices; ++i) {
		_colorMap[i].r = data->readByte();
		_colorMap[i].g = data->readByte();
		_colorMap[i].b = data->readByte();
		_colorMap[i].a = data->readByte();
	}
	if (type != 3) {
		_texVerts = new Math::Vector2d[_numVertices];
		for (int i = 0; i < _numVertices; i++) {
			_texVerts[i].readFromStream(data);
		}
	}
	// Faces

	_numFaces = data->readUint32LE();
	if (data->eos()) {
		_numFaces = 0;
		_faces = NULL;
		return;
	}

	_faces = new EMIMeshFace[_numFaces];

	for (uint32 j = 0; j < _numFaces; j++) {
		_faces[j].setParent(this);
		_faces[j].loadFace(data);
	}

	int hasBones = data->readUint32LE();

	if (hasBones == 1) {
		_numBones = data->readUint32LE();
		_boneNames = new Common::String[_numBones];
		for (int i = 0; i < _numBones; i++) {
			_boneNames[i] = readLAString(data);
		}

		_numBoneInfos =  data->readUint32LE();
		_boneInfos = new BoneInfo[_numBoneInfos];

		for (int i = 0; i < _numBoneInfos; i++) {
			_boneInfos[i]._incFac = data->readUint32LE();
			_boneInfos[i]._joint = data->readUint32LE();
			_boneInfos[i]._weight = data->readUint32LE();
		}
	} else {
		_numBones = 0;
		_numBoneInfos = 0;
	}
	prepareForRender();
}
void GLES2RendererVertexBuffer::bind(PxU32 streamID, PxU32 firstVertex)
{
	prepareForRender();
	GLES2RendererMaterial *mat = g_hackCurrentMat;
	PxU8 *buffer = ((PxU8*)0) + firstVertex*m_stride;
	if(m_vbo)
	{
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vbo);
		for(PxU32 i=0; i<NUM_SEMANTICS; i++)
		{
			Semantic semantic = (Semantic)i;
			const SemanticDesc &sm = m_semanticDescs[semantic];
			if(sm.format < NUM_FORMATS)
			{
				switch(semantic)
				{
					case SEMANTIC_POSITION:
						RENDERER_ASSERT(sm.format >= FORMAT_FLOAT1 && sm.format <= FORMAT_FLOAT4, "Unsupported Vertex Buffer Format for POSITION semantic.");
						if(sm.format >= FORMAT_FLOAT1 && sm.format <= FORMAT_FLOAT4)
						{
                            bindGL(mat->m_program[mat->m_currentPass].positionAttr, sm, buffer);
						}
						break;
					case SEMANTIC_COLOR:
						RENDERER_ASSERT(sm.format == FORMAT_COLOR_BGRA || sm.format == FORMAT_COLOR_RGBA || sm.format == FORMAT_COLOR_NATIVE || sm.format == FORMAT_FLOAT4, "Unsupported Vertex Buffer Format for COLOR semantic.");
						if(sm.format == FORMAT_COLOR_BGRA || sm.format == FORMAT_COLOR_RGBA || sm.format == FORMAT_COLOR_NATIVE || sm.format == FORMAT_FLOAT4)
						{
                            bindGL(mat->m_program[mat->m_currentPass].colorAttr, sm, buffer);
						}
						break;
					case SEMANTIC_NORMAL:
						RENDERER_ASSERT(sm.format == FORMAT_FLOAT3 || sm.format == FORMAT_FLOAT4, "Unsupported Vertex Buffer Format for NORMAL semantic.");
						if(sm.format == FORMAT_FLOAT3 || sm.format == FORMAT_FLOAT4)
						{
                            bindGL(mat->m_program[mat->m_currentPass].normalAttr, sm, buffer);
						}
						break;
					case SEMANTIC_TANGENT:
						RENDERER_ASSERT(sm.format == FORMAT_FLOAT3 || sm.format == FORMAT_FLOAT4, "Unsupported Vertex Buffer Format for TANGENT semantic.");
						if(sm.format == FORMAT_FLOAT3 || sm.format == FORMAT_FLOAT4)
						{
                            bindGL(mat->m_program[mat->m_currentPass].tangentAttr, sm, buffer);
						}
						break;
					case SEMANTIC_TEXCOORD0:
					case SEMANTIC_TEXCOORD1:
					case SEMANTIC_TEXCOORD2:
					case SEMANTIC_TEXCOORD3:
					{
						const PxU32 channel = semantic - SEMANTIC_TEXCOORD0;
						glActiveTextureARB((GLenum)(GL_TEXTURE0_ARB + channel));
						glClientActiveTextureARB((GLenum)(GL_TEXTURE0_ARB + channel));

                        bindGL(mat->m_program[mat->m_currentPass].texcoordAttr[channel], sm, buffer);

						break;
					}
					case SEMANTIC_BONEINDEX:
					{
						glActiveTextureARB((GLenum)(GL_TEXTURE0_ARB + RENDERER_BONEINDEX_CHANNEL));
						glClientActiveTextureARB((GLenum)(GL_TEXTURE0_ARB + RENDERER_BONEINDEX_CHANNEL));
                        bindGL(mat->m_program[mat->m_currentPass].boneIndexAttr, sm, buffer);
                        break;
					}
					case SEMANTIC_BONEWEIGHT:
					{
						glActiveTextureARB((GLenum)(GL_TEXTURE0_ARB + RENDERER_BONEWEIGHT_CHANNEL));
						glClientActiveTextureARB((GLenum)(GL_TEXTURE0_ARB + RENDERER_BONEWEIGHT_CHANNEL));
                        bindGL(mat->m_program[mat->m_currentPass].boneWeightAttr, sm, buffer);
						break;
					}
					default:
						/*
                        __android_log_print(ANDROID_LOG_DEBUG, "GLES2RendererVertexBuffer", "semantic: %d", i);
						RENDERER_ASSERT(0, "Unable to bind Vertex Buffer Semantic.");
						*/
						break;
				}
			}
		}
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
	}
}
void Ogre2dManager::renderBuffer()
{
   Ogre::RenderSystem* rs=Ogre::Root::getSingleton().getRenderSystem();
   std::list<Ogre2dSprite>::iterator currSpr, endSpr;
 
   VertexChunk thisChunk;
   std::list<VertexChunk> chunks;
 
   unsigned int newSize;
 
   newSize=sprites.size()*6;
   if (newSize<OGRE2D_MINIMAL_HARDWARE_BUFFER_SIZE)
      newSize=OGRE2D_MINIMAL_HARDWARE_BUFFER_SIZE;
 
   // grow hardware buffer if needed
   if (hardwareBuffer.isNull() || hardwareBuffer->getNumVertices()<newSize)
   {
      if (!hardwareBuffer.isNull())
         destroyHardwareBuffer();
 
      createHardwareBuffer(newSize);
   }
 
   if (sprites.empty()) return;
 
   // write quads to the hardware buffer, and remember chunks
   float* buffer;
   float z=-1;
 
   buffer=(float*)hardwareBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
 
   endSpr=sprites.end();
   currSpr=sprites.begin();
   thisChunk.texHandle=currSpr->texHandle;
   thisChunk.vertexCount=0;
   while (currSpr!=endSpr)
   {
      // 1st point (left bottom)
      *buffer=currSpr->x1; buffer++;
      *buffer=currSpr->y2; buffer++;
      *buffer=z; buffer++;
      *buffer=currSpr->tx1; buffer++;
      *buffer=currSpr->ty2; buffer++;
      // 2st point (right top)
      *buffer=currSpr->x2; buffer++;
      *buffer=currSpr->y1; buffer++;
      *buffer=z; buffer++;
      *buffer=currSpr->tx2; buffer++;
      *buffer=currSpr->ty1; buffer++;
      // 3rd point (left top)
      *buffer=currSpr->x1; buffer++;
      *buffer=currSpr->y1; buffer++;
      *buffer=z; buffer++;
      *buffer=currSpr->tx1; buffer++;
      *buffer=currSpr->ty1; buffer++;
 
      // 4th point (left bottom)
      *buffer=currSpr->x1; buffer++;
      *buffer=currSpr->y2; buffer++;
      *buffer=z; buffer++;
      *buffer=currSpr->tx1; buffer++;
      *buffer=currSpr->ty2; buffer++;
      // 5th point (right bottom)
      *buffer=currSpr->x2; buffer++;
      *buffer=currSpr->y1; buffer++;
      *buffer=z; buffer++;
      *buffer=currSpr->tx2; buffer++;
      *buffer=currSpr->ty1; buffer++;
      // 6th point (right top)
      *buffer=currSpr->x2; buffer++;
      *buffer=currSpr->y2; buffer++;
      *buffer=z; buffer++;
      *buffer=currSpr->tx2; buffer++;
      *buffer=currSpr->ty2; buffer++;
 
      // remember this chunk
      thisChunk.vertexCount+=6;
      currSpr++;
      if (currSpr==endSpr || thisChunk.texHandle!=currSpr->texHandle)
      {
         chunks.push_back(thisChunk);
         if (currSpr!=endSpr)
         {
            thisChunk.texHandle=currSpr->texHandle;
            thisChunk.vertexCount=0;
         }
      }
   }
 
   hardwareBuffer->unlock();
 
   // set up...
   prepareForRender();
 
   // do the real render!
   Ogre::TexturePtr tp;
   std::list<VertexChunk>::iterator currChunk, endChunk;
 
   endChunk=chunks.end();
   renderOp.vertexData->vertexStart=0;
   for (currChunk=chunks.begin(); currChunk!=endChunk; currChunk++)
   {
      renderOp.vertexData->vertexCount=currChunk->vertexCount;
      tp=Ogre::TextureManager::getSingleton().getByHandle(currChunk->texHandle);
      rs->_setTexture(0, true, tp->getName());
      rs->_render(renderOp);
      renderOp.vertexData->vertexStart+=currChunk->vertexCount;
   }
 
   // sprites go home!
   sprites.clear();
}