public static void apply(final ClipState state) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final ClipStateRecord record = (ClipStateRecord) context.getStateRecord(StateType.Clip); context.setCurrentState(StateType.Clip, state); final ContextCapabilities caps = context.getCapabilities(); final int max = Math.min(ClipState.MAX_CLIP_PLANES, caps.getMaxUserClipPlanes()); if (state.isEnabled()) { for (int i = 0; i < max; i++) { enableClipPlane(i, state.getPlaneEnabled(i), state, record); } } else { for (int i = 0; i < max; i++) { enableClipPlane(i, false, state, record); } } if (!record.isValid()) { record.validate(); } }
public static void apply(final JoglRenderer renderer, final ClipState state) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final ClipStateRecord record = (ClipStateRecord) context.getStateRecord(StateType.Clip); context.setCurrentState(StateType.Clip, state); final ContextCapabilities caps = context.getCapabilities(); final int max = Math.min(ClipState.MAX_CLIP_PLANES, caps.getMaxUserClipPlanes()); if (state.isEnabled()) { for (int i = 0; i < max; i++) { enableClipPlane(i, state.getPlaneEnabled(i), state, record); } } else { for (int i = 0; i < max; i++) { enableClipPlane(i, false, state, record); } } if (!record.isValid()) { record.validate(); } }
public static void apply(final ShadingState state) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final ShadingStateRecord record = (ShadingStateRecord) context.getStateRecord(StateType.Shading); context.setCurrentState(StateType.Shading, state); // If not enabled, we'll use smooth final int toApply = state.isEnabled() ? getGLShade(state.getShadingMode()) : GL11.GL_SMOOTH; // only apply if we're different. Update record to reflect any changes. if (!record.isValid() || toApply != record.lastShade) { GL11.glShadeModel(toApply); record.lastShade = toApply; } if (!record.isValid()) { record.validate(); } }
/** * Useful for external lwjgl based classes that need to safely set the current texture. */ public static void doTextureBind(final Texture texture, final int unit, final boolean invalidateState) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final ContextCapabilities caps = context.getCapabilities(); final TextureStateRecord record = (TextureStateRecord) context.getStateRecord(StateType.Texture); if (invalidateState) { // Set this to null because no current state really matches anymore context.setCurrentState(StateType.Texture, null); } checkAndSetUnit(unit, record, caps); final int id = texture.getTextureIdForContext(context); GL11C.glBindTexture(getGLType(texture.getType()), id); if (Constants.stats) { StatCollector.addStat(StatType.STAT_TEXTURE_BINDS, 1); } if (record != null) { record.units[unit].boundTexture = id; } }
public static void apply(final JoglRenderer renderer, final ShadingState state) { final GL gl = GLContext.getCurrentGL(); // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final ShadingStateRecord record = (ShadingStateRecord) context.getStateRecord(StateType.Shading); context.setCurrentState(StateType.Shading, state); // If not enabled, we'll use smooth final int toApply = state.isEnabled() ? getGLShade(state.getShadingMode()) : GLLightingFunc.GL_SMOOTH; // only apply if we're different. Update record to reflect any changes. if (!record.isValid() || toApply != record.lastShade) { gl.getGL2().glShadeModel(toApply); record.lastShade = toApply; } if (!record.isValid()) { record.validate(); } }
/** * Useful for external lwjgl based classes that need to safely set the current texture. */ public static void doTextureBind(final Texture texture, final int unit, final boolean invalidateState) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final ContextCapabilities caps = context.getCapabilities(); final TextureStateRecord record = (TextureStateRecord) context.getStateRecord(StateType.Texture); if (invalidateState) { // Set this to null because no current state really matches anymore context.setCurrentState(StateType.Texture, null); } checkAndSetUnit(unit, record, caps); final int id = texture.getTextureIdForContext(context.getGlContextRep()); GL11.glBindTexture(getGLType(texture.getType()), id); if (Constants.stats) { StatCollector.addStat(StatType.STAT_TEXTURE_BINDS, 1); } if (record != null) { record.units[unit].boundTexture = id; } }
/** * Useful for external jogl based classes that need to safely set the current texture. */ public static void doTextureBind(final Texture texture, final int unit, final boolean invalidateState) { final GL gl = GLContext.getCurrentGL(); // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final ContextCapabilities caps = context.getCapabilities(); final TextureStateRecord record = (TextureStateRecord) context.getStateRecord(StateType.Texture); if (invalidateState) { // Set this to null because no current state really matches anymore context.setCurrentState(StateType.Texture, null); } checkAndSetUnit(unit, record, caps); final int id = texture.getTextureIdForContext(context.getGlContextRep()); gl.glBindTexture(getGLType(texture.getType()), id); if (Constants.stats) { StatCollector.addStat(StatType.STAT_TEXTURE_BINDS, 1); } if (record != null) { record.units[unit].boundTexture = id; } }
public static void apply(final LwjglRenderer renderer, final WireframeState state) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final WireframeStateRecord record = (WireframeStateRecord) context.getStateRecord(StateType.Wireframe); context.setCurrentState(StateType.Wireframe, state); if (state.isEnabled()) { renderer.setupLineParameters(state.getLineWidth(), 1, (short) 0xFFFF, state.isAntialiased()); switch (state.getFace()) { case Front: applyPolyMode(GL11.GL_LINE, GL11.GL_FILL, record); break; case Back: applyPolyMode(GL11.GL_FILL, GL11.GL_LINE, record); break; case FrontAndBack: default: applyPolyMode(GL11.GL_LINE, GL11.GL_LINE, record); break; } } else { applyPolyMode(GL11.GL_FILL, GL11.GL_FILL, record); } if (!record.isValid()) { record.validate(); } }
public static void apply(final JoglRenderer renderer, final WireframeState state) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final WireframeStateRecord record = (WireframeStateRecord) context.getStateRecord(StateType.Wireframe); context.setCurrentState(StateType.Wireframe, state); if (state.isEnabled()) { renderer.setupLineParameters(state.getLineWidth(), 1, (short) 0xFFFF, state.isAntialiased()); switch (state.getFace()) { case Front: applyPolyMode(GL2GL3.GL_LINE, GL2GL3.GL_FILL, record); break; case Back: applyPolyMode(GL2GL3.GL_FILL, GL2GL3.GL_LINE, record); break; case FrontAndBack: default: applyPolyMode(GL2GL3.GL_LINE, GL2GL3.GL_LINE, record); break; } } else { applyPolyMode(GL2GL3.GL_FILL, GL2GL3.GL_FILL, record); } if (!record.isValid()) { record.validate(); } }
public static void apply(final Lwjgl3Renderer renderer, final WireframeState state) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final WireframeStateRecord record = (WireframeStateRecord) context.getStateRecord(StateType.Wireframe); context.setCurrentState(StateType.Wireframe, state); if (state.isEnabled()) { renderer.setupLineParameters(state.getLineWidth(), state.isAntialiased()); switch (state.getFace()) { case Front: applyPolyMode(GL11C.GL_LINE, GL11C.GL_FILL, record); break; case Back: applyPolyMode(GL11C.GL_FILL, GL11C.GL_LINE, record); break; case FrontAndBack: default: applyPolyMode(GL11C.GL_LINE, GL11C.GL_LINE, record); break; } } else { applyPolyMode(GL11C.GL_FILL, GL11C.GL_FILL, record); } if (!record.isValid()) { record.validate(); } }
public static void apply(final LwjglRenderer renderer, final OffsetState state) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final OffsetStateRecord record = (OffsetStateRecord) context.getStateRecord(StateType.Offset); context.setCurrentState(StateType.Offset, state); if (state.isEnabled()) { // enable any set offset types setOffsetEnabled(OffsetType.Fill, state.isTypeEnabled(OffsetType.Fill), record); setOffsetEnabled(OffsetType.Line, state.isTypeEnabled(OffsetType.Line), record); setOffsetEnabled(OffsetType.Point, state.isTypeEnabled(OffsetType.Point), record); // set factor and units. setOffset(state.getFactor(), state.getUnits(), record); } else { // disable all offset types setOffsetEnabled(OffsetType.Fill, false, record); setOffsetEnabled(OffsetType.Line, false, record); setOffsetEnabled(OffsetType.Point, false, record); // set factor and units to default 0, 0. setOffset(0, 0, record); } if (!record.isValid()) { record.validate(); } }
public static void apply(final Lwjgl3Renderer renderer, final OffsetState state) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final OffsetStateRecord record = (OffsetStateRecord) context.getStateRecord(StateType.Offset); context.setCurrentState(StateType.Offset, state); if (state.isEnabled()) { // enable any set offset types setOffsetEnabled(OffsetType.Fill, state.isTypeEnabled(OffsetType.Fill), record); setOffsetEnabled(OffsetType.Line, state.isTypeEnabled(OffsetType.Line), record); setOffsetEnabled(OffsetType.Point, state.isTypeEnabled(OffsetType.Point), record); // set factor and units. setOffset(state.getFactor(), state.getUnits(), record); } else { // disable all offset types setOffsetEnabled(OffsetType.Fill, false, record); setOffsetEnabled(OffsetType.Line, false, record); setOffsetEnabled(OffsetType.Point, false, record); // set factor and units to default 0, 0. setOffset(0, 0, record); } if (!record.isValid()) { record.validate(); } }
public static void apply(final JoglRenderer renderer, final OffsetState state) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final OffsetStateRecord record = (OffsetStateRecord) context.getStateRecord(StateType.Offset); context.setCurrentState(StateType.Offset, state); if (state.isEnabled()) { // enable any set offset types setOffsetEnabled(OffsetType.Fill, state.isTypeEnabled(OffsetType.Fill), record); setOffsetEnabled(OffsetType.Line, state.isTypeEnabled(OffsetType.Line), record); setOffsetEnabled(OffsetType.Point, state.isTypeEnabled(OffsetType.Point), record); // set factor and units. setOffset(state.getFactor(), state.getUnits(), record); } else { // disable all offset types setOffsetEnabled(OffsetType.Fill, false, record); setOffsetEnabled(OffsetType.Line, false, record); setOffsetEnabled(OffsetType.Point, false, record); // set factor and units to default 0, 0. setOffset(0, 0, record); } if (!record.isValid()) { record.validate(); } }
public static void apply(final ColorMaskState state) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final ColorMaskStateRecord record = (ColorMaskStateRecord) context.getStateRecord(StateType.ColorMask); context.setCurrentState(StateType.ColorMask, state); if (state.isEnabled()) { if (!record.isValid() || !record.is(state.getRed(), state.getGreen(), state.getBlue(), state.getAlpha())) { GL11.glColorMask(state.getRed(), state.getGreen(), state.getBlue(), state.getAlpha()); record.set(state.getRed(), state.getGreen(), state.getBlue(), state.getAlpha()); } } else if (!record.isValid() || !record.is(true, true, true, true)) { GL11.glColorMask(true, true, true, true); record.set(true, true, true, true); } if (!record.isValid()) { record.validate(); } } }
public static void apply(final ColorMaskState state) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final ColorMaskStateRecord record = (ColorMaskStateRecord) context.getStateRecord(StateType.ColorMask); context.setCurrentState(StateType.ColorMask, state); if (state.isEnabled()) { if (!record.isValid() || !record.is(state.getRed(), state.getGreen(), state.getBlue(), state.getAlpha())) { GL11C.glColorMask(state.getRed(), state.getGreen(), state.getBlue(), state.getAlpha()); record.set(state.getRed(), state.getGreen(), state.getBlue(), state.getAlpha()); } } else if (!record.isValid() || !record.is(true, true, true, true)) { GL11C.glColorMask(true, true, true, true); record.set(true, true, true, true); } if (!record.isValid()) { record.validate(); } } }
public static void apply(final BlendState state) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final BlendStateRecord record = (BlendStateRecord) context.getStateRecord(StateType.Blend); final ContextCapabilities caps = context.getCapabilities(); context.setCurrentState(StateType.Blend, state); if (state.isEnabled()) { applyBlendEquations(state.isBlendEnabled(), state, record, caps); applyBlendColor(state.isBlendEnabled(), state, record, caps); applyBlendFunctions(state.isBlendEnabled(), state, record, caps); applyTest(state.isTestEnabled(), state, record); applyAlphaCoverage(state.isSampleAlphaToCoverageEnabled(), state.isSampleAlphaToOneEnabled(), record, caps); applySampleCoverage(state.isSampleCoverageEnabled(), state, record, caps); } else { // disable blend applyBlendEquations(false, state, record, caps); // disable alpha test applyTest(false, state, record); // disable sample coverage applyAlphaCoverage(false, false, record, caps); applySampleCoverage(false, state, record, caps); } if (!record.isValid()) { record.validate(); } }
public static void apply(final JoglRenderer renderer, final ColorMaskState state) { final GL gl = GLContext.getCurrentGL(); // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final ColorMaskStateRecord record = (ColorMaskStateRecord) context.getStateRecord(StateType.ColorMask); context.setCurrentState(StateType.ColorMask, state); if (state.isEnabled()) { if (!record.isValid() || !record.is(state.getRed(), state.getGreen(), state.getBlue(), state.getAlpha())) { gl.glColorMask(state.getRed(), state.getGreen(), state.getBlue(), state.getAlpha()); record.set(state.getRed(), state.getGreen(), state.getBlue(), state.getAlpha()); } } else if (!record.isValid() || !record.is(true, true, true, true)) { gl.glColorMask(true, true, true, true); record.set(true, true, true, true); } if (!record.isValid()) { record.validate(); } } }
final BlendStateRecord record = (BlendStateRecord) context.getStateRecord(StateType.Blend); final ContextCapabilities caps = context.getCapabilities(); context.setCurrentState(StateType.Blend, state);
public static void apply(final MaterialState state) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final MaterialStateRecord record = (MaterialStateRecord) context.getStateRecord(StateType.Material); context.setCurrentState(StateType.Material, state); if (state.isEnabled()) { // setup colormaterial, if changed. applyColorMaterial(state.getColorMaterial(), state.getColorMaterialFace(), record); // apply colors, if needed and not what is currently set. applyColor(ColorMaterial.Ambient, state.getAmbient(), state.getBackAmbient(), record); applyColor(ColorMaterial.Diffuse, state.getDiffuse(), state.getBackDiffuse(), record); applyColor(ColorMaterial.Emissive, state.getEmissive(), state.getBackEmissive(), record); applyColor(ColorMaterial.Specular, state.getSpecular(), state.getBackSpecular(), record); // set our shine applyShininess(state.getShininess(), state.getBackShininess(), record); } else { // apply defaults applyColorMaterial(MaterialState.DEFAULT_COLOR_MATERIAL, MaterialState.DEFAULT_COLOR_MATERIAL_FACE, record); applyColor(ColorMaterial.Ambient, MaterialState.DEFAULT_AMBIENT, MaterialState.DEFAULT_AMBIENT, record); applyColor(ColorMaterial.Diffuse, MaterialState.DEFAULT_DIFFUSE, MaterialState.DEFAULT_DIFFUSE, record); applyColor(ColorMaterial.Emissive, MaterialState.DEFAULT_EMISSIVE, MaterialState.DEFAULT_EMISSIVE, record); applyColor(ColorMaterial.Specular, MaterialState.DEFAULT_SPECULAR, MaterialState.DEFAULT_SPECULAR, record); applyShininess(MaterialState.DEFAULT_SHININESS, MaterialState.DEFAULT_SHININESS, record); } if (!record.isValid()) { record.validate(); } }
public static void apply(final JoglRenderer renderer, final MaterialState state) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final MaterialStateRecord record = (MaterialStateRecord) context.getStateRecord(StateType.Material); context.setCurrentState(StateType.Material, state); if (state.isEnabled()) { // setup colormaterial, if changed. applyColorMaterial(state.getColorMaterial(), state.getColorMaterialFace(), record); // apply colors, if needed and not what is currently set. applyColor(ColorMaterial.Ambient, state.getAmbient(), state.getBackAmbient(), record); applyColor(ColorMaterial.Diffuse, state.getDiffuse(), state.getBackDiffuse(), record); applyColor(ColorMaterial.Emissive, state.getEmissive(), state.getBackEmissive(), record); applyColor(ColorMaterial.Specular, state.getSpecular(), state.getBackSpecular(), record); // set our shine applyShininess(state.getShininess(), state.getBackShininess(), record); } else { // apply defaults applyColorMaterial(MaterialState.DEFAULT_COLOR_MATERIAL, MaterialState.DEFAULT_COLOR_MATERIAL_FACE, record); applyColor(ColorMaterial.Ambient, MaterialState.DEFAULT_AMBIENT, MaterialState.DEFAULT_AMBIENT, record); applyColor(ColorMaterial.Diffuse, MaterialState.DEFAULT_DIFFUSE, MaterialState.DEFAULT_DIFFUSE, record); applyColor(ColorMaterial.Emissive, MaterialState.DEFAULT_EMISSIVE, MaterialState.DEFAULT_EMISSIVE, record); applyColor(ColorMaterial.Specular, MaterialState.DEFAULT_SPECULAR, MaterialState.DEFAULT_SPECULAR, record); applyShininess(MaterialState.DEFAULT_SHININESS, MaterialState.DEFAULT_SHININESS, record); } if (!record.isValid()) { record.validate(); } }