private void _renderSetupGLSL(SSRenderConfig renderConfig, SSMainShaderProgram shaderPgm, SSMeshOBJSubsetData subset) { // Step 1: setup GL rendering modes... // GL.Enable(EnableCap.Lighting); // GL.Enable(EnableCap.Blend); // GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); // Step 2: setup our material mode and paramaters... if (renderConfig.drawingShadowMap) { // assume SSObject.Render has setup our materials properly for the shadowmap Pass // TODO: find a better way to do this! return; } if (shaderPgm == null) { SSShaderProgram.DeactivateAll(); // fixed function single-texture if (subset.TextureMaterial.diffuseTex != null) { GL.ActiveTexture(TextureUnit.Texture0); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, subset.TextureMaterial.diffuseTex.TextureID); } } else { shaderPgm.Activate(); shaderPgm.SetupTextures(subset.TextureMaterial); } }
private void _renderSendVBOTriangles(SSRenderConfig renderConfig, SSMeshOBJSubsetData subset) { subset.ibo.DrawElements(renderConfig, PrimitiveType.Triangles); }
private void _renderSendVBOTriangles(SSRenderConfig renderConfig, SSMeshOBJSubsetData subset) { subset.triangleMesh.drawSingle(renderConfig, PrimitiveType.Triangles); }
private void _renderSetupGLSL(SSRenderConfig renderConfig, SSMainShaderProgram shaderPgm, SSMeshOBJSubsetData subset) { // Step 1: setup GL rendering modes... // GL.Enable(EnableCap.Lighting); // GL.Enable(EnableCap.Blend); // GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); // Step 2: setup our material mode and paramaters... if (renderConfig.drawingShadowMap) { // assume SSObject.Render has setup our materials properly for the shadowmap Pass // TODO: find a better way to do this! return; } if (shaderPgm == null) { SSShaderProgram.DeactivateAll (); // fixed function single-texture if (subset.TextureMaterial.diffuseTex != null) { GL.ActiveTexture(TextureUnit.Texture0); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, subset.TextureMaterial.diffuseTex.TextureID); } } else { shaderPgm.Activate(); shaderPgm.SetupTextures(subset.TextureMaterial); } }
private void _renderSendVBOLines(SSRenderConfig renderConfig, SSMeshOBJSubsetData subset) { // TODO: this currently has classic problems with z-fighting between the model and the wireframe // it is customary to "bump" the wireframe slightly towards the camera to prevent this. GL.LineWidth(1.5f); GL.Color4(0.8f, 0.5f, 0.5f, 0.5f); subset.wireframeMesh.drawSingle(renderConfig, PrimitiveType.Lines); }
private void _renderSendTriangles(SSMeshOBJSubsetData subset) { // Step 3: draw faces.. here we use the "old school" manual method of drawing // note: programs written for modern OpenGL & D3D don't do this! // instead, they hand the vertex-buffer and index-buffer to the // GPU and let it do this.. GL.Begin(PrimitiveType.Triangles); foreach(var idx in subset.triangleMesh.lastAssignedIndices) { var vertex = subset.triangleMesh.lastAssignedVertices[idx]; // retrieve the vertex // draw the vertex.. GL.Color3(System.Drawing.Color.FromArgb(vertex.DiffuseColor)); GL.TexCoord2(vertex.TexCoord.X, vertex.TexCoord.Y); GL.Normal3(vertex.Normal); GL.Vertex3(vertex.Position); } GL.End(); }
private void _renderSendLines(SSMeshOBJSubsetData subset) { // Step 3: draw faces.. here we use the "old school" manual method of drawing // note: programs written for modern OpenGL & D3D don't do this! // instead, they hand the vertex-buffer and index-buffer to the // GPU and let it do this.. var indices = subset.wireframeMesh.lastAssignedIndices; for(int i=0; i<indices.Length; i+=3) { var v1 = subset.wireframeMesh.lastAssignedVertices [indices[i]]; var v2 = subset.wireframeMesh.lastAssignedVertices [indices[i+1]]; var v3 = subset.wireframeMesh.lastAssignedVertices [indices[i+2]]; // draw the vertex.. GL.Color3(System.Drawing.Color.FromArgb(v1.DiffuseColor)); GL.Begin(PrimitiveType.LineLoop); GL.Vertex3 (v1.Position); GL.Vertex3 (v2.Position); GL.Vertex3 (v3.Position); GL.End(); } }
private SSMeshOBJSubsetData _loadMaterialSubset(SSAssetManager.Context ctx, WavefrontObjLoader wff, WavefrontObjLoader.MaterialInfoWithFaces objMatSubset) { // generate renderable geometry data... SSVertex_PosNormTexDiff[] vertices; UInt16[] triIndices, wireframeIndices; VertexSoup_VertexFormatBinder.generateDrawIndexBuffer( wff, out triIndices, out vertices); wireframeIndices = OpenTKHelper.generateLineIndicies (triIndices); SSMeshOBJSubsetData subsetData = new SSMeshOBJSubsetData( vertices, triIndices, wireframeIndices); // setup the material... // load and link every texture present subsetData.TextureMaterial = new SSTextureMaterial(); if (objMatSubset.mtl.diffuseTextureResourceName != null) { subsetData.TextureMaterial.diffuseTex = SSAssetManager.GetInstance<SSTexture>(ctx, objMatSubset.mtl.diffuseTextureResourceName); } if (objMatSubset.mtl.ambientTextureResourceName != null) { subsetData.TextureMaterial.ambientTex = SSAssetManager.GetInstance<SSTexture>(ctx, objMatSubset.mtl.ambientTextureResourceName); } if (objMatSubset.mtl.bumpTextureResourceName != null) { subsetData.TextureMaterial.bumpMapTex = SSAssetManager.GetInstance<SSTexture>(ctx, objMatSubset.mtl.bumpTextureResourceName); } if (objMatSubset.mtl.specularTextureResourceName != null) { subsetData.TextureMaterial.specularTex = SSAssetManager.GetInstance<SSTexture>(ctx, objMatSubset.mtl.specularTextureResourceName); } return subsetData; }
private void _renderSetupGLSL(ref SSRenderConfig renderConfig, SSMeshOBJSubsetData subset) { // Step 1: setup GL rendering modes... GL.Enable(EnableCap.CullFace); // GL.Enable(EnableCap.Lighting); // GL.Enable(EnableCap.Blend); // GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); // Step 2: setup our material mode and paramaters... GL.Color3(System.Drawing.Color.White); // clear the vertex color to white.. SSMainShaderProgram shaderPgm = renderConfig.BaseShader; if (renderConfig.drawingShadowMap) { // assume SSObject.Render has setup our materials properly for the shadowmap Pass // TODO: find a better way to do this! return; } if (shaderPgm == null) { SSShaderProgram.DeactivateAll(); GL.Disable(EnableCap.CullFace); // fixed function single-texture GL.Disable(EnableCap.Texture2D); if (subset.diffuseTexture != null) { GL.ActiveTexture(TextureUnit.Texture0); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, subset.diffuseTexture.TextureID); } } else { // activate GLSL shader shaderPgm.Activate(); // bind our texture-images to GL texture-units // http://adriangame.blogspot.com/2010/05/glsl-multitexture-checklist.html // these texture-unit assignments are hard-coded in the shader setup GL.ActiveTexture(TextureUnit.Texture0); if (subset.diffuseTexture != null) { GL.BindTexture(TextureTarget.Texture2D, subset.diffuseTexture.TextureID); shaderPgm.u_DiffTexEnabled = true; } else { GL.BindTexture(TextureTarget.Texture2D, 0); shaderPgm.u_DiffTexEnabled = false; } GL.ActiveTexture(TextureUnit.Texture1); if (subset.specularTexture != null) { GL.BindTexture(TextureTarget.Texture2D, subset.specularTexture.TextureID); shaderPgm.u_SpecTexEnabled = true; } else { GL.BindTexture(TextureTarget.Texture2D, 0); shaderPgm.u_SpecTexEnabled = false; } GL.ActiveTexture(TextureUnit.Texture2); if (subset.ambientTexture != null) { GL.BindTexture(TextureTarget.Texture2D, subset.ambientTexture.TextureID); shaderPgm.u_AmbTexEnabled = true; } else { GL.BindTexture(TextureTarget.Texture2D, 0); shaderPgm.u_AmbTexEnabled = false; } GL.ActiveTexture(TextureUnit.Texture3); if (subset.bumpTexture != null) { GL.BindTexture(TextureTarget.Texture2D, subset.bumpTexture.TextureID); shaderPgm.u_BumpTexEnabled = true; } else { GL.BindTexture(TextureTarget.Texture2D, 0); shaderPgm.u_BumpTexEnabled = false; } // reset to texture-unit 0 to be friendly.. GL.ActiveTexture(TextureUnit.Texture0); } }