void nuiDrawContext::DrawShape(nuiShape* pShape, nuiShapeMode Mode, float Quality) { NGL_ASSERT(pShape != NULL); PushState(); switch (Mode) { case eStrokeShape: { nuiRenderObject* pObject = pShape->Outline(Quality, mCurrentState.mLineWidth, mCurrentState.mLineJoin, mCurrentState.mLineCap); SetFillColor(GetStrokeColor()); SetTexture(mpAATexture); EnableTexturing(true); EnableBlending(true); SetBlendFunc(nuiBlendTransp);//GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); DrawObject(*pObject); delete pObject; } break; case eFillShape: { nuiTessellator* pTess = new nuiTessellator(pShape); pTess->SetFill(true); nuiRenderObject* pObject = pTess->Generate(Quality); DrawObject(*pObject); delete pObject; delete pTess; } break; case eStrokeAndFillShape: { { nuiRenderObject* pObject = pShape->Fill(Quality); DrawObject(*pObject); delete pObject; } { nuiRenderObject* pObject = pShape->Outline(Quality, mCurrentState.mLineWidth, mCurrentState.mLineJoin, mCurrentState.mLineCap); SetFillColor(GetStrokeColor()); SetTexture(mpAATexture); EnableTexturing(true); EnableBlending(true); SetBlendFunc(nuiBlendTransp);//GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); DrawObject(*pObject); delete pObject; } } break; case eDefault: //? break; } PopState(); }
void nuiGLDrawContext::BlurRect(const nuiRect& rRect, uint Strength) { nuiRect Rect = rRect; if (mClippingRect.mEnabled) Rect.Intersect(mClippingRect,rRect); nuiRect size = Rect.Size(); nuiTexture* pScratchPad = GetScratchPad(ToZero(size.GetWidth()), ToZero(size.GetHeight())); if (!pScratchPad) return; SetTexture(pScratchPad); glPushMatrix(); glLoadIdentity(); EnableBlending(true); EnableTexture2D(true); SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); do { glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, ToZero(rRect.mLeft), ToZero(mHeight) - 1 - ToZero(rRect.mTop) - ToZero(rRect.GetHeight()), ToZero(rRect.GetWidth()), ToZero(rRect.GetHeight()) ); SetFillColor(nuiColor(1,1,1,.15f)); nuiRect rect = Rect; rect.Move(-1,-1); DrawImage(rect,size); rect.Move(1,0); DrawImage(rect,size); rect.Move(1,0); DrawImage(rect,size); rect.Move(-2,1); DrawImage(rect,size); rect.Move(1,0); DrawImage(rect,size); rect.Move(1,0); DrawImage(rect,size); rect.Move(-2,1); DrawImage(rect,size); rect.Move(0,1); DrawImage(rect,size); rect.Move(0,1); DrawImage(rect,size); } while ((long)(Strength--) > 0); EnableBlending(false); EnableTexture2D(false); glPopMatrix(); }
void DrawBuffersIndexedBase::BlendMaskStateMachine::SetDefaults() { SetDisable(); SetColorMask(1, 1, 1, 1); SetBlendEquation(GL_FUNC_ADD); SetBlendFunc(GL_ONE, GL_ZERO); }
void GLRenderState::Bind() { SetBlend(srcBlend, dstBlend); SetBlendFunc(blendFunc); SetAlphaTest(alphaTest, alphaRef); SetCull(cullMode); SetDepthTest(depthTest); SetDepthWrite(depthWrite); /* if(!curState) { curState = this; return; } if(curState->GetSrcBlend() != srcBlend || curState->GetDstBlend() != dstBlend) { SetBlend(srcBlend, dstBlend); } if(curState->GetBlendFunc() != blendFunc) { SetBlendFunc(blendFunc); } if(curState->GetAlphaTest() != alphaTest || curState->GetAlphaRef() != alphaRef) { SetAlphaTest(alphaTest, alphaRef); } if(curState->GetDepthTest() != depthTest) { SetDepthTest(depthTest); } if(curState->GetDepthWrite() != depthWrite) { SetDepthWrite(depthWrite); } if(curState->GetCullMode() != cullMode) { SetCull(cullMode); } */ curState = this; }
void nuiGLDrawContext::DrawLine(float x1, float y1, float x2, float y2) { if (mCurrentState.mAntialiasing && mPermitAntialising) { EnableTexture2D(true); EnableBlending(true); EnableAlphaTest(true); glBindTexture(GL_TEXTURE_2D, glAA_texture[0]); SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glAlphaFunc(GL_GREATER, 1.0f/255.0f); // texture init glMatrixMode(GL_TEXTURE); glLoadIdentity(); glScalef(0.25/phf, 0.25/phf, 1.0); // glAArg requires rectangle coordinate setup glMatrixMode(GL_MODELVIEW); glAALineWidth(mCurrentState.mLineWidth); glAABegin(GL_LINES); glAAColor4f(mCurrentState.mStrokeColor.Red(), mCurrentState.mStrokeColor.Green(), mCurrentState.mStrokeColor.Blue(), mCurrentState.mStrokeColor.Alpha()); glAAVertex2f(x1, y1); glAAVertex2f(x2, y2); glAAEnd(); glAAFlush(); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); SetTexture(NULL); EnableTexture2D(false); EnableBlending(false); EnableAlphaTest(false); } else { mCurrentState.mStrokeColor.Apply(); glBegin(GL_LINES); glVertex2f(x1,y1); glVertex2f(x2,y2); glEnd(); } }
void nuiGLDrawContext::DrawShade (const nuiRect& rSourceRect, const nuiRect& rShadeRect) { // return; bool blending = mCurrentState.mBlending; GLenum blendfunc1,blendfunc2; blendfunc1 = mCurrentState.mBlendSourceFactor; blendfunc2 = mCurrentState.mBlendDestinationFactor; EnableBlending(true); SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); nuiSize ShadeSize = rSourceRect.mLeft - rShadeRect.mLeft; // Left shadow uint8 pLUT[256*4]; uint i; for (i = 0; i<256; i++) { pLUT[0+(i*4)] = 0; pLUT[1+(i*4)] = 0; pLUT[2+(i*4)] = 0; pLUT[3+(i*4)] = i; } EnableTexture2D(false); EnableTexture1D(true); glBindTexture(GL_TEXTURE_1D,0); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, pLUT); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); glBegin(GL_QUADS); glColor4f(0,0,0,0); glTexCoord1f(0); glVertex2f(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop); glTexCoord1f(1); glVertex2f(rSourceRect.mLeft,rSourceRect.mTop); glColor4f(0,0,0,SHADE_ALPHA); glTexCoord1f(1); glVertex2f(rSourceRect.mLeft,rSourceRect.mTop+ShadeSize); glTexCoord1f(0); glVertex2f(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop+ShadeSize); glEnd(); EnableTexture1D(false); glBegin(GL_QUADS); glColor4f(0,0,0,0); glVertex2f(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop+ShadeSize); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mLeft,rSourceRect.mTop+ShadeSize); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mLeft,rSourceRect.mBottom); glColor4f(0,0,0,0); glVertex2f(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom); glEnd(); // bottom shadow glBegin(GL_QUADS); glColor4f(0,0,0,0); glVertex2f(rSourceRect.mLeft,rSourceRect.mBottom+ShadeSize); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mLeft,rSourceRect.mBottom); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mRight,rSourceRect.mBottom); glColor4f(0,0,0,0); glVertex2f(rSourceRect.mRight,rSourceRect.mBottom+ShadeSize); glEnd(); // Right shadow EnableTexture1D(true); glBegin(GL_QUADS); glColor4f(0,0,0,0); glTexCoord1f(1); glVertex2f(rSourceRect.mRight,rSourceRect.mTop); glTexCoord1f(0); glVertex2f(rSourceRect.mRight+ShadeSize,rSourceRect.mTop); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mRight+ShadeSize,rSourceRect.mTop+ShadeSize); glTexCoord1f(1); glVertex2f(rSourceRect.mRight,rSourceRect.mTop+ShadeSize); glEnd(); EnableTexture1D(false); glBegin(GL_QUADS); glColor4f(0,0,0,0); glVertex2f(rSourceRect.mRight+ShadeSize,rSourceRect.mTop+ShadeSize); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mRight,rSourceRect.mTop+ShadeSize); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mRight,rSourceRect.mBottom); glColor4f(0,0,0,0); glVertex2f(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom); glEnd(); EnableTexture1D(true); glBegin(GL_QUADS); // Right Corner glColor4f(0,0,0,SHADE_ALPHA); glTexCoord1f(1); glVertex2f(rSourceRect.mRight,rSourceRect.mBottom); glColor4f(0,0,0,0); glVertex2f(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom); glColor4f(0,0,0,0); glTexCoord1f(0); glVertex2f(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom+ShadeSize); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mRight,rSourceRect.mBottom+ShadeSize); // Left Corner: glColor4f(0,0,0,0); glTexCoord1f(1); glVertex2f(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mLeft,rSourceRect.mBottom); glColor4f(0,0,0,SHADE_ALPHA); glTexCoord1f(0); glVertex2f(rSourceRect.mLeft,rSourceRect.mBottom+ShadeSize); glColor4f(0,0,0,0); glVertex2f(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom+ShadeSize); glEnd(); EnableTexture1D(false); EnableBlending(blending); SetBlendFunc(blendfunc1, blendfunc2); }
void nuiGLDrawContext::DrawCachedShape(std::list<nuiShape::CacheElement*>* pElements, nuiShapeMode Mode) { bool blend = mCurrentState.mBlending; uint func1,func2; bool tex2D; func1 = mCurrentState.mBlendSourceFactor; func2 = mCurrentState.mBlendDestinationFactor; tex2D = mCurrentState.mTexture2D; nuiColor c; if (Mode == eStrokeShape) { if (mCurrentState.mAntialiasing && mPermitAntialising) { EnableTexture2D(true); EnableBlending(true); EnableAlphaTest(true); glBindTexture(GL_TEXTURE_2D, glAA_texture[0]); SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glAlphaFunc(GL_GREATER, 1.0f/255.0f); // texture init glMatrixMode(GL_TEXTURE); glLoadIdentity(); glScalef(0.25/phf, 0.25/phf, 1.0); // glAArg requires rectangle coordinate setup glMatrixMode(GL_MODELVIEW); glAALineWidth(mCurrentState.mLineWidth); std::list<nuiShape::CacheElement*>::iterator it; std::list<nuiShape::CacheElement*>::iterator end = pElements->end(); for (it = pElements->begin(); it != end; ++it) { nuiShape::CacheElement* pElement = *it; uint i = 0; switch (pElement->mOperation) { case GL_POINTS: case GL_LINES: case GL_LINE_LOOP: case GL_LINE_STRIP: c = mCurrentState.mStrokeColor; break; case GL_TRIANGLES: case GL_TRIANGLE_STRIP: case GL_TRIANGLE_FAN: case GL_QUADS: case GL_QUAD_STRIP: case GL_POLYGON: c = mCurrentState.mFillColor; break; } /* if (pElement->mCount > 16) glAADisable(GLAA_VERTEX_ARRAY); // we want VAR acceleration and we will handle flushing else glAAEnable(GLAA_VERTEX_ARRAY); // we want VAR acceleration and we will handle flushing */ glAAColor4f( c.Red(), c.Green(), c.Blue(), c.Alpha() ); glAABegin(pElement->mOperation); for (i = 0; i<pElement->mCount; i++) { nuiShape::CacheElement* pElement = *it; /*float* c = pElement->mpVertices[i].mColor; (unused) */ float* coords = pElement->mpVertices[i].mCoord; glAAVertex2f(coords[0], coords[1]); } glAAEnd(); glAAFlush(); } glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); SetTexture(NULL); EnableTexture2D(false); EnableBlending(false); EnableAlphaTest(false); return; } glLineWidth(mCurrentState.mLineWidth); } std::list<nuiShape::CacheElement*>::iterator it; std::list<nuiShape::CacheElement*>::iterator end = pElements->end(); for (it = pElements->begin(); it != end; ++it) { nuiShape::CacheElement* pElement = *it; switch (pElement->mOperation) { case GL_POINTS: case GL_LINES: case GL_LINE_LOOP: case GL_LINE_STRIP: c = mCurrentState.mStrokeColor; break; case GL_TRIANGLES: case GL_TRIANGLE_STRIP: case GL_TRIANGLE_FAN: case GL_QUADS: case GL_QUAD_STRIP: case GL_POLYGON: c = mCurrentState.mFillColor; break; } glColor4f( c.Red(), c.Green(), c.Blue(), c.Alpha() ); if (pElement->mCount <= NUI_COMPLEX_SHAPE_THRESHOLD) { uint i = 0; glBegin(pElement->mOperation); for (i = 0; i<pElement->mCount; i++) { nuiShape::CacheElement* pElement = *it; glVertex3fv(pElement->mpVertices[i].mCoord); } glEnd(); } else { glVertexPointer(3,GL_FLOAT,sizeof(nuiShape::CacheElement::Vertex),pElement->mpVertices->mCoord); glEnableClientState(GL_VERTEX_ARRAY); glDrawArrays(pElement->mOperation, 0, pElement->mCount); } } //EnableLineSmooth(false); glDisable(GL_LINE_SMOOTH); SetBlendFunc(func1, func2); EnableTexture2D(tex2D); EnableBlending(blend); }
void nuiDrawContext::DrawShade(const nuiRect& rSourceRect, const nuiRect& rShadeRect, const nuiColor& rTint) { bool texturing = mCurrentState.mTexturing; bool blending = mCurrentState.mBlending; nuiBlendFunc blendfunc; blendfunc = mCurrentState.mBlendFunc; if (!blending) EnableBlending(true); if (blendfunc != nuiBlendTransp) SetBlendFunc(nuiBlendTransp); nuiSize ShadeSize = rSourceRect.mLeft - rShadeRect.mLeft; nuiTexture* pShade = ::nuiTexture::GetTexture(nglString(_T("NUI_Shade_LUT"))); if (!pShade) { // Left shadow const uint32 size = 16; uint8 pLUT[size * 4]; uint i; for (i = 0; i<size; i++) { pLUT[0+(i*4)] = 0; pLUT[1+(i*4)] = 0; pLUT[2+(i*4)] = 0; float p = (float)i * (255.0f / (float)size); pLUT[3+(i*4)] = ToBelow(p); } nglImageInfo info(false); info.mBitDepth = 32; info.mBufferFormat = eImageFormatRaw; info.mBytesPerLine = size * 4; info.mBytesPerPixel = 4; info.mHeight = 1; info.mWidth = size; info.mpBuffer = (char*)pLUT; info.mPixelFormat = eImagePixelRGBA; pShade = nuiTexture::GetTexture(info, true); pShade->SetSource(_T("NUI_Shade_LUT")); NGL_ASSERT(pShade); pShade->SetMinFilter(GL_LINEAR); pShade->SetMagFilter(GL_LINEAR); #ifndef _OPENGL_ES_ pShade->SetWrapS(GL_CLAMP); pShade->SetWrapT(GL_CLAMP); #else pShade->SetWrapS(GL_CLAMP_TO_EDGE); pShade->SetWrapT(GL_CLAMP_TO_EDGE); #endif pShade->SetEnvMode(GL_MODULATE); } nuiColor transp(rTint); nuiColor opaque(rTint); transp.Multiply(0.0f); opaque.Multiply(SHADE_ALPHA); if (!texturing) EnableTexturing(true); SetTexture(pShade); nuiRenderArray* pArray = new nuiRenderArray(GL_TRIANGLES); pArray->EnableArray(nuiRenderArray::eVertex); pArray->EnableArray(nuiRenderArray::eColor); pArray->EnableArray(nuiRenderArray::eTexCoord); pArray->Reserve(42); // Top Left: pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetTexCoords(0, 0); pArray->SetColor(opaque); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); // Left pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); // Left Corner: pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); // bottom shadow pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); // Right Corner pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); // Right pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom); pArray->PushVertex(); // Top Right pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); DrawArray(pArray); if (!texturing) EnableTexturing(false); if (!blending) EnableBlending(blending); if (blendfunc != nuiBlendTransp) SetBlendFunc(blendfunc); }
bool CRenderSystem::prepareMaterial(/*const */CMaterial& material, float fOpacity) // 由于使用了自动注册纹理的机制,很遗憾的导致不能用“const” { CTextureMgr& TM = GetTextureMgr(); for (size_t i=0;i<8;++i) { if (material.uTexture[i]==-1) { material.uTexture[i] = TM.RegisterTexture(material.getTexture(i)); } // ---- SetTexture(i, material.uTexture[i]); // ---- if (material.uTexture[i]==0) { break; } } if (material.uShader==-1) { material.uShader = GetShaderMgr().registerItem(material.getShader()); } // ---- SetLightingEnabled(material.bLightingEnabled); SetCullingMode((CullingMode)material.uCull); // ---- SetAlphaTestFunc(material.bAlphaTest, (CompareFunction)material.nAlphaTestCompare, material.uAlphaTestValue); SetBlendFunc(material.bBlend, (SceneBlendOperation)material.nBlendOP, (SceneBlendFactor)material.nBlendSrc, (SceneBlendFactor)material.nBlendDest); SetDepthBufferFunc(material.bDepthTest,material.bDepthWrite); // ---- if (0==material.uShader) { for (size_t i=0;i<8;++i) { CMaterial::TextureOP& texOP = material.textureOP[i]; SetTextureColorOP(i, (TextureBlendOperation)texOP.nColorOP, (TextureBlendSource)texOP.nColorSrc1, (TextureBlendSource)texOP.nColorSrc2); SetTextureColorOP(i, (TextureBlendOperation)texOP.nAlphaOP, (TextureBlendSource)texOP.nAlphaSrc1, (TextureBlendSource)texOP.nAlphaSrc2); if (TBOP_DISABLE == texOP.nColorOP) { break; } } } else { CShader* pShader = GetShaderMgr().getSharedShader(); if (pShader) { // for Terrain pShader->setVec2D("g_fScaleUV",material.vUVScale); } SetShader(material.uShader); } return true; /* if (material.bLightingEnabled) { SetMaterial(material.vAmbient,material.vDiffuse); } if (0==material.uShader) { //SetSamplerAddressUV(0,ADDRESS_WRAP,ADDRESS_WRAP); if (material.vTexAnim.lengthSquared()>0.0f) { Matrix matTex=Matrix::UNIT; float fTime = (float)GetGlobalTimer().GetTime(); matTex._13=fTime*material.vTexAnim.x; matTex._23=fTime*material.vTexAnim.y; setTextureMatrix(0, TTF_COUNT3, matTex); } Color32 cFactor = material.cEmissive; if (material.m_fOpacity<0.0f) { fOpacity = (float)(rand()%255)/255.0f; } else { fOpacity *= material.m_fOpacity; } if (material.uDiffuse) { SetTexture(0, material.uDiffuse); cFactor.a=(unsigned char)(cFactor.a*fOpacity); SetTextureFactor(cFactor); if (material.bLightingEnabled) { SetTextureColorOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_DIFFUSE); } else { SetTextureColorOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_TFACTOR); } if(material.bBlend||material.m_fOpacity<1.0f) { SetBlendFunc(true, BLENDOP_ADD, SBF_SOURCE_ALPHA, SBF_ONE_MINUS_SOURCE_ALPHA); } if (material.m_fOpacity<1.0f) { SetTextureAlphaOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_TFACTOR); } else if (material.bAlphaTest||material.bBlend) { SetTextureAlphaOP(0, TBOP_SOURCE1, TBS_TEXTURE); } else { SetTextureAlphaOP(0, TBOP_DISABLE); } ////////////////////////////////////////////////////////////////////////// if (material.uSpecular) { SetTexture(1, material.uSpecular); SetTextureColorOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_DIFFUSE); setResultARGToTemp(1,true); SetTextureColorOP(1, TBOP_MODULATE_X2, TBS_TEXTURE, TBS_SPECULAR); SetTextureColorOP(2, TBOP_ADD, TBS_CURRENT, TBS_TEMP); SetTexCoordIndex(0,0); SetTexCoordIndex(1,0); SetTexCoordIndex(2,0); } else if (material.uReflection) { SetTextureColorOP(1, TBOP_MODULATE_X2, TBS_CURRENT, TBS_TEXTURE); SetTexCoordIndex(1,TCI_CAMERASPACE_NORMAL|TCI_CAMERASPACE_POSITION); SetTexture(1, material.uReflection); } else if (material.uLightMap) { SetTextureColorOP(1, TBOP_MODULATE, TBS_CURRENT, TBS_TEXTURE); SetTexCoordIndex(1,1); SetTexture(1, material.uLightMap); } else if (material.uEmissive) { SetTextureColorOP(1, TBOP_ADD, TBS_CURRENT, TBS_TEXTURE); SetTexture(1, material.uEmissive); } else if(!material.bBlend&&material.m_fOpacity>=1.0f) { SetTextureColorOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_DIFFUSE); } } else { SetTextureFactor(cFactor); if (material.uSpecular) { //SetTexture(0, material.uSpecular); SetTextureColorOP(0, TBOP_SOURCE1, TBS_SPECULAR); SetTexCoordIndex(0,0); } else if(material.uReflection) { cFactor.r=(unsigned char)(cFactor.r*fOpacity); cFactor.g=(unsigned char)(cFactor.g*fOpacity); cFactor.b=(unsigned char)(cFactor.b*fOpacity); SetTextureFactor(cFactor); if (material.bBlend) { SetBlendFunc(true, BLENDOP_ADD, SBF_DEST_COLOUR, SBF_ONE); } SetTextureColorOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_TFACTOR); SetTextureAlphaOP(0, TBOP_DISABLE); SetTexCoordIndex(0,TCI_CAMERASPACE_NORMAL|TCI_CAMERASPACE_POSITION); SetTexture(0, material.uReflection); } else if (material.uLightMap) { if (material.bBlend) { SetBlendFunc(true, BLENDOP_ADD, SBF_DEST_COLOUR, SBF_ZERO); } SetTextureColorOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_TFACTOR); SetTextureAlphaOP(0, TBOP_DISABLE); SetTexture(0, material.uLightMap); } else if (material.uEmissive) { cFactor.r=(unsigned char)(cFactor.r*fOpacity); cFactor.g=(unsigned char)(cFactor.g*fOpacity); cFactor.b=(unsigned char)(cFactor.b*fOpacity); SetTextureFactor(cFactor); if (material.bBlend) { SetBlendFunc(true, BLENDOP_ADD, SBF_ONE, SBF_ONE); } SetTextureColorOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_TFACTOR); SetTextureAlphaOP(0, TBOP_DISABLE); SetTexture(0, material.uEmissive); } else if (material.uNormal) { CShader* pShader = GetShaderMgr().getSharedShader(); if (pShader) { static size_t s_uShaderID = GetShaderMgr().registerItem("EngineRes\\fx\\SpaceBump.fx"); pShader->setTexture("g_texNormal",material.uNormal); SetShader(s_uShaderID); } //SetBlendFunc(true, BLENDOP_ADD, SBF_DEST_COLOUR, SBF_ZERO); //SetTextureColorOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_TFACTOR); //SetTextureAlphaOP(0, TBOP_DISABLE); //SetTexture(0, uLightMap); } else { SetTextureColorOP(0,TBOP_SOURCE2); if (material.bBlend) { SetTextureAlphaOP(0,TBOP_SOURCE2); } else { SetTextureAlphaOP(0,TBOP_DISABLE); } //return false; } } } else { CShader* pShader = GetShaderMgr().getSharedShader(); if (pShader) { pShader->setTexture("g_texDiffuse",material.uDiffuse); pShader->setTexture("g_texLight",material.uLightMap); pShader->setTexture("g_texNormal",material.uNormal); //pShader->setTexture("g_texEnvironment",uEmissive); //pShader->setTexture("g_texEmissive",uEmissive); pShader->setTexture("g_texSpecular",material.uSpecular); // for Terrain pShader->setVec2D("g_fScaleUV",material.vUVScale); } SetShader(material.uShader); } return true;*/ }