/*!*************************************************************************** @Function SetTextures @Input pContext Context @Input dwScreenX Screen resolution along X @Input dwScreenY Screen resolution along Y @Input bRotate Rotate print3D by 90 degrees @Input bMakeCopy This instance of Print3D creates a copy of it's data instead of sharing with previous contexts. Set this parameter if you require thread safety. @Return PVR_SUCCESS or PVR_FAIL @Description Initialization and texture upload. Should be called only once for a given context. *****************************************************************************/ EPVRTError CPVRTPrint3D::SetTextures( const SPVRTContext * const pContext, const unsigned int dwScreenX, const unsigned int dwScreenY, const bool bRotate, const bool bMakeCopy) { // Determine which set of textures to use depending on the screen resolution. const unsigned int uiShortestEdge = PVRT_MIN(dwScreenX, dwScreenY); const void* pData = NULL; unsigned int uiDataSize = 0; if(uiShortestEdge >= 720) { pData = (void*)_arialbd_56_pvr; uiDataSize = _arialbd_56_pvr_size; } else if(uiShortestEdge >= 640) { pData = (void*)_arialbd_46_pvr; uiDataSize = _arialbd_46_pvr_size; } else { pData = (void*)_arialbd_36_pvr; uiDataSize = _arialbd_36_pvr_size; } return SetTextures(pContext, pData, dwScreenX, dwScreenY, bRotate, bMakeCopy); }
void HlModel::SetTextures( SgNode *pNode, BtU32 index, RsTexture *pTexture ) { // Cache the materials SgMaterial* pMaterials = pNode->pMaterial(); // Cache the number of materials BtU32 numMaterials = pMaterials->NumMaterials(); for( BtU32 i=0; i<numMaterials; i++) { // Cache the material RsMaterial* pMaterial = pMaterials->GetMaterial( i ); // Set the texture pMaterial->SetTexture( index, pTexture ); } // Cache the first child SgNode* pChild = pNode->pFirstChild(); // Loop through the children while( pChild != BtNull ) { // Set the materials SetTextures( pChild, index, pTexture ); // Move to the next child pChild = pChild->pNextSibling(); } }
void EC_SkyBox::OnAttributeUpdated(IAttribute* attribute) { if (!ViewEnabled()) return; std::string name = attribute->GetNameString(); if ((name == materialRef.GetNameString() && materialRef.Get().ref != lastMaterial_ ) || (name == distance.GetNameString() && distance.Get() != lastDistance_ ) || (name == drawFirst.GetNameString() && drawFirst.Get() != lastDrawFirst_ )) { DisableSky(); CreateSky(); lastMaterial_ = materialRef.Get().ref; lastDistance_ = distance.Get(); lastDrawFirst_ = drawFirst.Get(); } else if (name == textureRefs.GetNameString() ) { // What texture has changed? SetTextures(); } }
void RenderInputScene::Draw(GraphicsState & glstate, const std::vector <Drawable*> & drawlist, bool preculled) { for (std::vector <Drawable*>::const_iterator ptr = drawlist.begin(); ptr != drawlist.end(); ++ptr) { const Drawable & d = **ptr; if (preculled || !FrustumCull(d)) { SetFlags(d, glstate); SetTextures(d, glstate); SetTransform(d, glstate); if (d.GetDrawList()) { glCallList(d.GetDrawList()); } else if (d.GetVertArray()) { DrawVertexArray(*d.GetVertArray(), d.GetLineSize()); } } } }
void RenderEntities(void) { int i; entity_t* entity; matrix_t inv_modelMatrix; vec4_t modelSpaceLightPos; vec4_t modelSpaceCameraPos; matrix_t tmp; renderer.isRenderingShadow = ((renderer.props & PROP_SHADOW) == PROP_SHADOW) ; if (renderer.isRenderingShadow) { glCullFace(GL_FRONT); glBindFramebuffer(GL_FRAMEBUFFER,shadowFBOId); glClearColor(1.0,1.0,1.0,1.0); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(0.0,0.0,0.0,1.0); SRC_UseShader(&shaders[SHADOW_GENERATOR_SHADER]); glEnableVertexAttribArray(currentShader->vars[SHADER_ATT_VERTEX] ); glViewport(0, 0, renderWidth*shadowMapRation, renderHeight*shadowMapRation); //Setup perspective and camera gluPerspective(light.fov, camera.aspect,camera.zNear, camera.zFar, projectionMatrix); gluLookAt(light.position, light.lookAt, light.upVector, modelViewMatrix); entity = map; for(i=0; i < num_map_entities; i++,entity++) { matrix_multiply(modelViewMatrix,entity->matrix, tmp); matrix_multiply(projectionMatrix,tmp, modelViewProjectionMatrix); glUniformMatrix4fv(currentShader->vars[SHADER_MVT_MATRIX] ,1,GL_FALSE, modelViewProjectionMatrix); if (entity->type == ENTITY_OBJ) RenderEntitiesOBJ(entity->model); else RenderEntitiesMD5(entity->model); //Also need to cache the PVM matrix in entity matrixCopy(modelViewProjectionMatrix,entity->cachePVMShadow); } glViewport(0, 0, renderWidth, renderHeight); glCullFace(GL_BACK); renderer.isRenderingShadow = 0; glBindFramebuffer(GL_FRAMEBUFFER,renderer.mainFramebufferId); } //Setup perspective and camera SetupCamera(); entity = map; for(i=0; i < num_map_entities; i++,entity++) { //if (entity->type != ENTITY_OBJ) // continue; SRC_BindUberShader(entity->material->prop); matrix_multiply(modelViewMatrix,entity->matrix, tmp); matrix_multiply(projectionMatrix,tmp, modelViewProjectionMatrix); glUniformMatrix4fv(currentShader->vars[SHADER_MVT_MATRIX] ,1,GL_FALSE,modelViewProjectionMatrix); ComputeInvModelMatrix(entity->matrix, inv_modelMatrix); matrix_transform_vec4t(inv_modelMatrix, light.position, modelSpaceLightPos); glUniform3fv(currentShader->vars[SHADER_UNI_LIGHT_POS],1,modelSpaceLightPos); matrix_transform_vec4t(inv_modelMatrix, camera.position, modelSpaceCameraPos); glUniform3fv(currentShader->vars[SHADER_UNI_CAMERA_POS],1,modelSpaceCameraPos); if (renderer.props & PROP_SHADOW == PROP_SHADOW) glUniformMatrix4fv(currentShader->vars[SHADER_LIGHTPOV_MVT_MATRIX], 1, GL_FALSE,entity->cachePVMShadow); SetTextures(entity->material); if (entity->material->hasAlpha ) { if (!renderer.isBlending) { renderer.isBlending = 1; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); STATS_AddBlendingSwitch(); } } else { if (renderer.isBlending) { renderer.isBlending = 0; glDisable(GL_BLEND); STATS_AddBlendingSwitch(); } } glUniform1f(currentShader->vars[SHADER_UNI_MATERIAL_SHININESS], entity->material->shininess); glUniform3fv(currentShader->vars[SHADER_UNI_MAT_COL_SPECULAR],1,entity->material->specularColor); if (entity->type == ENTITY_OBJ) RenderEntitiesOBJ(entity->model); else RenderEntitiesMD5(entity->model); } }