Skip to content

Commit

Permalink
chore: revert opengl shader changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pollend committed Mar 22, 2021
1 parent 8a0e447 commit c83bac4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,23 @@ public void registerCoreAssetTypes(ModuleAwareAssetTypeManager assetTypeManager)
return path.getPath().get(1).equals("fonts");
}
}));
assetTypeManager.createAssetType(Shader.class, GLSLShader::create, "shaders");
assetTypeManager.createAssetType(Shader.class, (urn, assetType, data) -> GLSLShader.create(urn, assetType, data, this), "shaders");
assetTypeManager.createAssetType(Material.class, (urn, assetType, data) ->
GLSLMaterial.create(urn, this, assetType, data),
"materials");
assetTypeManager.createAssetType(Mesh.class, (urn, assetType, data) -> OpenGLMesh.create(urn, assetType, bufferPool, data, this),
"mesh");
assetTypeManager.createAssetType(SkeletalMesh.class,
(urn, assetType, data) ->
OpenGLSkeletalMesh.create(urn, assetType, data, this, bufferPool),
OpenGLSkeletalMesh.create(urn, assetType, data, this, bufferPool),
"skeletalMesh");
assetTypeManager.createAssetType(MeshAnimation.class, MeshAnimationImpl::new,
"animations", "skeletalMesh");
assetTypeManager.createAssetType(Atlas.class, Atlas::new, "atlas");
assetTypeManager.createAssetType(MeshAnimationBundle.class, MeshAnimationBundle::new,
"skeletalMesh", "animations");
assetTypeManager.createAssetType(Subtexture.class, Subtexture::new);
}{}
}

public void registerRenderingSubsystem(Context context) {
context.put(RenderingSubsystemFactory.class, new LwjglRenderingSubsystemFactory(bufferPool));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public class GLSLShader extends Shader {
}

private EnumSet<ShaderProgramFeature> availableFeatures = Sets.newEnumSet(Collections.emptyList(), ShaderProgramFeature.class);

private ShaderData shaderProgramBase;
private final LwjglGraphicsProcessing graphicsProcessing;
private Map<String, ShaderParameterMetadata> parameters = Maps.newHashMap();

private Config config = CoreRegistry.get(Config.class);
Expand All @@ -89,15 +89,18 @@ public class GLSLShader extends Shader {


public GLSLShader(ResourceUrn urn, AssetType<?, ShaderData> assetType, ShaderData data,
DisposalAction disposalAction) {
DisposalAction disposalAction, LwjglGraphicsProcessing graphicsProcessing) {
super(urn, assetType, disposalAction);
this.disposalAction = disposalAction;
reload(data);
this.graphicsProcessing = graphicsProcessing;
graphicsProcessing.asynchToDisplayThread(() -> {
reload(data);
});
}


public static GLSLShader create(ResourceUrn urn, AssetType<?, ShaderData> assetType, ShaderData data) {
return new GLSLShader(urn, assetType, data, new GLSLShader.DisposalAction(urn));
public static GLSLShader create(ResourceUrn urn, AssetType<?, ShaderData> assetType, ShaderData data, LwjglGraphicsProcessing graphicsProcessing) {
return new GLSLShader(urn, assetType, data, new GLSLShader.DisposalAction(urn, graphicsProcessing), graphicsProcessing);
}

private static InputStreamReader getInputStreamReaderFromResource(String resource) {
Expand Down Expand Up @@ -126,7 +129,9 @@ int linkShaderProgram(int featureHash) {

@Override
public void recompile() {
registerAllShaderPermutations();
graphicsProcessing.asynchToDisplayThread(() -> {
registerAllShaderPermutations();
});
}


Expand Down Expand Up @@ -399,14 +404,16 @@ protected void doReload(ShaderData data) {
public static class DisposalAction implements DisposableResource {

private final ResourceUrn urn;
private final LwjglGraphicsProcessing graphicsProcessing;

private final TIntIntMap fragmentPrograms = new TIntIntHashMap();
private final TIntIntMap vertexPrograms = new TIntIntHashMap();
private final TIntIntMap geometryPrograms = new TIntIntHashMap();

// made package-private after CheckStyle's suggestion
public DisposalAction(ResourceUrn urn) {
public DisposalAction(ResourceUrn urn, LwjglGraphicsProcessing graphicsProcessing) {
this.urn = urn;
this.graphicsProcessing = graphicsProcessing;
}

private void disposeData() {
Expand All @@ -416,11 +423,14 @@ private void disposeData() {
}

private void disposePrograms(TIntIntMap programs) {
TIntIntIterator it = programs.iterator();
while (it.hasNext()) {
it.advance();
GL20.glDeleteShader(it.value());
}
final TIntIntMap disposedPrograms = new TIntIntHashMap(programs);
graphicsProcessing.asynchToDisplayThread(() -> {
TIntIntIterator it = disposedPrograms.iterator();
while (it.hasNext()) {
it.advance();
GL20.glDeleteShader(it.value());
}
});
programs.clear();
}

Expand Down

0 comments on commit c83bac4

Please sign in to comment.