protected internal virtual void drawArraysTriangleFan(int first, int count) { Memory mem = Memory.Instance; CachedTextureResampled cachedTexture = CachedTexture; TriangleRenderer triangleRenderer = new TriangleRenderer(context, cachedTexture, useVertexTexture); VertexState tv1 = null; VertexState tv2 = null; VertexState tv3 = v1; bool readTexture = context.textureFlag.Enabled && !context.clearMode; for (int i = 0; i < count; i++) { readVertex(mem, first + i, tv3, readTexture); if (tv2 != null) { drawTriangle(triangleRenderer, tv1, tv2, tv3, false); VertexState v = tv2; tv2 = tv3; tv3 = v; } else if (tv1 == null) { tv1 = tv3; tv3 = v2; } else { tv2 = tv3; tv3 = v3; } } }
protected internal virtual void init(GeContext context, CachedTextureResampled texture, bool useVertexTexture, bool isTriangle) { this.cachedTexture = texture; this.useVertexTexture = useVertexTexture; this.isTriangle = isTriangle; nearZ = context.nearZ; farZ = context.farZ; scissorX1 = context.scissor_x1; scissorY1 = context.scissor_y1; scissorX2 = context.scissor_x2; scissorY2 = context.scissor_y2; clearMode = context.clearMode; cullFaceEnabled = context.cullFaceFlag.Enabled; frontFaceCw = context.frontFaceCw; clipPlanesEnabled = context.clipPlanesFlag.Enabled; fbw = context.fbw; zbw = context.zbw; if (context.ditherFlag.Enabled) { ditherMatrix = context.dither_matrix.Clone(); } transform2D = context.vinfo.transform2D; if (!transform2D) { viewportWidth = context.viewport_width; viewportHeight = context.viewport_height; viewportX = context.viewport_cx; viewportY = context.viewport_cy; screenOffsetX = context.offset_x; screenOffsetY = context.offset_y; zscale = context.zscale; zpos = context.zpos; if (context.tex_map_mode == GeCommands.TMAP_TEXTURE_MAP_MODE_TEXTURE_COORDIATES_UV) { texTranslateX = context.tex_translate_x; texTranslateY = context.tex_translate_y; texScaleX = context.tex_scale_x; texScaleY = context.tex_scale_y; } else if (context.tex_map_mode == GeCommands.TMAP_TEXTURE_MAP_MODE_ENVIRONMENT_MAP) { envMapLightPosU = new float[4]; envMapLightPosV = new float[4]; Utilities.copy(envMapLightPosU, context.light_pos[context.tex_shade_u]); Utilities.copy(envMapLightPosV, context.light_pos[context.tex_shade_v]); envMapDiffuseLightU = context.light_type[context.tex_shade_u] == GeCommands.LIGHT_AMBIENT_DIFFUSE; envMapDiffuseLightV = context.light_type[context.tex_shade_v] == GeCommands.LIGHT_AMBIENT_DIFFUSE; envMapShininess = context.materialShininess; } } if (isLogTraceEnabled) { log.trace(string.Format("Context: {0}", context.ToString())); } }
protected internal virtual void drawArraysTriangles(int first, int count) { Memory mem = Memory.Instance; CachedTextureResampled cachedTexture = CachedTexture; TriangleRenderer triangleRenderer = new TriangleRenderer(context, cachedTexture, useVertexTexture); bool readTexture = context.textureFlag.Enabled && !context.clearMode; for (int i = 0; i < count; i += 3) { readVertex(mem, first + i, v1, readTexture); readVertex(mem, first + i + 1, v2, readTexture); readVertex(mem, first + i + 2, v3, readTexture); drawTriangle(triangleRenderer, v1, v2, v3, false); } }
protected internal virtual void copy(BaseRenderer from) { imageWriterSkipEOL = from.imageWriterSkipEOL; depthWriterSkipEOL = from.depthWriterSkipEOL; compiledRendererKey = from.compiledRendererKey; compiledRenderer = from.compiledRenderer; lighting = from.lighting; textureAccess = from.textureAccess; transform2D = from.transform2D; nearZ = from.nearZ; farZ = from.farZ; scissorX1 = from.scissorX1; scissorY1 = from.scissorY1; scissorX2 = from.scissorX2; scissorY2 = from.scissorY2; cachedTexture = from.cachedTexture; isTriangle = from.isTriangle; colorTestRef = from.colorTestRef; colorTestMsk = from.colorTestMsk; alphaRef = from.alphaRef; alphaMask = from.alphaMask; stencilRef = from.stencilRef; stencilMask = from.stencilMask; sfix = from.sfix; dfix = from.dfix; colorMask = from.colorMask; primaryColorSetGlobally = from.primaryColorSetGlobally; texTranslateX = from.texTranslateX; texTranslateY = from.texTranslateY; texScaleX = from.texScaleX; texScaleY = from.texScaleY; textureWidth = from.textureWidth; textureHeight = from.textureHeight; texEnvColorB = from.texEnvColorB; texEnvColorG = from.texEnvColorG; texEnvColorR = from.texEnvColorR; envMapLightPosU = from.envMapLightPosU; envMapLightPosV = from.envMapLightPosV; envMapDiffuseLightU = from.envMapDiffuseLightU; envMapDiffuseLightV = from.envMapDiffuseLightV; envMapShininess = from.envMapShininess; texMinFilter = from.texMinFilter; texMagFilter = from.texMagFilter; primaryColor = from.primaryColor; ditherMatrix = from.ditherMatrix; }
public override void setCompressedTexImage(int level, int internalFormat, int width, int height, int compressedSize, Buffer buffer) { if (useTextureCache) { cachedTextureStatistics.start(); // TODO Cache all the texture levels if (level == 0) { int bufferWidth = context.texture_buffer_width[level]; IMemoryReader imageReader = ImageReader.getImageReader(context.texture_base_pointer[level], width, height, bufferWidth, internalFormat, false, 0, 0, 0, 0, 0, 0, null, null); CachedTexture cachedTexture = CachedTexture.getCachedTexture(System.Math.Min(width, bufferWidth), height, internalFormat, imageReader); CachedTextureResampled cachedTextureResampled = new CachedTextureResampled(cachedTexture); cachedTextures[bindTexture_Renamed] = cachedTextureResampled; } cachedTextureStatistics.end(); } }
protected internal virtual void drawArraysSprites(int first, int count) { CachedTextureResampled cachedTexture = CachedTexture; SpriteRenderer spriteRenderer = new SpriteRenderer(context, cachedTexture, useVertexTexture); bool readTexture = context.textureFlag.Enabled && !context.clearMode; Memory mem = Memory.Instance; for (int i = first; i < count - 1; i += 2) { int addr1 = context.vinfo.getAddress(mem, i); int addr2 = context.vinfo.getAddress(mem, i + 1); context.vinfo.readVertex(mem, addr1, v1, readTexture, VideoEngine.Instance.DoubleTexture2DCoords); context.vinfo.readVertex(mem, addr2, v2, readTexture, VideoEngine.Instance.DoubleTexture2DCoords); drawSprite(spriteRenderer, v1, v2); } }
protected internal override void init(GeContext context, CachedTextureResampled texture, bool useVertexTexture, bool isTriangle) { base.init(context, texture, useVertexTexture, isTriangle); prim.pxMax = int.MinValue; prim.pxMin = int.MaxValue; prim.pyMax = int.MinValue; prim.pyMin = int.MaxValue; prim.pzMax = int.MinValue; prim.pzMin = int.MaxValue; if (!transform2D) { // Pre-compute the Model-View matrix matrixMult(pixel.modelViewMatrix, context.view_uploaded_matrix, context.model_uploaded_matrix); // Pre-compute the Model-View-Projection matrix matrixMult(pixel.modelViewProjectionMatrix, context.proj_uploaded_matrix, pixel.modelViewMatrix); } }
public override void setTexImage(int level, int internalFormat, int width, int height, int format, int type, int textureSize, Buffer buffer) { if (useTextureCache) { cachedTextureStatistics.start(); // TODO Cache all the texture levels if (level == 0) { CachedTexture cachedTexture = null; if (buffer is IntBuffer) { cachedTexture = CachedTexture.getCachedTexture(textureBufferWidth, height, format, ((IntBuffer)buffer).array(), buffer.arrayOffset(), textureSize >> 2); } else if (buffer is ShortBuffer) { cachedTexture = CachedTexture.getCachedTexture(textureBufferWidth, height, format, ((ShortBuffer)buffer).array(), buffer.arrayOffset(), textureSize >> 1); } CachedTextureResampled cachedTextureResampled = new CachedTextureResampled(cachedTexture); cachedTextures[bindTexture_Renamed] = cachedTextureResampled; } cachedTextureStatistics.end(); } }
protected internal virtual void drawArraysTriangleStrips(int first, int count) { Memory mem = Memory.Instance; CachedTextureResampled cachedTexture = CachedTexture; TriangleRenderer triangleRenderer = new TriangleRenderer(context, cachedTexture, useVertexTexture); SpriteRenderer spriteRenderer = null; VertexState tv1 = null; VertexState tv2 = null; VertexState tv3 = null; VertexState tv4 = v1; bool readTexture = context.textureFlag.Enabled && !context.clearMode; for (int i = 0; i < count; i++) { readVertex(mem, first + i, tv4, readTexture); if (tv3 != null) { // Displaying a sprite (i.e. rectangular area) is faster. // Try to merge adjacent triangles if they form a sprite. if (isSprite(context.vinfo, tv1, tv2, tv3, tv4)) { if (spriteRenderer == null) { spriteRenderer = new SpriteRenderer(context, cachedTexture, useVertexTexture); } drawSprite(spriteRenderer, tv1, tv4); v5.copy(tv3); v6.copy(tv4); v1.copy(v5); v2.copy(v6); tv1 = v1; tv2 = v2; tv3 = null; tv4 = v3; } else { // The Front face direction is inverted every 2 triangles in the strip. drawTriangle(triangleRenderer, tv1, tv2, tv3, ((i - 3) & 1) != 0); VertexState v = tv1; tv1 = tv2; tv2 = tv3; tv3 = tv4; tv4 = v; } } else if (tv1 == null) { tv1 = tv4; tv4 = v2; } else if (tv2 == null) { tv2 = tv4; tv4 = v3; } else { tv3 = tv4; tv4 = v4; } } if (tv3 != null) { // The Front face direction is inverted every 2 triangles in the strip. drawTriangle(triangleRenderer, tv1, tv2, tv3, (count & 1) == 0); } }