Ejemplo n.º 1
0
        public SSShadowMap(SSLight light, TextureUnit texUnit)
        {
            validateVersion();
            if (s_numberOfShadowMaps >= c_maxNumberOfShadowMaps)
            {
                throw new Exception("Unsupported number of shadow maps: "
                                    + (c_maxNumberOfShadowMaps + 1));
            }
            ++s_numberOfShadowMaps;

            m_light         = light;
            m_frameBufferID = GL.Ext.GenFramebuffer();
            m_textureID     = GL.GenTexture();

            // bind the texture and set it up...
            m_textureUnit = texUnit;
            BindShadowMapToTexture();
            GL.TexParameter(TextureTarget.Texture2D,
                            TextureParameterName.TextureMagFilter,
                            (int)TextureMagFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D,
                            TextureParameterName.TextureMinFilter,
                            (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D,
                            TextureParameterName.TextureWrapS,
                            (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2D,
                            TextureParameterName.TextureWrapT,
                            (int)TextureWrapMode.ClampToEdge);

            // GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.GenerateMipmap, (float)1.0f);

            GL.TexImage2D(TextureTarget.Texture2D, 0,
                          PixelInternalFormat.DepthComponent16,
                          c_texWidth, c_texHeight, 0,
                          PixelFormat.DepthComponent, PixelType.Float, IntPtr.Zero);

            // bind the framebuffer and set it up..
            GL.Ext.BindFramebuffer(FramebufferTarget.Framebuffer, m_frameBufferID);
            GL.Ext.FramebufferTexture(FramebufferTarget.Framebuffer,
                                      FramebufferAttachment.DepthAttachment,
                                      m_textureID, 0);

            // turn off reading and writing to color data
            GL.DrawBuffer(DrawBufferMode.None);
            GL.ReadBuffer(ReadBufferMode.None);
            //GL.Ext.FramebufferTexture(
            //	FramebufferTarget.Framebuffer,
            //    FramebufferAttachment.Depth,0,0);


            assertFramebufferOK();
        }
Ejemplo n.º 2
0
 public void RemoveLight(SSLight light)
 {
     if (!m_lights.Contains(light))
     {
         throw new Exception("Light not found.");
     }
     m_lights.Remove(light);
     if (BaseShader != null)
     {
         BaseShader.Activate();
         BaseShader.SetupShadowMap(m_lights);
         BaseShader.Deactivate();
     }
 }
Ejemplo n.º 3
0
 public void AddLight(SSLight light)
 {
     if (m_lights.Contains(light))
     {
         return;
     }
     m_lights.Add(light);
     if (BaseShader != null)
     {
         BaseShader.Activate();
         BaseShader.SetupShadowMap(m_lights);
         BaseShader.Deactivate();
     }
 }