-
Notifications
You must be signed in to change notification settings - Fork 7
Feature/uniform location #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Mee-gu
wants to merge
11
commits into
minggo:metal-support
Choose a base branch
from
Mee-gu:feature/uniformLocation
base: metal-support
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d094d41
[Feature] update uniform location
Mee-gu 6b15161
[Feature] remove unneeded code
Mee-gu 01218b9
[Feature] add program files
Mee-gu 17c23e4
[Feature] remove BindGroup
Mee-gu 9786a45
[BugFix] fix reference retain
Mee-gu 999198e
[Feature] update uniform location
Mee-gu 2152f8e
[Feature] remove unneeded code
Mee-gu c38092c
[Feature] use unordered_map to simply code
Mee-gu 64706e1
[Feature] add ProgramCache
Mee-gu 10c0698
[Feature] remove unneeded code
Mee-gu 2063ed7
[Feature] update ProgramCache
Mee-gu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #include "Program.h" | ||
| #include "ShaderModule.h" | ||
| #include "Texture.h" | ||
|
|
||
| CC_BACKEND_BEGIN | ||
|
|
||
| Program::~Program() | ||
| { | ||
| _vertexTextureInfos.clear(); | ||
| _fragTextureInfos.clear(); | ||
| } | ||
|
|
||
| Program::TextureInfo::~TextureInfo() | ||
| { | ||
| releaseTextures(); | ||
| } | ||
|
|
||
| void Program::TextureInfo::retainTextures() | ||
| { | ||
| for (auto& texture : textures) | ||
| CC_SAFE_RETAIN(texture); | ||
| } | ||
|
|
||
| void Program::TextureInfo::releaseTextures() | ||
| { | ||
| for (auto& texture : textures) | ||
| CC_SAFE_RELEASE(texture); | ||
| } | ||
|
|
||
| void Program::setVertexTexture(int location, uint32_t slot, Texture* texture) | ||
| { | ||
| setTexture(location, slot, texture, _vertexTextureInfos); | ||
| } | ||
|
|
||
| void Program::setFragmentTexture(int location, uint32_t slot, Texture* texture) | ||
| { | ||
| setTexture(location, slot, texture, _fragTextureInfos); | ||
| } | ||
|
|
||
| void Program::setVertexTextureArray(int location, const std::vector<uint32_t>& slots, const std::vector<Texture*> textures) | ||
| { | ||
| setTextureArray(location, slots, textures, _vertexTextureInfos); | ||
| } | ||
|
|
||
| void Program::setFragmentTextureArray(int location, const std::vector<uint32_t>& slots, const std::vector<Texture*> textures) | ||
| { | ||
| setTextureArray(location, slots, textures, _fragTextureInfos); | ||
| } | ||
|
|
||
| void Program::setTexture(int location, uint32_t slot, Texture* texture, std::vector<TextureInfo>& textureInfo) | ||
| { | ||
| if(location < 0) | ||
| return; | ||
|
|
||
| TextureInfo info; | ||
| info.location = location; | ||
| info.slot = {slot}; | ||
| info.textures = {texture}; | ||
| info.retainTextures(); | ||
| textureInfo.at(location) = info; | ||
| } | ||
|
|
||
| void Program::setTextureArray(int location, const std::vector<uint32_t>& slots, const std::vector<Texture*> textures, std::vector<TextureInfo>& textureInfo) | ||
| { | ||
| assert(slots.size() == textures.size()); | ||
| TextureInfo info; | ||
| info.location = location; | ||
| info.slot = slots; | ||
| info.textures = textures; | ||
| info.retainTextures(); | ||
| textureInfo.at(location) = info; | ||
| } | ||
|
|
||
| CC_BACKEND_END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #pragma once | ||
|
|
||
| #include "Macros.h" | ||
| #include "base/CCRef.h" | ||
| #include "platform/CCPlatformMacros.h" | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| CC_BACKEND_BEGIN | ||
|
|
||
| class ShaderModule; | ||
| class Texture; | ||
|
|
||
| class Program : public Ref | ||
| { | ||
| public: | ||
| struct TextureInfo | ||
| { | ||
| ~TextureInfo(); | ||
|
|
||
| void retainTextures(); | ||
| void releaseTextures(); | ||
|
|
||
| int location = 0; | ||
| std::vector<uint32_t> slot; | ||
| std::vector<Texture*> textures; | ||
| }; | ||
|
|
||
| virtual int getVertexUniformLocation(const std::string& uniform) const = 0; | ||
| virtual int getFragmentUniformLocation(const std::string& uniform) const = 0; | ||
| virtual void setVertexUniform(int location, void* data, uint32_t size) = 0; | ||
| virtual void setFragmentUniform(int location, void* data, uint32_t size) = 0; | ||
| virtual void setVertexTexture(int location, uint32_t slot, Texture* texture); | ||
| virtual void setFragmentTexture(int location, uint32_t slot, Texture* texture); | ||
| virtual void setVertexTextureArray(int location, const std::vector<uint32_t>& slots, const std::vector<Texture*> textures); | ||
| virtual void setFragmentTextureArray(int location, const std::vector<uint32_t>& slots, const std::vector<Texture*> textures); | ||
|
|
||
| inline const std::vector<TextureInfo>& getVertexTextureInfos() const { return _vertexTextureInfos; } | ||
| inline const std::vector<TextureInfo>& getFragmentTextureInfos() const { return _fragTextureInfos; } | ||
|
|
||
| protected: | ||
| Program() = default; | ||
| virtual ~Program(); | ||
|
|
||
| void setTexture(int location, uint32_t slot, Texture* texture, std::vector<TextureInfo>& textureInfo); | ||
| void setTextureArray(int location, const std::vector<uint32_t>& slots, const std::vector<Texture*> textures, std::vector<TextureInfo>& textureInfo); | ||
|
|
||
| std::vector<TextureInfo> _vertexTextureInfos; | ||
| std::vector<TextureInfo> _fragTextureInfos; | ||
| }; | ||
|
|
||
| CC_BACKEND_END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #include "RenderPipeline.h" | ||
| #include "Program.h" | ||
|
|
||
| CC_BACKEND_BEGIN | ||
|
|
||
| RenderPipeline::RenderPipeline(Program* program) | ||
| :_program(program) | ||
| { | ||
| CC_SAFE_RETAIN(_program); | ||
| } | ||
|
|
||
| RenderPipeline::~RenderPipeline() | ||
| { | ||
| CC_SAFE_RELEASE(_program); | ||
| } | ||
|
|
||
| CC_BACKEND_END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,11 +6,17 @@ | |
| #include "base/CCRef.h" | ||
|
|
||
| CC_BACKEND_BEGIN | ||
|
|
||
| class Program; | ||
| class RenderPipeline : public cocos2d::Ref | ||
| { | ||
| public: | ||
| RenderPipeline(Program* program); | ||
| virtual ~RenderPipeline(); | ||
|
|
||
| virtual Program* getProgram() { return _program; } | ||
|
||
|
|
||
| protected: | ||
| virtual ~RenderPipeline() = default; | ||
| Program* _program = nullptr; | ||
| }; | ||
|
|
||
| CC_BACKEND_END | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it need to be public?