public static string Optimize(string shaderCode, ShaderType shaderType) { glslopt_shader_type glslType; switch (shaderType) { case ShaderType.FragmentShader: glslType = glslopt_shader_type.kGlslOptShaderFragment; break; case ShaderType.VertexShader: glslType = glslopt_shader_type.kGlslOptShaderVertex; break; default: throw new ArgumentException("Must be pixel or vertex shader"); } //pretend to be version 1 or glsloptimizer complains shaderCode = shaderCode.Replace ("#version 110", ""); IntPtr shader = glslopt_optimize(ctx, glslType, shaderCode, 0); string output; try { if (glslopt_get_status(shader)) { output = glslopt_get_output(shader); } else { string errorLog = glslopt_get_log(shader); throw new Exception(errorLog); } } finally { glslopt_shader_delete(shader); } return output; }
protected TextureBase(TextureTarget target) { // set texture target mTextureTarget = target; // generate texture id GL.GenTextures (1, out mTextureId); }
protected void CompleteDefInfo( GLenum glType, Axiom.Graphics.GpuProgramParameters.GpuConstantDefinition defToUpdate ) { //Decode unifrom size and type //Note GLSL ES never packs rows into float4's (from an API perspective anyway) //therefore all values are tight in the buffer switch ( glType ) { case GLenum.Float: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Float1; break; case GLenum.FloatVec2: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Float2; break; case GLenum.FloatVec3: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Float3; break; case GLenum.FloatVec4: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Float4; break; case GLenum.Sampler2D: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Sampler2D; break; case GLenum.SamplerCube: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.SamplerCube; break; case GLenum.Int: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Int1; break; case GLenum.IntVec2: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Int2; break; case GLenum.IntVec3: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Int3; break; case GLenum.IntVec4: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Int4; break; case GLenum.FloatMat2: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_2X2; break; case GLenum.FloatMat3: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_3X3; break; case GLenum.FloatMat4: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Unknown; break; default: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Unknown; break; } //GL doesn't pad defToUpdate.ElementSize = Axiom.Graphics.GpuProgramParameters.GpuConstantDefinition.GetElementSize( defToUpdate.ConstantType, false ); }
public override FramebufferErrorCode CheckStatus(FramebufferTarget target) { return GL.Ext.CheckFramebufferStatus(target); }
public virtual FramebufferErrorCode CheckStatus(FramebufferTarget target) { return (FramebufferErrorCode)GL.CheckFramebufferStatus(target); }
public virtual void Texture2D(FramebufferTarget target, FramebufferAttachment attachment, TextureTarget textureTarget, int texture, int level) { GL.FramebufferTexture2D(target, attachment, textureTarget, texture, level); GraphicsExtensions.CheckGLError(); }
public override void GetBestDepthStencil( GLenum internalColorFormat, ref OpenTK.Graphics.ES20.All depthFormat, ref OpenTK.Graphics.ES20.All stencilFormat ) { FormatProperties prop = this.props[ (int) internalColorFormat ]; int bestmode = 0; int bestscore = -1; for ( int mode = 0; mode < prop.Modes.Count; mode++ ) { int desirability = 0; /// Find most desirable mode /// desirability == 0 if no depth, no stencil /// desirability == 1000...2000 if no depth, stencil /// desirability == 2000...3000 if depth, no stencil /// desirability == 3000+ if depth and stencil /// beyond this, the total numer of bits (stencil+depth) is maximised if ( prop.Modes[ mode ].Stencil > 0 ) { desirability += 1000; } if ( prop.Modes[ mode ].Depth > 0 ) { desirability += 2000; } if ( depthBits[ prop.Modes[ mode ].Depth ] == 24 ) //Prefer 24 bit for now { desirability += 500; } if ( depthFormats[ prop.Modes[ mode ].Depth ] == GLenum.Depth24Stencil8Oes ) //Prefer 24/8 packed { desirability += 5000; } desirability += stencilBits[ prop.Modes[ mode ].Stencil ] + depthBits[ prop.Modes[ mode ].Depth ]; if ( desirability > bestscore ) { bestscore = desirability; bestmode = mode; } } depthFormat = depthFormats[ prop.Modes[ bestmode ].Depth ]; stencilFormat = stencilFormats[ prop.Modes[ bestmode ].Stencil ]; }
///<summary> /// Populate a list of uniforms based on a program object ///</summary> ///<param name="programObject"> Handle to the program object to query </param> ///<param name="vertexConstantDefs"> vertexConstantDefs Definition of the constants extracted from the vertex program, used to match up physical buffer indexes with program uniforms. May be null if there is no vertex program. </param> ///<param name="fragmentConstantDefs"> fragmentConstantDefs Definition of the constants extracted from the fragment program, used to match up physical buffer indexes with program uniforms. May be null if there is no fragment program. </param> ///<param name="list"> The list to populate (will not be cleared before adding, clear it yourself before calling this if that's what you want). </param> public void ExtractUniforms(int programObject, Graphics.GpuProgramParameters.GpuConstantDefinitionMap vertexConstantDefs, Graphics.GpuProgramParameters.GpuConstantDefinitionMap fragmentConstantDefs, List <GLUniformReference> list) { //Scan through the active uniforms and add them to the reference list int uniformCount = 0; int maxLength = 0; string uniformName = string.Empty; GL.GetProgram(programObject, GLenum.ActiveUniformMaxLength, ref maxLength); GLES2Config.GlCheckError(this); //If the max length of active uniforms is 0, then there are 0 active. //There won't be any to extract so we can return if (maxLength == 0) { return; } GLUniformReference newGLUniformReference; //Get the number of active uniforms GL.GetProgram(programObject, GLenum.ActiveUniforms, ref uniformCount); GLES2Config.GlCheckError(this); //Loop over each of the active uniforms, and add them to the reference container //only do this for user defined uniforms, ignore built in gl state uniforms for (int index = 0; index < uniformCount; index++) { int arraySize = 0; GLenum glType = GLenum.None; int tmp = 0; GL.GetActiveUniform(programObject, index, maxLength, ref tmp, ref arraySize, ref glType, uniformName); GLES2Config.GlCheckError(this); //don't add built in uniforms newGLUniformReference = new GLUniformReference(); newGLUniformReference.Location = GL.GetUniformLocation(programObject, uniformName); GLES2Config.GlCheckError(this); if (newGLUniformReference.Location >= 0) { //User defined uniform found, add it to the reference list string paramName = uniformName; //If the uniform name has a '[' in it then its an array element uniform. int arrayStart = -1; for (int i = 0; i < paramName.Length; i++) { if (paramName[i] == '[') { arrayStart = i; break; } } if (arrayStart != -1) { //If not the first array element then skip it and continue to the next uniform string sub = paramName.Substring(arrayStart, paramName.Length - 1); if (sub == "[0]") { continue; } paramName = paramName.Substring(0, arrayStart); } //Find out which params object this comes from bool foundSource = this.CompleteParamSource(paramName, vertexConstantDefs, fragmentConstantDefs, newGLUniformReference); //Only add this param if we found the source if (foundSource) { list.Add(newGLUniformReference); } } } if (uniformName != string.Empty) { uniformName = string.Empty; } }
public void BindRenderbuffer (All target, int renderbuffer) { GLES20.BindRenderbuffer ((RenderbufferTarget)target, renderbuffer); }
public void BindFramebuffer (All target, int framebuffer) { GLES11.Oes.BindFramebuffer ((All11) target, framebuffer); }
public virtual FramebufferErrorCode CheckStatus(FramebufferTarget target) { return((FramebufferErrorCode)GL.CheckFramebufferStatus(target)); }
public virtual void Renderbuffer(FramebufferTarget target, FramebufferAttachment attachment, RenderbufferTarget renderbufferTarget, int renderbuffer) { GL.FramebufferRenderbuffer(target, attachment, renderbufferTarget, renderbuffer); GraphicsExtensions.CheckGLError(); }
public RBFormat( GLenum format, int width, int height, int samples ) { this.Format = format; this.Width = width; this.Height = height; this.Samples = samples; }
public virtual void Bind(FramebufferTarget target, int id) { GL.BindFramebuffer(target, id); GraphicsExtensions.CheckGLError(); }
/// <summary> /// Tries a certain packed depth/stencil format, and return the status. /// </summary> /// <param name="packedFormat"> </param> /// <returns> True if this combo is supported, otherwise false </returns> private bool TryPackedFormat( GLenum packedFormat ) { int packedRB = 0; GLenum status = GLenum.None; //Generate renderbuffer GL.GenRenderbuffers( 1, ref packedRB ); //Bind it to FBO GL.BindRenderbuffer( GLenum.Renderbuffer, packedRB ); //Allocate storage for buffer GL.RenderbufferStorage( GLenum.Renderbuffer, packedFormat, PROBE_SIZE, PROBE_SIZE ); //Attach depth GL.FramebufferRenderbuffer( GLenum.Framebuffer, GLenum.DepthAttachment, GLenum.Renderbuffer, packedRB ); //Attach stencil GL.FramebufferRenderbuffer( GLenum.Framebuffer, GLenum.StencilAttachment, GLenum.Renderbuffer, packedRB ); status = GL.CheckFramebufferStatus( GLenum.Framebuffer ); //Detach and destroy GL.FramebufferRenderbuffer( GLenum.Framebuffer, GLenum.DepthAttachment, GLenum.Renderbuffer, 0 ); GL.FramebufferRenderbuffer( GLenum.Framebuffer, GLenum.StencilAttachment, GLenum.Renderbuffer, 0 ); GL.DeleteRenderbuffers( 1, ref packedRB ); return status == GLenum.FramebufferComplete; }
/// <summary> /// Try a ceratin FBO format, and return the status. Also sets depthRB and stencilRB /// </summary> /// <param name="depthFormat"> </param> /// <param name="stencilFormat"> </param> /// <returns> true if this combo is supported, otherwise false </returns> private bool TryFormat( GLenum depthFormat, GLenum stencilFormat ) { int depthRB = 0, stencilRB = 0; GLenum status = GLenum.None; if ( depthFormat != GLenum.None ) { //Generate depth renderbuffer GL.GenRenderbuffers( 1, ref depthRB ); //Bind it to FBO GL.BindRenderbuffer( GLenum.Renderbuffer, depthRB ); //Allocate storage for depth buffer GL.RenderbufferStorage( GLenum.Renderbuffer, depthFormat, PROBE_SIZE, PROBE_SIZE ); //Attach depth GL.FramebufferRenderbuffer( GLenum.Framebuffer, GLenum.DepthAttachment, GLenum.Renderbuffer, depthRB ); } if ( stencilFormat != GLenum.None ) { //Generate stencil renderbuffer GL.GenRenderbuffers( 1, ref stencilRB ); //Bind it to FBO GL.BindRenderbuffer( GLenum.Renderbuffer, stencilRB ); //Allocate storage for stencil buffer GL.RenderbufferStorage( GLenum.Renderbuffer, stencilFormat, PROBE_SIZE, PROBE_SIZE ); //Attach stencil GL.FramebufferRenderbuffer( GLenum.Framebuffer, GLenum.StencilAttachment, GLenum.Renderbuffer, stencilRB ); } status = GL.CheckFramebufferStatus( GLenum.Framebuffer ); //If status is negative, clean up //Detach and destroy GL.FramebufferRenderbuffer( GLenum.Framebuffer, GLenum.DepthAttachment, GLenum.Renderbuffer, 0 ); GL.FramebufferRenderbuffer( GLenum.Framebuffer, GLenum.StencilAttachment, GLenum.Renderbuffer, 0 ); if ( depthRB > 0 ) { GL.DeleteRenderbuffers( 1, ref depthRB ); } if ( stencilRB > 0 ) { GL.DeleteRenderbuffers( 1, ref stencilRB ); } return status == GLenum.FramebufferComplete; }
public GLES2SurfaceDesc RequestRenderBuffer( GLenum format, int width, int height, int fsaa ) { var retVal = new GLES2SurfaceDesc(); retVal.buffer = null; if ( format != GLenum.None ) { var key = new RBFormat( format, width, height, fsaa ); if ( this.renderBufferMap.ContainsKey( key ) ) { retVal.buffer = this.renderBufferMap[ key ].buffer; retVal.zoffset = 0; retVal.numSamples = fsaa; } else { //New one var rb = new GLES2RenderBuffer( format, width, height, fsaa ); this.renderBufferMap.Add( key, new RBRef( rb ) ); retVal.buffer = rb; retVal.zoffset = 0; retVal.numSamples = fsaa; } } return retVal; }
public void FramebufferRenderbuffer ( All target, All attachment, All renderbuffertarget, int renderbuffer) { GLES11.Oes.FramebufferRenderbuffer ( (All11) target, (All11) attachment, (All11) renderbuffertarget, renderbuffer); }
internal void Activate(TextureTarget target, bool useMipmaps = false) { switch (Filter) { case TextureFilter.Point: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapNearest : TextureMinFilter.Nearest)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GraphicsExtensions.CheckGLError(); break; case TextureFilter.Linear: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapLinear : TextureMinFilter.Linear)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); break; case TextureFilter.Anisotropic: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, MathHelper.Clamp(this.MaxAnisotropy, 1.0f, SamplerState.MaxTextureMaxAnisotropy)); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapLinear : TextureMinFilter.Linear)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); break; case TextureFilter.PointMipLinear: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapLinear : TextureMinFilter.Nearest)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GraphicsExtensions.CheckGLError(); break; case TextureFilter.LinearMipPoint: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapNearest : TextureMinFilter.Linear)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); break; case TextureFilter.MinLinearMagPointMipLinear: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapLinear : TextureMinFilter.Linear)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GraphicsExtensions.CheckGLError(); break; case TextureFilter.MinLinearMagPointMipPoint: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapNearest: TextureMinFilter.Linear)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GraphicsExtensions.CheckGLError(); break; case TextureFilter.MinPointMagLinearMipLinear: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapLinear: TextureMinFilter.Nearest)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); break; case TextureFilter.MinPointMagLinearMipPoint: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapNearest: TextureMinFilter.Nearest)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); break; default: throw new NotSupportedException(); } // Set up texture addressing. GL.TexParameter(target, TextureParameterName.TextureWrapS, (int)GetWrapMode(AddressU)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureWrapT, (int)GetWrapMode(AddressV)); GraphicsExtensions.CheckGLError(); #if !GLES // LOD bias is not supported by glTexParameter in OpenGL ES 2.0 GL.TexParameter(target, TextureParameterName.TextureLodBias, MipMapLevelOfDetailBias); GraphicsExtensions.CheckGLError(); #endif if (GraphicsCapabilities.SupportsTextureMaxLevel) { if (this.MaxMipLevel > 0) { GL.TexParameter(TextureTarget.Texture2D, TextureParameterNameTextureMaxLevel, this.MaxMipLevel); } else { GL.TexParameter(TextureTarget.Texture2D, TextureParameterNameTextureMaxLevel, 1000); } } }
public All CheckFramebufferStatus (All target) { return (All)GLES20.CheckFramebufferStatus ((FramebufferTarget)target); }
/// <summary> /// Detect which internal formats are allowed as RTT Also detect what combinations of stencil and depth are allowed with this interal format. /// </summary> private void DetectFBOFormats() { //Try all formats, and report which ones work as target int fb = 0, tid = 0; GLenum target = GLenum.Texture2D; for (int x = 0; x < (int)PixelFormat.Count; x++) { this.props[x].Valid = false; //Fetch gl format token var fmt = GLES2PixelUtil.GetGLInternalFormat((PixelFormat)x); if ((fmt == GLenum.None) && (x != 0)) { continue; } //No test for compressed formats if (PixelUtil.IsCompressed((PixelFormat)x)) { continue; } //Create and attach framebuffer GL.GenFramebuffers(1, ref fb); GL.BindFramebuffer(GLenum.Framebuffer, fb); if (fmt != GLenum.None) { //Create and attach texture GL.GenTextures(1, ref tid); GL.BindTexture(target, tid); //Set some default parameters GL.TexParameter(target, GLenum.TextureMinFilter, (int)GLenum.Nearest); GL.TexParameter(target, GLenum.TextureMagFilter, (int)GLenum.Nearest); GL.TexParameter(target, GLenum.TextureWrapS, (int)GLenum.ClampToEdge); GL.TexParameter(target, GLenum.TextureWrapT, (int)GLenum.ClampToEdge); GL.TexImage2D(target, 0, (int)fmt, PROBE_SIZE, PROBE_SIZE, 0, fmt, GLES2PixelUtil.GetGLOriginDataType((PixelFormat)x), IntPtr.Zero); GL.FramebufferTexture2D(GLenum.Framebuffer, GLenum.ColorAttachment0, target, tid, 0); } //Check status GLenum status = GL.CheckFramebufferStatus(GLenum.Framebuffer); // Ignore status in case of fmt==GL_NONE, because no implementation will accept // a buffer without *any* attachment. Buffers with only stencil and depth attachment // might still be supported, so we must continue probing. if (fmt == GLenum.None || status == GLenum.FramebufferComplete) { this.props[x].Valid = true; var sb = new StringBuilder(); sb.Append("FBO " + PixelUtil.GetFormatName((PixelFormat)x) + " depth/stencil support: "); //For each depth/stencil formats for (int depth = 0; depth < DepthFormatCount; depth++) { if (depthFormats[depth] != GLenum.Depth24Stencil8Oes) { //General depth/stencil combination for (int stencil = 0; stencil < StencilFormatCount; stencil++) { if (this.TryFormat(depthFormats[depth], stencilFormats[stencil])) { //Add mode to allowed modes sb.Append("D" + depthBits[depth] + "S" + stencilBits[stencil] + " "); var mode = new FormatProperties.Mode(); mode.Depth = depth; mode.Stencil = stencil; this.props[x].Modes.Add(mode); } } } else { //Packed depth/stencil format if (this.TryPackedFormat(depthFormats[depth])) { //Add mode to allowed modes sb.Append("Packed-D" + depthBits[depth] + "S" + 8 + " "); var mode = new FormatProperties.Mode(); mode.Depth = depth; mode.Stencil = 0; //unuse this.props[x].Modes.Add(mode); } } } Core.LogManager.Instance.Write(sb.ToString()); } //Delte texture and framebuffer GL.BindFramebuffer(GLenum.Framebuffer, 0); GL.DeleteFramebuffers(1, ref fb); if (fmt != GLenum.None) { GL.DeleteTextures(1, ref tid); } } // Clear any errors GLES2Config.GlClearError(); string fmtstring = string.Empty; for (int x = 0; x < (int)PixelFormat.Count; x++) { if (this.props[x].Valid) { fmtstring += PixelUtil.GetFormatName((PixelFormat)x) + " "; } Core.LogManager.Instance.Write("[GLES2] : Valid FBO targets " + fmtstring); } }
public void GetInteger (All name, ref int value) { GLES20.GetInteger ((GetPName)name, out value); }
public ESImage(Bitmap image, GL20.All filter) { // By default set the scale to 1.0f texture = new ESTexture2D(image, filter); Initialize(1.0f); }
protected void CompleteDefInfo(GLenum glType, Axiom.Graphics.GpuProgramParameters.GpuConstantDefinition defToUpdate) { //Decode unifrom size and type //Note GLSL ES never packs rows into float4's (from an API perspective anyway) //therefore all values are tight in the buffer switch (glType) { case GLenum.Float: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Float1; break; case GLenum.FloatVec2: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Float2; break; case GLenum.FloatVec3: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Float3; break; case GLenum.FloatVec4: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Float4; break; case GLenum.Sampler2D: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Sampler2D; break; case GLenum.SamplerCube: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.SamplerCube; break; case GLenum.Int: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Int1; break; case GLenum.IntVec2: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Int2; break; case GLenum.IntVec3: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Int3; break; case GLenum.IntVec4: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Int4; break; case GLenum.FloatMat2: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_2X2; break; case GLenum.FloatMat3: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_3X3; break; case GLenum.FloatMat4: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Unknown; break; default: defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Unknown; break; } //GL doesn't pad defToUpdate.ElementSize = Axiom.Graphics.GpuProgramParameters.GpuConstantDefinition.GetElementSize(defToUpdate.ConstantType, false); }
internal TextureCube(GraphicsDevice graphicsDevice, int size, bool mipMap, SurfaceFormat format, bool renderTarget) { if (graphicsDevice == null) { throw new ArgumentNullException("graphicsDevice"); } this.GraphicsDevice = graphicsDevice; this.size = size; this.format = format; this.levelCount = mipMap ? CalculateMipLevels(size) : 1; #if DIRECTX var description = new Texture2DDescription { Width = size, Height = size, MipLevels = levelCount, ArraySize = 6, // A texture cube is a 2D texture array with 6 textures. Format = SharpDXHelper.ToFormat(format), BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.TextureCube }; if (renderTarget) { description.BindFlags |= BindFlags.RenderTarget; if (mipMap) { description.OptionFlags |= ResourceOptionFlags.GenerateMipMaps; } } _texture = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, description); #elif PSM //TODO #else this.glTarget = TextureTarget.TextureCubeMap; #if IOS || ANDROID GL.GenTextures(1, ref this.glTexture); #else GL.GenTextures(1, out this.glTexture); #endif GraphicsExtensions.CheckGLError(); GL.BindTexture(TextureTarget.TextureCubeMap, this.glTexture); GraphicsExtensions.CheckGLError(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, mipMap ? (int)TextureMinFilter.LinearMipmapLinear : (int)TextureMinFilter.Linear); GraphicsExtensions.CheckGLError(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); GraphicsExtensions.CheckGLError(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); GraphicsExtensions.CheckGLError(); format.GetGLFormat(out glInternalFormat, out glFormat, out glType); for (int i = 0; i < 6; i++) { TextureTarget target = GetGLCubeFace((CubeMapFace)i); if (glFormat == (PixelFormat)All.CompressedTextureFormats) { throw new NotImplementedException(); } else { #if IOS || ANDROID GL.TexImage2D(target, 0, (int)glInternalFormat, size, size, 0, glFormat, glType, IntPtr.Zero); #else GL.TexImage2D(target, 0, glInternalFormat, size, size, 0, glFormat, glType, IntPtr.Zero); #endif GraphicsExtensions.CheckGLError(); } } if (mipMap) { #if IOS || ANDROID GL.GenerateMipmap(TextureTarget.TextureCubeMap); #else GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.GenerateMipmap, (int)All.True); #endif GraphicsExtensions.CheckGLError(); } #endif }
public override void Bind(FramebufferTarget target, int id) { GL.Ext.BindFramebuffer(target, id); GraphicsExtensions.CheckGLError(); }
public override FramebufferErrorCode CheckStatus(FramebufferTarget target) { return(GL.Ext.CheckFramebufferStatus(target)); }
internal void Activate(TextureTarget target, bool useMipmaps = false) { switch (Filter) { case TextureFilter.Point: if (GraphicsCapabilities.TextureFilterAnisotric) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapNearest : TextureMinFilter.Nearest)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GraphicsExtensions.CheckGLError(); break; case TextureFilter.Linear: if (GraphicsCapabilities.TextureFilterAnisotric) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapLinear : TextureMinFilter.Linear)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); break; case TextureFilter.Anisotropic: if (GraphicsCapabilities.TextureFilterAnisotric) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, MathHelper.Clamp(this.MaxAnisotropy, 1.0f, SamplerState.MaxTextureMaxAnisotropy)); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapLinear : TextureMinFilter.Linear)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); break; case TextureFilter.PointMipLinear: if (GraphicsCapabilities.TextureFilterAnisotric) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapLinear : TextureMinFilter.Nearest)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GraphicsExtensions.CheckGLError(); break; case TextureFilter.LinearMipPoint: if (GraphicsCapabilities.TextureFilterAnisotric) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapNearest : TextureMinFilter.Linear)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); break; case TextureFilter.MinLinearMagPointMipLinear: if (GraphicsCapabilities.TextureFilterAnisotric) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapLinear : TextureMinFilter.Linear)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GraphicsExtensions.CheckGLError(); break; case TextureFilter.MinLinearMagPointMipPoint: if (GraphicsCapabilities.TextureFilterAnisotric) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapNearest: TextureMinFilter.Linear)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GraphicsExtensions.CheckGLError(); break; case TextureFilter.MinPointMagLinearMipLinear: if (GraphicsCapabilities.TextureFilterAnisotric) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapLinear: TextureMinFilter.Nearest)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); break; case TextureFilter.MinPointMagLinearMipPoint: if (GraphicsCapabilities.TextureFilterAnisotric) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapNearest: TextureMinFilter.Nearest)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); break; default: throw new NotImplementedException(); } // Set up texture addressing. GL.TexParameter(target, TextureParameterName.TextureWrapS, (int)GetWrapMode(AddressU)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureWrapT, (int)GetWrapMode(AddressV)); GraphicsExtensions.CheckGLError(); }
public ESImage(Bitmap image, float imageScale, GL20.All filter) { texture = new ESTexture2D(image, filter); Initialize(imageScale); }
internal static void GetGLFormat(this SurfaceFormat format, out PixelInternalFormat glInternalFormat, out PixelFormat glFormat, out PixelType glType) { glInternalFormat = PixelInternalFormat.Rgba; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedByte; switch (format) { case SurfaceFormat.Color: glInternalFormat = PixelInternalFormat.Rgba; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedByte; break; case SurfaceFormat.Bgr565: glInternalFormat = PixelInternalFormat.Rgb; glFormat = PixelFormat.Rgb; glType = PixelType.UnsignedShort565; break; case SurfaceFormat.Bgra4444: #if IOS || ANDROID glInternalFormat = PixelInternalFormat.Rgba; #else glInternalFormat = PixelInternalFormat.Rgba4; #endif glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedShort4444; break; case SurfaceFormat.Bgra5551: glInternalFormat = PixelInternalFormat.Rgba; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedShort5551; break; case SurfaceFormat.Alpha8: glInternalFormat = PixelInternalFormat.Luminance; glFormat = PixelFormat.Luminance; glType = PixelType.UnsignedByte; break; #if !IOS && !ANDROID && !ANGLE case SurfaceFormat.Dxt1: glInternalFormat = PixelInternalFormat.CompressedRgbS3tcDxt1Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt1a: glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt3: glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt5: glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Single: glInternalFormat = PixelInternalFormat.R32f; glFormat = PixelFormat.Red; glType = PixelType.Float; break; case SurfaceFormat.HalfVector2: glInternalFormat = PixelInternalFormat.Rg16f; glFormat = PixelFormat.Rg; glType = PixelType.HalfFloat; break; // HdrBlendable implemented as HalfVector4 (see http://blogs.msdn.com/b/shawnhar/archive/2010/07/09/surfaceformat-hdrblendable.aspx) case SurfaceFormat.HdrBlendable: case SurfaceFormat.HalfVector4: glInternalFormat = PixelInternalFormat.Rgba16f; glFormat = PixelFormat.Rgba; glType = PixelType.HalfFloat; break; case SurfaceFormat.HalfSingle: glInternalFormat = PixelInternalFormat.R16f; glFormat = PixelFormat.Red; glType = PixelType.HalfFloat; break; case SurfaceFormat.Vector2: glInternalFormat = PixelInternalFormat.Rg32f; glFormat = PixelFormat.Rg; glType = PixelType.Float; break; case SurfaceFormat.Vector4: glInternalFormat = PixelInternalFormat.Rgba32f; glFormat = PixelFormat.Rgba; glType = PixelType.Float; break; case SurfaceFormat.NormalizedByte2: glInternalFormat = PixelInternalFormat.Rg8i; glFormat = PixelFormat.Rg; glType = PixelType.Byte; break; case SurfaceFormat.NormalizedByte4: glInternalFormat = PixelInternalFormat.Rgba8i; glFormat = PixelFormat.Rgba; glType = PixelType.Byte; break; case SurfaceFormat.Rg32: glInternalFormat = PixelInternalFormat.Rg16ui; glFormat = PixelFormat.Rg; glType = PixelType.UnsignedShort; break; case SurfaceFormat.Rgba64: glInternalFormat = PixelInternalFormat.Rgba16ui; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedShort; break; case SurfaceFormat.Rgba1010102: glInternalFormat = PixelInternalFormat.Rgb10A2ui; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedInt1010102; break; #endif #if ANDROID case SurfaceFormat.Dxt1: // 0x83F0 is the RGB version, 0x83F1 is the RGBA version (1-bit alpha) // XNA uses the RGB version. glInternalFormat = (PixelInternalFormat)0x83F0; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt1a: // 0x83F0 is the RGB version, 0x83F1 is the RGBA version (1-bit alpha) glInternalFormat = (PixelInternalFormat)0x83F1; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt3: glInternalFormat = (PixelInternalFormat)0x83F2; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt5: glInternalFormat = (PixelInternalFormat)0x83F3; glFormat = (PixelFormat)All.CompressedTextureFormats; break; #endif #if IOS || ANDROID case SurfaceFormat.RgbEtc1: glInternalFormat = (PixelInternalFormat)0x8D64; // GL_ETC1_RGB8_OES glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbPvrtc2Bpp: glInternalFormat = PixelInternalFormat.CompressedRgbPvrtc2Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbPvrtc4Bpp: glInternalFormat = PixelInternalFormat.CompressedRgbPvrtc4Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbaPvrtc2Bpp: glInternalFormat = PixelInternalFormat.CompressedRgbaPvrtc2Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbaPvrtc4Bpp: glInternalFormat = PixelInternalFormat.CompressedRgbaPvrtc4Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; #endif default: throw new NotSupportedException(); } }
public void SetData <T>(CubeMapFace face, int level, Rectangle?rect, T[] data, int startIndex, int elementCount) where T : struct { if (data == null) { throw new ArgumentNullException("data"); } #if !PORTABLE var elementSizeInByte = Marshal.SizeOf(typeof(T)); var dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned); // Use try..finally to make sure dataHandle is freed in case of an error try { var dataPtr = (IntPtr)(dataHandle.AddrOfPinnedObject().ToInt64() + startIndex * elementSizeInByte); int xOffset, yOffset, width, height; if (rect.HasValue) { xOffset = rect.Value.X; yOffset = rect.Value.Y; width = rect.Value.Width; height = rect.Value.Height; } else { xOffset = 0; yOffset = 0; width = Math.Max(1, this.size >> level); height = Math.Max(1, this.size >> level); // For DXT textures the width and height of each level is a multiple of 4. // OpenGL only: The last two mip levels require the width and height to be // passed as 2x2 and 1x1, but there needs to be enough data passed to occupy // a 4x4 block. // Ref: http://www.mentby.com/Group/mac-opengl/issue-with-dxt-mipmapped-textures.html if (_format == SurfaceFormat.Dxt1 || _format == SurfaceFormat.Dxt1a || _format == SurfaceFormat.Dxt3 || _format == SurfaceFormat.Dxt5) { #if DIRECTX width = (width + 3) & ~3; height = (height + 3) & ~3; #else if (width > 4) { width = (width + 3) & ~3; } if (height > 4) { height = (height + 3) & ~3; } #endif } } #if DIRECTX var box = new DataBox(dataPtr, GetPitch(width), 0); int subresourceIndex = (int)face * _levelCount + level; var region = new ResourceRegion { Top = yOffset, Front = 0, Back = 1, Bottom = yOffset + height, Left = xOffset, Right = xOffset + width }; var d3dContext = GraphicsDevice._d3dContext; lock (d3dContext) d3dContext.UpdateSubresource(box, GetTexture(), subresourceIndex, region); #elif PSM //TODO #else GL.BindTexture(TextureTarget.TextureCubeMap, this.glTexture); GraphicsExtensions.CheckGLError(); TextureTarget target = GetGLCubeFace(face); if (glFormat == (PixelFormat)All.CompressedTextureFormats) { throw new NotImplementedException(); } else { GL.TexSubImage2D(target, level, xOffset, yOffset, width, height, glFormat, glType, dataPtr); GraphicsExtensions.CheckGLError(); } #endif } finally { dataHandle.Free(); } #endif }
internal TextureCube(GraphicsDevice graphicsDevice, int size, bool mipMap, SurfaceFormat format, bool renderTarget) { if (graphicsDevice == null) { throw new ArgumentNullException("graphicsDevice"); } this.GraphicsDevice = graphicsDevice; this.size = size; this._format = format; this._levelCount = mipMap ? CalculateMipLevels(size) : 1; #if DIRECTX _renderTarget = renderTarget; _mipMap = mipMap; // Create texture GetTexture(); #elif PSM //TODO #elif !PORTABLE this.glTarget = TextureTarget.TextureCubeMap; #if IOS || ANDROID GL.GenTextures(1, ref this.glTexture); #else GL.GenTextures(1, out this.glTexture); #endif GraphicsExtensions.CheckGLError(); GL.BindTexture(TextureTarget.TextureCubeMap, this.glTexture); GraphicsExtensions.CheckGLError(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, mipMap ? (int)TextureMinFilter.LinearMipmapLinear : (int)TextureMinFilter.Linear); GraphicsExtensions.CheckGLError(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); GraphicsExtensions.CheckGLError(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); GraphicsExtensions.CheckGLError(); format.GetGLFormat(out glInternalFormat, out glFormat, out glType); for (int i = 0; i < 6; i++) { TextureTarget target = GetGLCubeFace((CubeMapFace)i); if (glFormat == (PixelFormat)All.CompressedTextureFormats) { throw new NotImplementedException(); } else { #if IOS || ANDROID GL.TexImage2D(target, 0, (int)glInternalFormat, size, size, 0, glFormat, glType, IntPtr.Zero); #else GL.TexImage2D(target, 0, glInternalFormat, size, size, 0, glFormat, glType, IntPtr.Zero); #endif GraphicsExtensions.CheckGLError(); } } if (mipMap) { #if IOS || ANDROID GL.GenerateMipmap(TextureTarget.TextureCubeMap); #else GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.GenerateMipmap, (int)All.True); #endif GraphicsExtensions.CheckGLError(); } #endif }
public void BindRenderbuffer (All target, int renderbuffer) { GLES11.Oes.BindRenderbuffer ((All11) target, renderbuffer); }
internal void Activate(TextureTarget target, bool useMipmaps = false) { switch(Filter) { case TextureFilter.Point: GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapNearest : TextureMinFilter.Nearest)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GraphicsExtensions.CheckGLError(); break; case TextureFilter.Linear: GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapLinear : TextureMinFilter.Linear)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); break; case TextureFilter.Anisotropic: // TODO: Requires EXT_texture_filter_anisotropic. Use linear filtering for now. GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapLinear : TextureMinFilter.Linear)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); break; case TextureFilter.PointMipLinear: GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapNearest : TextureMinFilter.Nearest)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GraphicsExtensions.CheckGLError(); break; default: throw new NotImplementedException(); } // Set up texture addressing. GL.TexParameter(target, TextureParameterName.TextureWrapS, (int)GetWrapMode(AddressU)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureWrapT, (int)GetWrapMode(AddressV)); GraphicsExtensions.CheckGLError(); }
public void GetInteger (All name, ref int value) { GLES11.GetInteger ((All11) name, out value); }
public void InitWithDataGL20(IntPtr data, SurfaceFormat pixelFormat, int width, int height, Size size, GL20.All filter) { openGLVersion = GLContextVersion.Gles2_0; GL20.GL.GenTextures(1, ref _name); GL20.GL.BindTexture(GL20.All.Texture2D, _name); GL20.GL.TexParameter(GL20.All.Texture2D, GL20.All.TextureMinFilter, (int)filter); GL20.GL.TexParameter(GL20.All.Texture2D, GL20.All.TextureMagFilter, (int)filter); GL20.GL.TexParameter(GL20.All.Texture2D, GL20.All.TextureWrapS, (int)GL20.All.ClampToEdge); GL20.GL.TexParameter(GL20.All.Texture2D, GL20.All.TextureWrapT, (int)GL20.All.ClampToEdge); int sz = 0; switch (pixelFormat) { case SurfaceFormat.Color /*kTexture2DPixelFormat_RGBA8888*/: case SurfaceFormat.Dxt1: case SurfaceFormat.Dxt3: sz = 4; GL20.GL.TexImage2D(GL20.All.Texture2D, 0, (int)GL20.All.Rgba, (int)width, (int)height, 0, GL20.All.Rgba, GL20.All.UnsignedByte, data); break; case SurfaceFormat.Bgra4444 /*kTexture2DPixelFormat_RGBA4444*/: sz = 2; GL20.GL.TexImage2D(GL20.All.Texture2D, 0, (int)GL20.All.Rgba, (int)width, (int)height, 0, GL20.All.Rgba, GL20.All.UnsignedShort4444, data); break; case SurfaceFormat.Bgra5551 /*kTexture2DPixelFormat_RGB5A1*/: sz = 2; GL20.GL.TexImage2D(GL20.All.Texture2D, 0, (int)GL20.All.Rgba, (int)width, (int)height, 0, GL20.All.Rgba, GL20.All.UnsignedShort5551, data); break; case SurfaceFormat.Alpha8 /*kTexture2DPixelFormat_A8*/: sz = 1; GL20.GL.TexImage2D(GL20.All.Texture2D, 0, (int)GL20.All.Alpha, (int)width, (int)height, 0, GL20.All.Alpha, GL20.All.UnsignedByte, data); break; default: throw new NotSupportedException("Texture format"); } _size = size; _width = width; _height = height; _format = pixelFormat; _maxS = size.Width / (float)width; _maxT = size.Height / (float)height; _pixelData = data; }
public void BindFramebuffer (All target, int framebuffer) { GLES20.BindFramebuffer((FramebufferTarget)target, framebuffer); }
public ESTexture2D(IntPtr data, SurfaceFormat pixelFormat, int width, int height, Size size, GL20.All filter) { InitWithDataGL20(data, pixelFormat, width, height, size, filter); }
public void FramebufferRenderbuffer ( All target, All attachment, All renderbuffertarget, int renderbuffer) { GLES20.FramebufferRenderbuffer ((FramebufferTarget)target, (FramebufferSlot)attachment, (RenderbufferTarget)renderbuffertarget, renderbuffer); }
public ESTexture2D(Bitmap image, GL20.All filter) { InitWithBitmapGL20(image, filter); }
public All CheckFramebufferStatus (All target) { return (All) GLES11.Oes.CheckFramebufferStatus ((All11) target); }
internal static void GetGLFormat(this SurfaceFormat format, out PixelInternalFormat glInternalFormat, out PixelFormat glFormat, out PixelType glType) { glInternalFormat = PixelInternalFormat.Rgba; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedByte; switch (format) { case SurfaceFormat.Color: glInternalFormat = PixelInternalFormat.Rgba; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedByte; break; case SurfaceFormat.Bgr565: glInternalFormat = PixelInternalFormat.Rgb; glFormat = PixelFormat.Rgb; glType = PixelType.UnsignedShort565; break; case SurfaceFormat.Bgra4444: #if IOS || ANDROID glInternalFormat = PixelInternalFormat.Rgba; #else glInternalFormat = PixelInternalFormat.Rgba4; #endif glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedShort4444; break; case SurfaceFormat.Bgra5551: glInternalFormat = PixelInternalFormat.Rgba; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedShort5551; break; case SurfaceFormat.Alpha8: glInternalFormat = PixelInternalFormat.Luminance; glFormat = PixelFormat.Luminance; glType = PixelType.UnsignedByte; break; #if !IOS && !ANDROID case SurfaceFormat.Dxt1: glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt3: glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt5: glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Single: glInternalFormat = PixelInternalFormat.R32f; glFormat = PixelFormat.Red; glType = PixelType.Float; break; #endif #if IOS || ANDROID case SurfaceFormat.RgbPvrtc2Bpp: glInternalFormat = PixelInternalFormat.CompressedRgbPvrtc2Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbPvrtc4Bpp: glInternalFormat = PixelInternalFormat.CompressedRgbPvrtc4Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbaPvrtc2Bpp: glInternalFormat = PixelInternalFormat.CompressedRgbaPvrtc2Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbaPvrtc4Bpp: glInternalFormat = PixelInternalFormat.CompressedRgbaPvrtc4Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; #endif default: throw new NotSupportedException(); } }
internal static void GetGLFormat (this SurfaceFormat format, out PixelInternalFormat glInternalFormat, out PixelFormat glFormat, out PixelType glType) { glInternalFormat = PixelInternalFormat.Rgba; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedByte; switch (format) { case SurfaceFormat.Color: glInternalFormat = PixelInternalFormat.Rgba; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedByte; break; case SurfaceFormat.Bgr565: glInternalFormat = PixelInternalFormat.Rgb; glFormat = PixelFormat.Rgb; glType = PixelType.UnsignedShort565; break; case SurfaceFormat.Bgra4444: #if IOS || ANDROID glInternalFormat = PixelInternalFormat.Rgba; #else glInternalFormat = PixelInternalFormat.Rgba4; #endif glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedShort4444; break; case SurfaceFormat.Bgra5551: glInternalFormat = PixelInternalFormat.Rgba; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedShort5551; break; case SurfaceFormat.Alpha8: glInternalFormat = PixelInternalFormat.Luminance; glFormat = PixelFormat.Luminance; glType = PixelType.UnsignedByte; break; #if !IOS && !ANDROID case SurfaceFormat.Dxt1: glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt3: glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt5: glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Single: glInternalFormat = PixelInternalFormat.R32f; glFormat = PixelFormat.Red; glType = PixelType.Float; break; case SurfaceFormat.HalfVector2: glInternalFormat = PixelInternalFormat.Rg16f; glFormat = PixelFormat.Rg; glType = PixelType.HalfFloat; break; // HdrBlendable implemented as HalfVector4 (see http://blogs.msdn.com/b/shawnhar/archive/2010/07/09/surfaceformat-hdrblendable.aspx) case SurfaceFormat.HdrBlendable: case SurfaceFormat.HalfVector4: glInternalFormat = PixelInternalFormat.Rgba16f; glFormat = PixelFormat.Rgba; glType = PixelType.HalfFloat; break; case SurfaceFormat.HalfSingle: glInternalFormat = PixelInternalFormat.R16f; glFormat = PixelFormat.Red; glType = PixelType.HalfFloat; break; case SurfaceFormat.Vector2: glInternalFormat = PixelInternalFormat.Rg32f; glFormat = PixelFormat.Rg; glType = PixelType.Float; break; case SurfaceFormat.Vector4: glInternalFormat = PixelInternalFormat.Rgba32f; glFormat = PixelFormat.Rgba; glType = PixelType.Float; break; case SurfaceFormat.NormalizedByte2: glInternalFormat = PixelInternalFormat.Rg8i; glFormat = PixelFormat.Rg; glType = PixelType.Byte; break; case SurfaceFormat.NormalizedByte4: glInternalFormat = PixelInternalFormat.Rgba8i; glFormat = PixelFormat.Rgba; glType = PixelType.Byte; break; case SurfaceFormat.Rg32: glInternalFormat = PixelInternalFormat.Rg16ui; glFormat = PixelFormat.Rg; glType = PixelType.UnsignedShort; break; case SurfaceFormat.Rgba64: glInternalFormat = PixelInternalFormat.Rgba16ui; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedShort; break; case SurfaceFormat.Rgba1010102: glInternalFormat = PixelInternalFormat.Rgb10A2ui; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedInt1010102; break; #endif #if OUYA case SurfaceFormat.Dxt1: glInternalFormat = (PixelInternalFormat)0x83F1; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt3: glInternalFormat = (PixelInternalFormat)0x83F2; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt5: glInternalFormat = (PixelInternalFormat)0x83F3; glFormat = (PixelFormat)All.CompressedTextureFormats; break; #endif #if IOS || ANDROID case SurfaceFormat.RgbPvrtc2Bpp: glInternalFormat = PixelInternalFormat.CompressedRgbPvrtc2Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbPvrtc4Bpp: glInternalFormat = PixelInternalFormat.CompressedRgbPvrtc4Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbaPvrtc2Bpp: glInternalFormat = PixelInternalFormat.CompressedRgbaPvrtc2Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbaPvrtc4Bpp: glInternalFormat = PixelInternalFormat.CompressedRgbaPvrtc4Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; #endif default: throw new NotSupportedException(); } }
internal void Activate(TextureTarget target, bool useMipmaps = false) { switch (Filter) { case TextureFilter.Point: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapNearest : TextureMinFilter.Nearest)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GraphicsExtensions.CheckGLError(); break; case TextureFilter.Linear: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapLinear : TextureMinFilter.Linear)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); break; case TextureFilter.Anisotropic: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, MathHelper.Clamp(this.MaxAnisotropy, 1.0f, SamplerState.MaxTextureMaxAnisotropy)); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapLinear : TextureMinFilter.Linear)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); break; case TextureFilter.PointMipLinear: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapLinear : TextureMinFilter.Nearest)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GraphicsExtensions.CheckGLError(); break; case TextureFilter.LinearMipPoint: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapNearest : TextureMinFilter.Linear)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); break; case TextureFilter.MinLinearMagPointMipLinear: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapLinear : TextureMinFilter.Linear)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GraphicsExtensions.CheckGLError(); break; case TextureFilter.MinLinearMagPointMipPoint: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.LinearMipmapNearest: TextureMinFilter.Linear)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GraphicsExtensions.CheckGLError(); break; case TextureFilter.MinPointMagLinearMipLinear: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapLinear: TextureMinFilter.Nearest)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); break; case TextureFilter.MinPointMagLinearMipPoint: if (GraphicsCapabilities.SupportsTextureFilterAnisotropic) { GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); GraphicsExtensions.CheckGLError(); } GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapNearest: TextureMinFilter.Nearest)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GraphicsExtensions.CheckGLError(); break; default: throw new NotSupportedException(); } // Set up texture addressing. GL.TexParameter(target, TextureParameterName.TextureWrapS, (int)GetWrapMode(AddressU)); GraphicsExtensions.CheckGLError(); GL.TexParameter(target, TextureParameterName.TextureWrapT, (int)GetWrapMode(AddressV)); GraphicsExtensions.CheckGLError(); #if !GLES // LOD bias is not supported by glTexParameter in OpenGL ES 2.0 GL.TexParameter(target, TextureParameterName.TextureLodBias, MipMapLevelOfDetailBias); GraphicsExtensions.CheckGLError(); #endif }
/// <summary> /// Initializes object (find suitable depth and stencil format). Must be called every time the bindings change. It will throw an exception if: -Attachment point 0 has no binding -Not all bound surfaces have the same size -Not all bound surfaces have the same internal format /// </summary> private void Initialize() { this._manager.ReleaseRenderBuffer( this._depth ); this._manager.ReleaseRenderBuffer( this._stencil ); this._manager.ReleaseRenderBuffer( this._multiSampleColorBuffer ); //First buffer must be bound if ( this._color[ 0 ].buffer == null ) { throw new Core.AxiomException( "Attachment 0 must have surface attached" ); } // If we're doing multisampling, then we need another FBO which contains a // renderbuffer which is set up to multisample, and we'll blit it to the final // FBO afterwards to perform the multisample resolve. In that case, the // mMultisampleFB is bound during rendering and is the one with a depth/stencil var maxSupportedMRTs = Core.Root.Instance.RenderSystem.Capabilities.MultiRenderTargetCount; //Store basic stats int width = this._color[ 0 ].buffer.Width; int height = this._color[ 0 ].buffer.Height; GLenum format = this._color[ 0 ].buffer.GLFormat; //Bind simple buffer to add color attachments GL.BindFramebuffer( OpenTK.Graphics.ES20.All.Framebuffer, this._fb ); GLES2Config.GlCheckError( this ); //bind all attachment points to frame buffer for ( int x = 0; x < maxSupportedMRTs; x++ ) { if ( this._color[ x ].buffer != null ) { if ( this._color[ x ].buffer.Width != width || this._color[ x ].buffer.Height != height ) { var ss = new StringBuilder(); ss.Append( "Attachment " + x + " has incompatible size " ); ss.Append( this._color[ x ].buffer.Width + "x" + this._color[ x ].buffer.Height ); ss.Append( ". It must be of the same as the size of surface 0, " ); ss.Append( width + "x" + height.ToString() ); ss.Append( "." ); throw new Core.AxiomException( ss.ToString() ); } if ( this._color[ x ].buffer.GLFormat != format ) { throw new Core.AxiomException( "Attachment " + x.ToString() + " has incompatible format." ); } this._color[ x ].buffer.BindToFramebuffer( (GLenum) ( (int) GLenum.ColorAttachment0 ) + x, this._color[ x ].zoffset ); } else { //Detach GL.FramebufferRenderbuffer( GLenum.Framebuffer, (GLenum) ( (int) GLenum.ColorAttachment0 ) + x, GLenum.Renderbuffer, 0 ); GLES2Config.GlCheckError( this ); } } //Now deal with depth/stencil if ( this._multiSampleFB > 0 ) { //Bind multisample buffer GL.BindFramebuffer( GLenum.Framebuffer, this._multiSampleFB ); GLES2Config.GlCheckError( this ); //Create AA render buffer (color) //note, this can be shared too because we blit it to the final FBO //right after the render is finished this._multiSampleColorBuffer = this._manager.RequestRenderBuffer( format, width, height, this._numSamples ); //Attach it, because we won't be attaching below and non-multisample has //actually been attached to other FBO this._multiSampleColorBuffer.buffer.BindToFramebuffer( GLenum.ColorAttachment0, this._multiSampleColorBuffer.zoffset ); //depth & stencil will be dealt with below } /// Depth buffer is not handled here anymore. /// See GLES2FrameBufferObject::attachDepthBuffer() & RenderSystem::setDepthBufferFor() var bufs = new GLenum[ Configuration.Config.MaxMultipleRenderTargets ]; for ( int x = 0; x < Configuration.Config.MaxMultipleRenderTargets; x++ ) { //Fill attached color buffers if ( this._color[ x ].buffer != null ) { bufs[ x ] = (GLenum) ( (int) GLenum.ColorAttachment0 ) + x; } else { bufs[ x ] = GLenum.None; } } //Check status var status = GL.CheckFramebufferStatus( GLenum.Framebuffer ); GLES2Config.GlCheckError( this ); //Possible todo: /*Port notes * Ogre leaves a comment indicating that the screen buffer for iOS * is 1 as opposed to 0 in the case of most other devices * I'd like to think that OpenTK takes care of this for us and have defaulted it * to 0 */ GL.BindFramebuffer( GLenum.Framebuffer, 0 ); GLES2Config.GlCheckError( this ); switch ( status ) { case GLenum.FramebufferComplete: //All is good break; case GLenum.FramebufferUnsupported: throw new Core.AxiomException( "All framebuffer formats with this texture internal format unsupported" ); default: throw new Core.AxiomException( "Framebuffer incomplete or other FBO status error" ); } }
public override void GetBestDepthStencil(GLenum internalColorFormat, ref OpenTK.Graphics.ES20.All depthFormat, ref OpenTK.Graphics.ES20.All stencilFormat) { FormatProperties prop = this.props[(int)internalColorFormat]; int bestmode = 0; int bestscore = -1; for (int mode = 0; mode < prop.Modes.Count; mode++) { int desirability = 0; /// Find most desirable mode /// desirability == 0 if no depth, no stencil /// desirability == 1000...2000 if no depth, stencil /// desirability == 2000...3000 if depth, no stencil /// desirability == 3000+ if depth and stencil /// beyond this, the total numer of bits (stencil+depth) is maximised if (prop.Modes[mode].Stencil > 0) { desirability += 1000; } if (prop.Modes[mode].Depth > 0) { desirability += 2000; } if (depthBits[prop.Modes[mode].Depth] == 24) //Prefer 24 bit for now { desirability += 500; } if (depthFormats[prop.Modes[mode].Depth] == GLenum.Depth24Stencil8Oes) //Prefer 24/8 packed { desirability += 5000; } desirability += stencilBits[prop.Modes[mode].Stencil] + depthBits[prop.Modes[mode].Depth]; if (desirability > bestscore) { bestscore = desirability; bestmode = mode; } } depthFormat = depthFormats[prop.Modes[bestmode].Depth]; stencilFormat = stencilFormats[prop.Modes[bestmode].Stencil]; }
internal static void GetGLFormat (this SurfaceFormat format, out PixelInternalFormat glInternalFormat, out PixelFormat glFormat, out PixelType glType) { glInternalFormat = PixelInternalFormat.Rgba; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedByte; switch (format) { case SurfaceFormat.Color: glInternalFormat = PixelInternalFormat.Rgba; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedByte; break; case SurfaceFormat.Bgr565: glInternalFormat = PixelInternalFormat.Rgb; glFormat = PixelFormat.Rgb; glType = PixelType.UnsignedShort565; break; case SurfaceFormat.Bgra4444: #if IOS || ANDROID glInternalFormat = PixelInternalFormat.Rgba; #else glInternalFormat = PixelInternalFormat.Rgba4; #endif glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedShort4444; break; case SurfaceFormat.Bgra5551: glInternalFormat = PixelInternalFormat.Rgba; glFormat = PixelFormat.Rgba; glType = PixelType.UnsignedShort5551; break; case SurfaceFormat.Alpha8: glInternalFormat = PixelInternalFormat.Luminance; glFormat = PixelFormat.Luminance; glType = PixelType.UnsignedByte; break; #if !IOS && !ANDROID case SurfaceFormat.Dxt1: glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt3: glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Dxt5: glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.Single: glInternalFormat = PixelInternalFormat.R32f; glFormat = PixelFormat.Red; glType = PixelType.Float; break; #endif #if IOS || ANDROID case SurfaceFormat.RgbPvrtc2Bpp: glInternalFormat = PixelInternalFormat.CompressedRgbPvrtc2Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbPvrtc4Bpp: glInternalFormat = PixelInternalFormat.CompressedRgbPvrtc4Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbaPvrtc2Bpp: glInternalFormat = PixelInternalFormat.CompressedRgbaPvrtc2Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; case SurfaceFormat.RgbaPvrtc4Bpp: glInternalFormat = PixelInternalFormat.CompressedRgbaPvrtc4Bppv1Img; glFormat = (PixelFormat)All.CompressedTextureFormats; break; #endif default: throw new NotSupportedException(); } }
public void SetData <T>(CubeMapFace face, int level, Rectangle?rect, T[] data, int startIndex, int elementCount) where T : struct { if (data == null) { throw new ArgumentNullException("data"); } var elementSizeInByte = Marshal.SizeOf(typeof(T)); var dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned); var dataPtr = (IntPtr)(dataHandle.AddrOfPinnedObject().ToInt64() + startIndex * elementSizeInByte); int xOffset, yOffset, width, height; if (rect.HasValue) { xOffset = rect.Value.X; yOffset = rect.Value.Y; width = rect.Value.Width; height = rect.Value.Height; } else { xOffset = 0; yOffset = 0; width = Math.Max(1, this.size >> level); height = Math.Max(1, this.size >> level); } #if DIRECTX var box = new DataBox(dataPtr, GetPitch(width), 0); int subresourceIndex = (int)face * levelCount + level; var region = new ResourceRegion { Top = yOffset, Front = 0, Back = 1, Bottom = yOffset + height, Left = xOffset, Right = xOffset + width }; var d3dContext = GraphicsDevice._d3dContext; lock (d3dContext) d3dContext.UpdateSubresource(box, _texture, subresourceIndex, region); #elif PSM //TODO #else GL.BindTexture(TextureTarget.TextureCubeMap, this.glTexture); GraphicsExtensions.CheckGLError(); TextureTarget target = GetGLCubeFace(face); if (glFormat == (PixelFormat)All.CompressedTextureFormats) { throw new NotImplementedException(); } else { GL.TexSubImage2D(target, level, xOffset, yOffset, width, height, glFormat, glType, dataPtr); GraphicsExtensions.CheckGLError(); } #endif dataHandle.Free(); }