void ExtractNormalMap(MFnDependencyNode& fn, unsigned int* tex = NULL) { MString texname; MPlug p = fn.findPlug( "normalCamera" ); MPlugArray plugs; p.connectedTo(plugs,true,true); for(int i = 0; i != plugs.length(); ++i) { if (plugs[i].node().apiType() == MFn::kBump) { MFnDependencyNode fnDepBump( plugs[i].node() ); MPlug pp = fnDepBump.findPlug( "bumpValue" ); MPlugArray pplugs; pp.connectedTo(pplugs, true, true); for(int j = 0; j != pplugs.length(); ++j) { if (pplugs[j].node().apiType() == MFn::kFileTexture) { MFnDependencyNode fnDep(pplugs[j].node()); texname = fnDep.name(); break; } } } } *tex = GetTextureID( texname ); }
void ExtractAttribute(MFnDependencyNode& fn, std::string name, SMatAttrib& attrib) { MPlug p; // extract attribute color std::string r = name + "R"; std::string g = name + "G"; std::string b = name + "B"; p = fn.findPlug(r.c_str()); p.getValue(attrib.color[0]); p = fn.findPlug(g.c_str()); p.getValue(attrib.color[1]); p = fn.findPlug(b.c_str()); p.getValue(attrib.color[2]); // extract attribute texture MString texname; p = fn.findPlug(name.c_str()); MPlugArray plugs; p.connectedTo(plugs,true,true); for(int i = 0; i != plugs.length(); ++i) { if (plugs[i].node().apiType() == MFn::kFileTexture) { MFnDependencyNode fnDep(plugs[i].node()); texname = fnDep.name(); break; } } attrib.textureID = GetTextureID( texname ); }
int JRenderServer::CreateTexture( const TextureProperties& texProp ) { int texID = GetTextureID( texProp.m_Name ); if (texID != -1) { if (m_Textures[texID].m_pTexture) { return texID; } } else { m_Textures.push_back( TextureFile() ); texID = m_Textures.size() - 1; } DWORD usage = 0; D3DFORMAT format = ConvertColorFormat( texProp.m_Format ); D3DPOOL pool = ConvertPoolType( texProp.m_PoolType ); IDirect3DTexture8* pTexture = NULL; if (texProp.m_bRenderTarget) { usage = D3DUSAGE_RENDERTARGET; } if (pool == D3DPOOL_DEFAULT) { m_pDevice->ResourceManagerDiscardBytes( 0 ); } HRESULT hRes = m_pDevice->CreateTexture( texProp.m_Width, texProp.m_Height, texProp.m_NMips, usage, format, pool, &pTexture ); if (hRes != S_OK) { rlog.err( "Could not reate texture %s (width=%d, height=%d).", texProp.m_Name, texProp.m_Width, texProp.m_Height ); return -1; } TextureFile& tex = m_Textures[texID]; tex.m_Prop = texProp; tex.m_pTexture = pTexture; tex.m_pDepthStencil = NULL; tex.m_Name = texProp.m_Name; return texID; } // JRenderServer::CreateTexture
void IOGLBaseShader::SetSampler(const CString& strName, CRefPtr<Graphic::IBaseTexture> pTexture){ CR_APICHECK(this, pTexture); auto pGLTexture = pTexture.Cast<IOGLBaseTexture>(); auto uParam = this->GetParameter(strName); this->FreeSampler(strName); cgGLSetTextureParameter(uParam, pGLTexture->GetTextureID()); if(this->m_bBinded){ cgGLEnableTextureParameter(uParam); } this->m_uSamplerParams.Add(uParam); this->m_pSamplerTextures.Add(pGLTexture); }
void LuaMatTexture::Bind() const { const GLuint texID = GetTextureID(); const GLuint texType = GetTextureTarget(); if (texID != 0) { glBindTexture(texType, texID); if (enable && (texType == GL_TEXTURE_2D)) { glEnable(GL_TEXTURE_2D); } } else if (!enable && (texType == GL_TEXTURE_2D)) { glDisable(GL_TEXTURE_2D); } if (enableTexParams && type == LUATEX_SHADOWMAP) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL); glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE); } }
void CheckStar(_lp_vertex star, int idx) { if (idx < _num_stars) { star->z++; if (star->z > nearest) { star->x = (rand() % Width) - (Width / 2); star->y = (rand() % Height) - (Height / 2); star->z = (rand() % nearest); star->tex_type = -1; //set to not have texture by default star->id = -1; int sidx = (rand() % GetTextureCount()); if (GetTextureCount() == 1) sidx = 0; star->tex_type = GetTextureType(sidx); star->id = GetTextureID(sidx); } } }
int JRenderServer::CreateRenderTarget( const char* texName, int w, int h, ColorFormat fmt ) { int texID = GetTextureID( texName ); if (texID != -1) { return texID; } DWORD usage = D3DUSAGE_RENDERTARGET; DXTexture* pTex = NULL; HRESULT hRes = m_pDevice->CreateTexture( w, h, 1, usage, ConvertColorFormat( fmt ), D3DPOOL_DEFAULT, &pTex ); if (hRes != S_OK || !pTex) { rlog.err( "Could not create render target texture %dx%d. %s", GetDXError( hRes ) ); return -1; } TextureFile tex; D3DSURFACE_DESC desc; pTex->GetLevelDesc( 0, &desc ); TextureProperties& tp = tex.m_Prop; tp.m_bAutoGenMips = false; tp.m_Format = ConvertColorFormat( desc.Format ); tp.m_Height = desc.Height; tp.m_Width = desc.Width; tp.m_bRenderTarget = true; tp.m_PoolType = ConvertPoolType( desc.Pool ); tp.m_NMips = pTex->GetLevelCount(); strcpy( tp.m_Name, texName ); tex.m_pTexture = pTex; tex.m_pDepthStencil = NULL; tex.m_Name = texName; m_Textures.push_back( tex ); return m_Textures.size() - 1; } // JRenderServer::CreateRenderTarget
void cgImage::DrawEx( float centerX, float centerY, float w, float h, cgColor color, float rotation, bool xFlip /*= false*/, bool yFlip /*= false*/ ) { static const size_t rect_vertex_num = 4; static cgRenderVertex polygon[rect_vertex_num]; polygon[0].x = -w/2; polygon[0].y = -h/2; PointToFinalTextureCoordinate(0, 0, polygon[0].u, polygon[0].v); polygon[1].x = -polygon[0].x; polygon[1].y = polygon[0].y; PointToFinalTextureCoordinate(GetWidth(), 0, polygon[1].u, polygon[1].v); polygon[2].x = polygon[1].x; polygon[2].y = -polygon[1].y; PointToFinalTextureCoordinate(GetWidth(), GetHeight(), polygon[2].u, polygon[2].v); polygon[3].x = polygon[0].x; polygon[3].y = polygon[2].y; PointToFinalTextureCoordinate(0, GetHeight(), polygon[3].u, polygon[3].v); // 旋转,如果小于1°,则不处理了 for (size_t i = 0; i < rect_vertex_num; ++i) { if (rotation > 0.006f || rotation <-0.006f ) cgXRotate(polygon[i].x, polygon[i].y, rotation); polygon[i].color = color; polygon[i].x += centerX; polygon[i].y += centerY; } // X反转 if (xFlip) { float fTemp = 0.0f; fTemp = polygon[0].u; polygon[0].u = polygon[1].u; polygon[1].u = fTemp; fTemp = polygon[2].u; polygon[2].u = polygon[3].u; polygon[3].u = fTemp; } // Y反转 if (yFlip) { float fTemp = 0.0f; fTemp = polygon[0].v; polygon[0].v = polygon[3].v; polygon[3].v = fTemp; fTemp = polygon[1].v; polygon[1].v = polygon[2].v; polygon[2].v = fTemp; } cgRender::Get()->RenderPolygon(polygon, rect_vertex_num, GetTextureID()); }
bool NxTextureVideo::OpenVideoFile( const std::string & filename, const std::string & TextureName, bool useOpenGL, NxVideoPixelFormatInfo & info ) { mNxVideoFile = NxVideoManager::getSingleton().OpenVideoFile( filename, info ); Type = TYPE_AVI; if( mNxVideoFile->HasAudio() ) { mHasAudio = true; mAudioSampleRate = mNxVideoFile->GetAudioSampleRate() ; mAudioChannels = mNxVideoFile->GetAudioNumChannels(); mAudioBufferSize = mNxVideoFile->GetAudioBufferSize(); mAudioBitsPerSamples = mNxVideoFile->GetAudioBitsperSamples(); } if( mNxVideoFile->HasVideo() ) { NxVideoPixelFormat format = mNxVideoFile->GetVideoFormat(); std::vector<VideoPlaneInfo> info; GetVideoPlaneInfo( mNxVideoFile, info ); for( int i = 0 ; i < info.size(); i++ ) { int numMipMaps = 0; Ogre::TexturePtr tex = TextureManager::getSingleton().createManual( TextureName+"_"+Ogre::StringConverter::toString( i ), "NxMaterialVideo", TEX_TYPE_2D, info[i].width, info[i].height, numMipMaps, (Ogre::PixelFormat)info[i].format, TU_DYNAMIC_WRITE_ONLY_DISCARDABLE ); mTexture.push_back( tex.get() ); mNxVideoFile->SetOpenGLID( i, GetTextureID( i ) ); } mFrameBuffer = new NxFrameBufferVideo( this ); //NxPixelBuffer = mVideoTexture->mTexture->getBuffer(0,0).get(); //if( mVideoTexture->NxPixelBuffer->getFormat() != mVideoTexture->FormatType ) { // LogMsg("----- ERROR texture depth INVALID2 !"); // // doesnt matter so much since when uploading to gpu, pixelbox will be converted... // LogMsg("pixel buffer format : " + Ogre::StringConverter::toString( mVideoTexture->mTexture->getFormat() ) ); // LogMsg("texture format : " + Ogre::StringConverter::toString( mVideoTexture->FormatType ) ); //} //mVideoTexture->Width = mVideoTexture->GetVideoWidth(); //mVideoTexture->Height = mVideoTexture->GetVideoHeight(); //mVideoTexture->NxTextureName = TextureName; //mVideoTexture->Bpp = mVideoTexture->GetVideoBpp(); //mVideoTexture->Bpp == 4 ? mVideoTexture->FormatType = NXPF_A8R8G8B8 : mVideoTexture->FormatType = NXPF_BYTE_BGR; // PixelFormat::PF_BYTE_BGRA // -> PF_A8R8G8B8 } return mNxVideoFile != NULL; }