static void DialogClose(GtkDialog * UNUSED(dialog), gint response, void *UNUSED(data)) { if ((GtkResponseType) response == GTK_RESPONSE_OK) { /* Apply new settings */ char *texStr; /* Copy new settings to preview material */ curDetails->mat = col3d; *curDetails->pBoardMat = col3d; if (useTexture) { texStr = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(textureComboBox)); if (!strcmp(texStr, NO_TEXTURE_STRING)) col3d.textureInfo = 0; else { BoardData *bd = (BOARD(pwPrevBoard))->board_data; ClearTextures(bd->bd3d); GetTextures(bd->bd3d, bd->rd); } } UpdatePreview(); gtk_widget_queue_draw(curDetails->preview); } /* Hide dialog so can be reshown quickly */ gtk_widget_hide(pwColourDialog3d); }
void scRenderSystem::_Draw() { auto vpIter = mSceneManager.GetViewports().begin(); for (; vpIter != mSceneManager.GetViewports().end(); ++vpIter) { scViewport* vp = (*vpIter); // 不渲染不可见的viewport if (!vp->IsVisible()) continue; // 设置当前viewport mContext->RSSetViewports(1, &vp->GetViewport()); // 投影矩阵(viewport相关) //XMMATRIX projMat = XMMatrixPerspectiveFovRH( XM_PIDIV4, 500.f / 500.0f, 0.01f, 1000.0f ); XMMATRIX projMat = XMLoadFloat4x4(&vp->GetProjectionMatrix()); projMat = XMMatrixTranspose( projMat ); mContext->UpdateSubresource( projCB_, 0, 0, &projMat, 0, 0 ); mContext->VSSetConstantBuffers( 2, 1, &projCB_ ); // 视矩阵(摄像机矩阵) //XMMATRIX viewMat = XMMatrixLookAtRH(XMVectorSet(0, 0, 100, 1), XMVectorSet(0, 0, 0, 1), XMVectorSet(0, 1, 0, 1)); XMMATRIX viewMat = XMLoadFloat4x4(&vp->GetCamera()->GetViewMatrix()); viewMat = XMMatrixTranspose( viewMat ); mContext->UpdateSubresource( viewCB_, 0, 0, &viewMat, 0, 0 ); mContext->VSSetConstantBuffers( 1, 1, &viewCB_ ); // 测试 mSceneManager._RenderScene(); unsigned int stride = sizeof( scVertex ); unsigned int offset = 0; // sampler mContext->PSSetSamplers(0, 1, &mSampler); // 遍历渲染列表 auto roIter = mSceneManager.GetRenderQueue().begin(); while (roIter != mSceneManager.GetRenderQueue().end()) { scMesh* mesh = roIter->GetMesh(); scVertexShader* vs = roIter->GetVertexShader(); scPixelShader* ps = roIter->GetPixelShader(); ID3D11Buffer* meshBuf = mesh->GetMeshBufferPtr(); mContext->IASetVertexBuffers(0, 1, &meshBuf, &stride, &offset); mContext->IASetPrimitiveTopology(mesh->GetTopology()); mContext->VSSetShader(vs->GetShaderDataPtr(), 0, 0); mContext->IASetInputLayout(vs->GetInputLayout()); mContext->PSSetShader(ps->GetShaderDataPtr(), 0, 0); if (!roIter->GetTextures().empty()) { auto texIter = roIter->GetTextures().begin(); while (texIter != roIter->GetTextures().end()) { ID3D11ShaderResourceView* tex = (*texIter)->GetTextureDataPtr(); //TODO: 不知道这样做多重纹理会不会有问题 mContext->PSSetShaderResources(0, 1, &tex); ++texIter; } } XMMATRIX worldMat = XMLoadFloat4x4(&roIter->_GetTransform()); worldMat = XMMatrixTranspose( worldMat ); mContext->UpdateSubresource( worldCB_, 0, 0, &worldMat, 0, 0 ); mContext->VSSetConstantBuffers( 0, 1, &worldCB_ ); mContext->Draw( mesh->GetVertexCount(), 0 ); ++roIter; } } }
void SpriteBatch::FlushText( const std::vector<sstring>& text, const tstring& fontname, TransformComponent* transform, const Color& color ) { if(text.size() == 0) { Logger::GetInstance()->Log(LogLevel::Warning, _T("FontManager::DrawText: Drawing an empty string...")); return; } auto curfont = FontManager::GetInstance()->GetFont(fontname); float32 h = curfont.GetSize()/0.63f; const vec2& position = transform->GetWorldPosition().pos2D(); const vec2& origposition = position; GLuint* textures = curfont.GetTextures(); const std::vector<fontUvCoords>& tempuvs = curfont.GetUvCoords(); const std::vector<fontVertices>& tempverts = curfont.GetVetrices(); const std::vector<ivec2>& tempsizes = curfont.GetLetterDimensions(); m_Shader.Bind(); //Enable the attributes glEnableVertexAttribArray(ATTRIB_VERTEX); glEnableVertexAttribArray(ATTRIB_UV); glActiveTexture(GL_TEXTURE0); GLint s_textureId = glGetUniformLocation(m_Shader.GetID(), "textureSampler"); glUniform1i(s_textureId, 0); GLint s_colorId = glGetUniformLocation(m_Shader.GetID(), "colorMultiplier"); glUniform4f(s_colorId,color.r,color.g,color.b,color.a); float32 scaleValue = ScaleSystem::GetInstance()->GetScale(); mat4 scaleMat = Scale(scaleValue, scaleValue, 1.0f); int32 offsetX(0); int32 offsetY(0); for(auto it = text.begin(); it != text.end() ; ++it) { const schar *start_line=it->c_str(); for(int32 i = 0 ; start_line[i] != 0 ; ++i) { glBindTexture(GL_TEXTURE_2D,textures[ start_line[i] ]); //Set attributes and buffers glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT,0,0, tempverts[start_line[i]].ver); glVertexAttribPointer(ATTRIB_UV, 2, GL_FLOAT, 0, 0, tempuvs[start_line[i]].uv); mat4 offsetTrans; if(start_line[i] != 0) { int32 offset = curfont.GetMaxLetterHeight() - tempsizes[start_line[i]].y; offsetTrans = Translate( vec3(offsetX, offsetY - curfont.GetMaxLetterHeight() - offset, 0)); offsetX += tempsizes[start_line[i]].x; } else { offsetTrans = Translate(0.0f, 0.0f, 0.0f); } const mat4& world = transform->GetWorldMatrix() * offsetTrans; glUniformMatrix4fv(glGetUniformLocation(m_Shader.GetID(),"MVP"), 1,GL_FALSE, ToPointerValue( Transpose(world) * scaleMat * GraphicsManager::GetInstance()->GetViewProjectionMatrix() ) ); glDrawArrays(GL_TRIANGLE_STRIP,0,4); } offsetY -= curfont.GetMaxLetterHeight(); offsetX = 0; } //Unbind attributes and buffers glDisableVertexAttribArray(ATTRIB_VERTEX); glDisableVertexAttribArray(ATTRIB_UV); m_Shader.Unbind(); }
/// \brief /// Gather relevant resource information that pOwner relies on. In this case, add all textures /// from all sets. void GetDependencies(VResourceSnapshot &snapshot, VManagedResource *pOwner) { for (int i=0;i<m_iSurfaceCount;i++) GetTextures(i)->GetDependencies(snapshot,pOwner); }