Exemple #1
0
        public static void render_model_surfaces(Matrix4 leftViewMat, Matrix4 leftProjMat, Viewport leftViewport, float time)
        {
            int i;

            // Setup State
            shader_gl shader = modelSurfaces[0].shader;

            glshading.setShader(shader);
            stage_gl      stage         = shader.stages[0];
            shader_prog_t shaderProgram = glshading.setShaderStage(shader, stage, time);

            BspOpenglBinders.BindShaderAttribs(shaderProgram);
            GL.ActiveTexture(TextureUnit.Texture0);

            BspOpenglBinders.BindShaderMatrix(shaderProgram, leftViewMat, leftProjMat);
            setViewport(leftViewport);

            for (i = 0; i < modelSurfaces.Count; ++i)
            {
                shader_p surface = modelSurfaces[i];
                stage_gl stage2  = surface.shader.stages[0];
                GL.BindTexture(TextureTarget.Texture2D, stage2.texture);
                GL.DrawElements(BeginMode.Triangles, surface.elementCount, DrawElementsType.UnsignedShort, surface.indexOffset);
            }
        }
Exemple #2
0
        public static void render_default_surfaces(Matrix4 leftViewMat, Matrix4 leftProjMat, Viewport leftViewport, float time)
        {
            int i;

            // Map Geometry buffers
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer);

            // Default shader surfaces (can bind shader once and draw all of them very quickly)
            if (defaultSurfaces.Count > 0 || unshadedSurfaces.Count > 0)
            {
                // Setup State
                shader_gl shader = glshading.defaultShader;
                glshading.setShader(shader);
                stage_gl      stage         = shader.stages[0];
                shader_prog_t shaderProgram = glshading.setShaderStage(shader, stage, time);


                BspOpenglBinders.BindShaderAttribs(shaderProgram);

                GL.ActiveTexture(TextureUnit.Texture0);
                GL.BindTexture(TextureTarget.Texture2D, glshading.defaultTexture);

                BspOpenglBinders.BindShaderMatrix(shaderProgram, leftViewMat, leftProjMat);
                setViewport(leftViewport);

                for (i = 0; i < unshadedSurfaces.Count; ++i)
                {
                    shader_p surface = unshadedSurfaces[i];
                    GL.DrawElements(BeginMode.Triangles, surface.elementCount, DrawElementsType.UnsignedShort, surface.indexOffset);
                }
                for (i = 0; i < defaultSurfaces.Count; ++i)
                {
                    shader_p surface = defaultSurfaces[i];
                    //stage_gl stage2 = surface.shader.stages[0];
                    foreach (stage_gl stage2 in surface.shader.stages)
                    {
                        GL.ActiveTexture(TextureUnit.Texture0);
                        GL.BindTexture(TextureTarget.Texture2D, stage2.texture);
                        GL.DrawElements(BeginMode.Triangles, surface.elementCount, DrawElementsType.UnsignedShort, surface.indexOffset);
                    }
                }
            }
        }
Exemple #3
0
        public static void render_effect_surfaces(Matrix4 leftViewMat, Matrix4 leftProjMat, Viewport leftViewport, float time)
        {
            int i;
            int j;

            // Effect surfaces
            for (i = 0; i < effectSurfaces.Count; ++i)
            {
                shader_p surface = effectSurfaces[i];
                if (surface.elementCount == 0 || surface.visible != true)
                {
                    continue;
                }

                // Bind the surface shader
                shader_gl shader = surface.shader;

                if (highlighted != null && highlighted == surface.shaderName)
                {
                    shader = glshading.defaultShader;
                }

                //shader = glshading.defaultShader; // test to show that effect shaders are buggy. Later remove this line to use the effect shader properly.

                if (shader.name == "textures/atcs/force_field_s")
                {
                    //var tex = shader.stages[0].texture;
                    //shader = glshading.defaultShader;
                    //shader.stages[0].texture = tex;

                    var tmp = shader;
                    shader = glshading.defaultShader;
                    shader.stages[0].texture = tmp.stages[0].texture;
                }

                if (!glshading.setShader(shader))
                {
                    continue;
                }

                for (j = 0; j < shader.stages.Count; ++j)
                {
                    stage_gl      stage = shader.stages[j];
                    shader_prog_t shaderProgram;

                    //if (stage.shaderName == "textures/atcs/force_field_s")
                    //{
                    //    //shaderProgram = glshading.setShaderStage_EffectDEBUG(shader, stage, time);
                    //    shaderProgram = glshading.defaultProgram;
                    //    GL.UseProgram(shaderProgram.program);
                    //}
                    //else
                    //{
                    //    shaderProgram = glshading.setShaderStage(shader, stage, time);
                    //}

                    //shaderProgram = glshading.defaultProgram;
                    //GL.UseProgram(shaderProgram.program);

                    shaderProgram = glshading.setShaderStage(shader, stage, time);

                    if (shaderProgram == null)
                    {
                        continue;
                    }

                    BspOpenglBinders.BindShaderAttribs(shaderProgram);
                    BspOpenglBinders.BindShaderMatrix(shaderProgram, leftViewMat, leftProjMat);

                    setViewport(leftViewport);

                    // Draw all geometry that uses this textures
                    GL.DrawElements(BeginMode.Triangles, surface.elementCount, DrawElementsType.UnsignedShort, surface.indexOffset);
                }
            }
        }