mirror of
https://github.com/wiiu-env/NotificationModule.git
synced 2026-10-03 22:36:45 -05:00
First commit
This commit is contained in:
169
src/shaders/ColorShader.cpp
Normal file
169
src/shaders/ColorShader.cpp
Normal file
@@ -0,0 +1,169 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#include "ColorShader.h"
|
||||
|
||||
static const uint32_t cpVertexShaderProgram[] = {
|
||||
0x00000000, 0x00008009, 0x20000000, 0x000078a0,
|
||||
0x3c200000, 0x88060094, 0x00c00000, 0x88062014,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00a11f00, 0xfc00620f, 0x02490001, 0x80000040,
|
||||
0xfd041f80, 0x900c0060, 0x83f9223e, 0x0000803f,
|
||||
0xfe282001, 0x10000040, 0xfe001f80, 0x00080060,
|
||||
0xfeac9f80, 0xfd00624f, 0xdb0f49c0, 0xdb0fc940,
|
||||
0xfea81f80, 0x9000e02f, 0x83f9223e, 0x00000000,
|
||||
0xfe041f80, 0x00370000, 0xffa01f00, 0x80000000,
|
||||
0xff101f00, 0x800c0020, 0x7f041f80, 0x80370000,
|
||||
0x0000103f, 0x00000000, 0x02c51f00, 0x80000000,
|
||||
0xfea41f00, 0x80000020, 0xffa09f00, 0x80000040,
|
||||
0xff001f80, 0x800c0060, 0x398ee33f, 0x0000103f,
|
||||
0x02c41f00, 0x9000e00f, 0x02c59f01, 0x80000020,
|
||||
0xfea81f00, 0x80000040, 0x02c19f80, 0x9000e06f,
|
||||
0x398ee33f, 0x00000000, 0x02c11f01, 0x80000000,
|
||||
0x02c49f80, 0x80000060, 0x02e08f01, 0xfe0c620f,
|
||||
0x02c01f80, 0x7f00622f, 0xfe242000, 0x10000000,
|
||||
0xfe20a080, 0x10000020, 0xf2178647, 0x49c0e9fb,
|
||||
0xfbbdb2ab, 0x768ac733};
|
||||
|
||||
static const uint32_t cpVertexShaderRegs[] = {
|
||||
0x00000103, 0x00000000, 0x00000000, 0x00000001,
|
||||
0xffffff00, 0xffffffff, 0xffffffff, 0xffffffff,
|
||||
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
|
||||
0xffffffff, 0xffffffff, 0x00000000, 0xfffffffc,
|
||||
0x00000002, 0x00000001, 0x00000000, 0x000000ff,
|
||||
0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
|
||||
0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
|
||||
0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
|
||||
0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
|
||||
0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
|
||||
0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
|
||||
0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
|
||||
0x000000ff, 0x00000000, 0x0000000e, 0x00000010};
|
||||
|
||||
static const uint32_t cpPixelShaderProgram[] = {
|
||||
0x20000000, 0x00000ca0, 0x00000000, 0x88062094,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00002000, 0x90000000, 0x0004a000, 0x90000020,
|
||||
0x00082001, 0x90000040, 0x000ca081, 0x90000060,
|
||||
0xbb7dd898, 0x9746c59c, 0xc69b00e7, 0x03c36218};
|
||||
static const uint32_t cpPixelShaderRegs[] = {
|
||||
0x00000001, 0x00000002, 0x14000001, 0x00000000,
|
||||
0x00000001, 0x00000100, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x0000000f, 0x00000001, 0x00000010,
|
||||
0x00000000};
|
||||
|
||||
ColorShader *ColorShader::shaderInstance = nullptr;
|
||||
|
||||
ColorShader::ColorShader()
|
||||
: vertexShader(cuAttributeCount) {
|
||||
//! create pixel shader
|
||||
pixelShader.setProgram(cpPixelShaderProgram, sizeof(cpPixelShaderProgram), cpPixelShaderRegs, sizeof(cpPixelShaderRegs));
|
||||
|
||||
colorIntensityLocation = 0;
|
||||
pixelShader.addUniformVar((GX2UniformVar){
|
||||
"unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, -1});
|
||||
|
||||
//! create vertex shader
|
||||
vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs));
|
||||
|
||||
angleLocation = 0;
|
||||
offsetLocation = 4;
|
||||
scaleLocation = 8;
|
||||
vertexShader.addUniformVar((GX2UniformVar){
|
||||
"unf_angle", GX2_SHADER_VAR_TYPE_FLOAT, 1, angleLocation, -1});
|
||||
vertexShader.addUniformVar((GX2UniformVar){
|
||||
"unf_offset", GX2_SHADER_VAR_TYPE_FLOAT3, 1, offsetLocation, -1});
|
||||
vertexShader.addUniformVar((GX2UniformVar){
|
||||
"unf_scale", GX2_SHADER_VAR_TYPE_FLOAT3, 1, scaleLocation, -1});
|
||||
|
||||
colorLocation = 1;
|
||||
positionLocation = 0;
|
||||
vertexShader.addAttribVar((GX2AttribVar){
|
||||
"attr_color", GX2_SHADER_VAR_TYPE_FLOAT4, 0, colorLocation});
|
||||
vertexShader.addAttribVar((GX2AttribVar){
|
||||
"attr_position", GX2_SHADER_VAR_TYPE_FLOAT3, 0, positionLocation});
|
||||
|
||||
//! setup attribute streams
|
||||
GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32);
|
||||
GX2InitAttribStream(vertexShader.getAttributeBuffer(1), colorLocation, 1, 0, GX2_ATTRIB_FORMAT_UNORM_8_8_8_8);
|
||||
|
||||
//! create fetch shader
|
||||
fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount());
|
||||
|
||||
//! model vertex has to be align and cannot be in unknown regions for GX2 like 0xBCAE1000
|
||||
positionVtxs = (float *) MEMAllocFromMappedMemoryForGX2Ex(cuPositionVtxsSize, GX2_VERTEX_BUFFER_ALIGNMENT);
|
||||
if (positionVtxs) {
|
||||
//! position vertex structure
|
||||
int32_t i = 0;
|
||||
positionVtxs[i++] = -1.0f;
|
||||
positionVtxs[i++] = -1.0f;
|
||||
positionVtxs[i++] = 0.0f;
|
||||
positionVtxs[i++] = 1.0f;
|
||||
positionVtxs[i++] = -1.0f;
|
||||
positionVtxs[i++] = 0.0f;
|
||||
positionVtxs[i++] = 1.0f;
|
||||
positionVtxs[i++] = 1.0f;
|
||||
positionVtxs[i++] = 0.0f;
|
||||
positionVtxs[i++] = -1.0f;
|
||||
positionVtxs[i++] = 1.0f;
|
||||
positionVtxs[i++] = 0.0f;
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, positionVtxs, cuPositionVtxsSize);
|
||||
}
|
||||
}
|
||||
|
||||
ColorShader::~ColorShader() {
|
||||
if (positionVtxs) {
|
||||
MEMFreeToMappedMemory(positionVtxs);
|
||||
positionVtxs = nullptr;
|
||||
}
|
||||
|
||||
delete fetchShader;
|
||||
fetchShader = nullptr;
|
||||
}
|
||||
90
src/shaders/ColorShader.h
Normal file
90
src/shaders/ColorShader.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "FetchShader.h"
|
||||
#include "PixelShader.h"
|
||||
#include "VertexShader.h"
|
||||
|
||||
class ColorShader : public Shader {
|
||||
private:
|
||||
ColorShader();
|
||||
virtual ~ColorShader();
|
||||
|
||||
static const uint32_t cuAttributeCount = 2;
|
||||
static const uint32_t cuPositionVtxsSize = 4 * cuVertexAttrSize;
|
||||
|
||||
static ColorShader *shaderInstance;
|
||||
|
||||
FetchShader *fetchShader;
|
||||
VertexShader vertexShader;
|
||||
PixelShader pixelShader;
|
||||
|
||||
float *positionVtxs;
|
||||
|
||||
uint32_t angleLocation;
|
||||
uint32_t offsetLocation;
|
||||
uint32_t scaleLocation;
|
||||
uint32_t colorLocation;
|
||||
uint32_t colorIntensityLocation;
|
||||
uint32_t positionLocation;
|
||||
|
||||
public:
|
||||
static const uint32_t cuColorVtxsSize = 4 * cuColorAttrSize;
|
||||
|
||||
static ColorShader *instance() {
|
||||
if (!shaderInstance) {
|
||||
shaderInstance = new ColorShader();
|
||||
}
|
||||
return shaderInstance;
|
||||
}
|
||||
static void destroyInstance() {
|
||||
if (shaderInstance) {
|
||||
delete shaderInstance;
|
||||
shaderInstance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void setShaders() const {
|
||||
fetchShader->setShader();
|
||||
vertexShader.setShader();
|
||||
pixelShader.setShader();
|
||||
}
|
||||
|
||||
void setAttributeBuffer(const uint8_t *colorAttr, const float *posVtxs_in = nullptr, const uint32_t &vtxCount = 0) const {
|
||||
if (posVtxs_in && vtxCount) {
|
||||
VertexShader::setAttributeBuffer(0, vtxCount * cuVertexAttrSize, cuVertexAttrSize, posVtxs_in);
|
||||
VertexShader::setAttributeBuffer(1, vtxCount * cuColorAttrSize, cuColorAttrSize, colorAttr);
|
||||
} else {
|
||||
VertexShader::setAttributeBuffer(0, cuPositionVtxsSize, cuVertexAttrSize, positionVtxs);
|
||||
VertexShader::setAttributeBuffer(1, cuColorVtxsSize, cuColorAttrSize, colorAttr);
|
||||
}
|
||||
}
|
||||
|
||||
void setAngle(const float &val) const {
|
||||
VertexShader::setUniformReg(angleLocation, 4, &val);
|
||||
}
|
||||
void setOffset(const glm::vec3 &vec) const {
|
||||
VertexShader::setUniformReg(offsetLocation, 4, &vec[0]);
|
||||
}
|
||||
void setScale(const glm::vec3 &vec) const {
|
||||
VertexShader::setUniformReg(scaleLocation, 4, &vec[0]);
|
||||
}
|
||||
void setColorIntensity(const glm::vec4 &vec) const {
|
||||
PixelShader::setUniformReg(colorIntensityLocation, 4, &vec[0]);
|
||||
}
|
||||
};
|
||||
55
src/shaders/FetchShader.h
Normal file
55
src/shaders/FetchShader.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "Shader.h"
|
||||
#include <malloc.h>
|
||||
#include <memory/mappedmemory.h>
|
||||
|
||||
class FetchShader : public Shader {
|
||||
public:
|
||||
FetchShader(GX2AttribStream *attributes, uint32_t attrCount, GX2FetchShaderType type = GX2_FETCH_SHADER_TESSELLATION_NONE, GX2TessellationMode tess = GX2_TESSELLATION_MODE_DISCRETE)
|
||||
: fetchShader(nullptr), fetchShaderProgramm(nullptr) {
|
||||
uint32_t shaderSize = GX2CalcFetchShaderSizeEx(attrCount, type, tess);
|
||||
fetchShaderProgramm = (uint8_t *) MEMAllocFromMappedMemoryForGX2Ex(shaderSize, GX2_SHADER_PROGRAM_ALIGNMENT);
|
||||
if (fetchShaderProgramm) {
|
||||
fetchShader = (GX2FetchShader *) memalign(0x40, sizeof(GX2FetchShader));
|
||||
GX2InitFetchShaderEx(fetchShader, fetchShaderProgramm, attrCount, attributes, type, tess);
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, fetchShaderProgramm, shaderSize);
|
||||
}
|
||||
}
|
||||
~FetchShader() override {
|
||||
if (fetchShaderProgramm) {
|
||||
MEMFreeToMappedMemory(fetchShaderProgramm);
|
||||
}
|
||||
if (fetchShader) {
|
||||
free(fetchShader);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] GX2FetchShader *getFetchShader() const {
|
||||
return fetchShader;
|
||||
}
|
||||
|
||||
void setShader() const {
|
||||
GX2SetFetchShader(fetchShader);
|
||||
}
|
||||
|
||||
protected:
|
||||
GX2FetchShader *fetchShader;
|
||||
uint8_t *fetchShaderProgramm;
|
||||
};
|
||||
137
src/shaders/PixelShader.h
Normal file
137
src/shaders/PixelShader.h
Normal file
@@ -0,0 +1,137 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "Shader.h"
|
||||
#include <malloc.h>
|
||||
|
||||
class PixelShader : public Shader {
|
||||
public:
|
||||
PixelShader()
|
||||
: pixelShader((GX2PixelShader *) memalign(0x40, sizeof(GX2PixelShader))) {
|
||||
if (pixelShader) {
|
||||
memset(pixelShader, 0, sizeof(GX2PixelShader));
|
||||
pixelShader->mode = GX2_SHADER_MODE_UNIFORM_REGISTER;
|
||||
}
|
||||
}
|
||||
~PixelShader() override {
|
||||
if (pixelShader) {
|
||||
if (pixelShader->program) {
|
||||
MEMFreeToMappedMemory(pixelShader->program);
|
||||
}
|
||||
for (uint32_t i = 0; i < pixelShader->uniformBlockCount; i++) {
|
||||
free((void *) pixelShader->uniformBlocks[i].name);
|
||||
}
|
||||
if (pixelShader->uniformBlocks) {
|
||||
free((void *) pixelShader->uniformBlocks);
|
||||
}
|
||||
for (uint32_t i = 0; i < pixelShader->uniformVarCount; i++) {
|
||||
free((void *) pixelShader->uniformVars[i].name);
|
||||
}
|
||||
if (pixelShader->uniformVars) {
|
||||
free((void *) pixelShader->uniformVars);
|
||||
}
|
||||
if (pixelShader->initialValues) {
|
||||
free((void *) pixelShader->initialValues);
|
||||
}
|
||||
for (uint32_t i = 0; i < pixelShader->samplerVarCount; i++) {
|
||||
free((void *) pixelShader->samplerVars[i].name);
|
||||
}
|
||||
if (pixelShader->samplerVars) {
|
||||
free((void *) pixelShader->samplerVars);
|
||||
}
|
||||
if (pixelShader->loopVars) {
|
||||
free((void *) pixelShader->loopVars);
|
||||
}
|
||||
free(pixelShader);
|
||||
}
|
||||
}
|
||||
|
||||
void setProgram(const uint32_t *program, const uint32_t &programSize, const uint32_t *regs, const uint32_t ®sSize) {
|
||||
if (!pixelShader)
|
||||
return;
|
||||
|
||||
//! this must be moved into an area where the graphic engine has access to and must be aligned to 0x100
|
||||
pixelShader->size = programSize;
|
||||
pixelShader->program = (uint8_t *) MEMAllocFromMappedMemoryForGX2Ex(pixelShader->size, GX2_SHADER_PROGRAM_ALIGNMENT);
|
||||
if (pixelShader->program) {
|
||||
memcpy(pixelShader->program, program, pixelShader->size);
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, pixelShader->program, pixelShader->size);
|
||||
}
|
||||
|
||||
memcpy(&pixelShader->regs, regs, regsSize);
|
||||
}
|
||||
|
||||
void addUniformVar(const GX2UniformVar &var) {
|
||||
if (!pixelShader) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t idx = pixelShader->uniformVarCount;
|
||||
|
||||
auto *newVar = (GX2UniformVar *) memalign(0x40, (pixelShader->uniformVarCount + 1) * sizeof(GX2UniformVar));
|
||||
if (newVar) {
|
||||
if (pixelShader->uniformVars) {
|
||||
memcpy(newVar, pixelShader->uniformVars, pixelShader->uniformVarCount * sizeof(GX2UniformVar));
|
||||
free(pixelShader->uniformVars);
|
||||
}
|
||||
pixelShader->uniformVars = newVar;
|
||||
|
||||
memcpy(pixelShader->uniformVars + idx, &var, sizeof(GX2UniformVar));
|
||||
pixelShader->uniformVars[idx].name = (char *) memalign(0x40, strlen(var.name) + 1);
|
||||
strcpy((char *) pixelShader->uniformVars[idx].name, var.name);
|
||||
|
||||
pixelShader->uniformVarCount++;
|
||||
}
|
||||
}
|
||||
|
||||
void addSamplerVar(const GX2SamplerVar &var) {
|
||||
if (!pixelShader)
|
||||
return;
|
||||
|
||||
uint32_t idx = pixelShader->samplerVarCount;
|
||||
|
||||
auto *newVar = (GX2SamplerVar *) memalign(0x40, (pixelShader->samplerVarCount + 1) * sizeof(GX2SamplerVar));
|
||||
if (newVar) {
|
||||
if (pixelShader->samplerVars) {
|
||||
memcpy(newVar, pixelShader->samplerVars, pixelShader->samplerVarCount * sizeof(GX2SamplerVar));
|
||||
free(pixelShader->samplerVars);
|
||||
}
|
||||
pixelShader->samplerVars = newVar;
|
||||
|
||||
memcpy(pixelShader->samplerVars + idx, &var, sizeof(GX2SamplerVar));
|
||||
pixelShader->samplerVars[idx].name = (char *) memalign(0x40, strlen(var.name) + 1);
|
||||
strcpy((char *) pixelShader->samplerVars[idx].name, var.name);
|
||||
|
||||
pixelShader->samplerVarCount++;
|
||||
}
|
||||
}
|
||||
[[nodiscard]] GX2PixelShader *getPixelShader() const {
|
||||
return pixelShader;
|
||||
}
|
||||
|
||||
void setShader() const {
|
||||
GX2SetPixelShader(pixelShader);
|
||||
}
|
||||
|
||||
static inline void setUniformReg(uint32_t location, uint32_t size, const void *reg) {
|
||||
GX2SetPixelUniformReg(location, size, (uint32_t *) reg);
|
||||
}
|
||||
|
||||
protected:
|
||||
GX2PixelShader *pixelShader;
|
||||
};
|
||||
70
src/shaders/Shader.h
Normal file
70
src/shaders/Shader.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "gx2_ext.h"
|
||||
#pragma GCC diagnostic ignored "-Wvolatile"
|
||||
#include <glm/glm.hpp>
|
||||
#include <gx2/draw.h>
|
||||
#include <gx2/enum.h>
|
||||
#include <gx2/mem.h>
|
||||
#include <gx2/registers.h>
|
||||
#include <gx2/shaders.h>
|
||||
#include <gx2/texture.h>
|
||||
#include <memory/mappedmemory.h>
|
||||
|
||||
class Shader {
|
||||
protected:
|
||||
Shader() = default;
|
||||
virtual ~Shader() = default;
|
||||
|
||||
public:
|
||||
static const uint16_t cuVertexAttrSize = sizeof(float) * 3;
|
||||
static const uint16_t cuTexCoordAttrSize = sizeof(float) * 2;
|
||||
static const uint16_t cuColorAttrSize = sizeof(uint8_t) * 4;
|
||||
|
||||
static void setLineWidth(const float &width) {
|
||||
GX2SetLineWidth(width);
|
||||
}
|
||||
|
||||
static void draw(int32_t primitive = GX2_PRIMITIVE_MODE_QUADS, uint32_t vtxCount = 4) {
|
||||
switch (primitive) {
|
||||
default:
|
||||
case GX2_PRIMITIVE_MODE_QUADS: {
|
||||
GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, vtxCount, 0, 1);
|
||||
break;
|
||||
}
|
||||
case GX2_PRIMITIVE_MODE_TRIANGLES: {
|
||||
GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLES, vtxCount, 0, 1);
|
||||
break;
|
||||
}
|
||||
case GX2_PRIMITIVE_MODE_TRIANGLE_FAN: {
|
||||
GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLE_FAN, vtxCount, 0, 1);
|
||||
break;
|
||||
}
|
||||
case GX2_PRIMITIVE_MODE_LINES: {
|
||||
GX2DrawEx(GX2_PRIMITIVE_MODE_LINES, vtxCount, 0, 1);
|
||||
break;
|
||||
}
|
||||
case GX2_PRIMITIVE_MODE_LINE_STRIP: {
|
||||
GX2DrawEx(GX2_PRIMITIVE_MODE_LINE_STRIP, vtxCount, 0, 1);
|
||||
break;
|
||||
}
|
||||
//! TODO: add other primitives later
|
||||
};
|
||||
}
|
||||
};
|
||||
279
src/shaders/Texture2DShader.cpp
Normal file
279
src/shaders/Texture2DShader.cpp
Normal file
@@ -0,0 +1,279 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#include "Texture2DShader.h"
|
||||
|
||||
static const uint32_t cpVertexShaderProgram[] = {
|
||||
0x00000000, 0x00008009, 0x20000000, 0x000080a0,
|
||||
0x3c200100, 0x88060094, 0x00400000, 0x88042014,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x02290001, 0x80000000, 0x02041f00, 0x900c0020,
|
||||
0x00a11f00, 0xfc00624f, 0xfd041f00, 0x900c4060,
|
||||
0x02001f80, 0x900c0000, 0x83f9223e, 0x0000803f,
|
||||
0xfe081f00, 0x00080020, 0xfe202081, 0x10004040,
|
||||
0xfea49f80, 0xfd00620f, 0xdb0f49c0, 0xdb0fc940,
|
||||
0xfea01f80, 0x9000e06f, 0x83f9223e, 0x00000000,
|
||||
0xfe0c1f80, 0x00370000, 0xffa01f00, 0x80000040,
|
||||
0xff101f00, 0x800c0060, 0x7f0c1f80, 0x80370040,
|
||||
0x0000103f, 0x00000000, 0xffa01f00, 0x80000000,
|
||||
0xff001f00, 0x800c0020, 0x02c51f01, 0x80000040,
|
||||
0xfeac9f80, 0x80000060, 0x0000103f, 0x398ee33f,
|
||||
0xfea01f00, 0x80000000, 0x02c19f01, 0x9000e02f,
|
||||
0x01c41f01, 0x9000e04f, 0x02c59f80, 0x80000060,
|
||||
0x398ee33f, 0x00000000, 0x01c49f01, 0x80000020,
|
||||
0x02c11f80, 0x80000040, 0x01e08f00, 0xfe04624f,
|
||||
0x01c01f81, 0x7f08626f, 0xfe2c2000, 0x10004000,
|
||||
0xfe28a080, 0x10004020, 0xeb825790, 0xb6f711be,
|
||||
0x7c0e2df2, 0x81173cfa};
|
||||
|
||||
static const uint32_t cpVertexShaderRegs[] = {
|
||||
0x00000103, 0x00000000, 0x00000000, 0x00000001,
|
||||
0xffffff00, 0xffffffff, 0xffffffff, 0xffffffff,
|
||||
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
|
||||
0xffffffff, 0xffffffff, 0x00000000, 0xfffffffc,
|
||||
0x00000002, 0x00000000, 0x00000001, 0x000000ff,
|
||||
0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
|
||||
0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
|
||||
0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
|
||||
0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
|
||||
0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
|
||||
0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
|
||||
0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
|
||||
0x000000ff, 0x00000000, 0x0000000e, 0x00000010};
|
||||
|
||||
static const uint32_t cPixelShaderProgram[] = {
|
||||
0x20000000, 0x00000ca4, 0x0b000000, 0x00000085,
|
||||
0x24000000, 0x000050a0, 0xb0000000, 0x000cc080,
|
||||
0x39000000, 0x00005ca0, 0xb8000000, 0x000cc080,
|
||||
0x51000000, 0x000078a0, 0xc0000000, 0x000cc080,
|
||||
0x70000000, 0x000064a0, 0xc8000000, 0x0008c080,
|
||||
0x8a000000, 0x00005ca0, 0x0e000000, 0x01008086,
|
||||
0xce000000, 0x0000c080, 0xa2000000, 0x00000ca8,
|
||||
0x00800000, 0x88062094, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00051f00, 0x80060000, 0x00011f80, 0x80060040,
|
||||
0xfec81f80, 0xfb802320, 0x01041f80, 0x8c220000,
|
||||
0x00a41f00, 0xfc10620f, 0x010d1f00, 0x900c0021,
|
||||
0x00091f00, 0x80060040, 0x00a01f80, 0xfc10626f,
|
||||
0x00000040, 0x00000000, 0xfe080000, 0xfe8cc300,
|
||||
0xfe088080, 0xfe80c320, 0x00a11f00, 0xfe000200,
|
||||
0x00a51f00, 0xfe040220, 0x00a19f00, 0xfe000240,
|
||||
0x00a59f00, 0xfe040260, 0x00a11f81, 0xfe002600,
|
||||
0x4260e5bc, 0xa69bc4bc, 0x0ad7a3bc, 0x00000000,
|
||||
0x00a11f00, 0x06004200, 0x00a59f00, 0x06042220,
|
||||
0x00a51f00, 0x06044240, 0x00a11f01, 0x06008260,
|
||||
0x00a51f81, 0x06048620, 0x6f1283bc, 0x0ad7a3bc,
|
||||
0xa69b44bc, 0x00000000, 0x00a41f00, 0x80000000,
|
||||
0x00a01f00, 0x80000020, 0x00ac1f00, 0x80000040,
|
||||
0x00a81f00, 0x80000060, 0x00a19f80, 0x06000600,
|
||||
0xcac3123c, 0x6f1203bc, 0x03a41f00, 0xfe00620f,
|
||||
0x03a01f00, 0xfe04622f, 0x03ac1f00, 0xfe08624f,
|
||||
0x03a81f00, 0xfe0c626f, 0x00a59f80, 0x06040620,
|
||||
0xcc28913b, 0x6f1203bc, 0x01a41f00, 0xfe00620f,
|
||||
0x01a01f00, 0xfe04622f, 0x01ac1f00, 0xfe08624f,
|
||||
0x01a81f00, 0xfe0c626f, 0x00a19f80, 0x06002600,
|
||||
0xe8eab03c, 0x6f1283bb, 0x02ac1f00, 0xfe084200,
|
||||
0x02a81f00, 0xfe0c4220, 0x02a41f00, 0xfe004240,
|
||||
0x02a01f00, 0xfe044260, 0x00a59f80, 0x06042620,
|
||||
0x92bb353d, 0x6f1283bb, 0x04a81f00, 0x0204620f,
|
||||
0x04ac1f00, 0x0200662f, 0x04a41f00, 0x0208624f,
|
||||
0x04a01f00, 0x020c626f, 0x00a19f80, 0x06004600,
|
||||
0xc4139f3d, 0x6f12833b, 0x00a41f00, 0xfe08620f,
|
||||
0x00a01f00, 0xfe0c622f, 0x00ac1f00, 0xfe04624f,
|
||||
0x00a81f00, 0xfe00626f, 0x00a59f80, 0x06044620,
|
||||
0xb950ed3d, 0x6f12833b, 0x01a41f00, 0xfe00620f,
|
||||
0x01a01f00, 0xfe04622f, 0x01ac1f00, 0xfe08624f,
|
||||
0x01a81f00, 0xfe0c626f, 0x00a19f80, 0x06002600,
|
||||
0xecd7163e, 0x6f12033c, 0x03a41f00, 0xfe000200,
|
||||
0x03a01f00, 0xfe040220, 0x03ac1f00, 0xfe082240,
|
||||
0x03a81f00, 0xfe0c2260, 0x00a59f80, 0x06042620,
|
||||
0x2168233e, 0x6f12033c, 0x00a11f00, 0x06006200,
|
||||
0x00a51f00, 0x06046220, 0x00a19f00, 0x06006240,
|
||||
0x00a59f00, 0x06046260, 0x00a11f81, 0x0600e600,
|
||||
0xa69b443c, 0x6f12833c, 0x0ad7a33c, 0x00000000,
|
||||
0x02ac1f00, 0x0108620f, 0x02a81f00, 0x010c622f,
|
||||
0x02a41f00, 0x0000624f, 0x02a01f00, 0x0004666f,
|
||||
0x00a59f80, 0x0604e620, 0xecd7163e, 0x0ad7a33c,
|
||||
0x04a81f00, 0xfe04620f, 0x04ac1f00, 0xfe00622f,
|
||||
0x04a41f00, 0xfe08624f, 0x04a01f00, 0xfe0c626f,
|
||||
0x00a19f80, 0x06008600, 0xb950ed3d, 0xa69bc43c,
|
||||
0x05a41f00, 0xfe08620f, 0x05a01f00, 0xfe0c622f,
|
||||
0x05ac1f00, 0xfe04624f, 0x05a81f00, 0xfe00626f,
|
||||
0x00a59f80, 0x06048620, 0xc4139f3d, 0xa69bc43c,
|
||||
0x03a41f00, 0xfe00a200, 0x03a01f00, 0xfe04a220,
|
||||
0x03ac1f00, 0xfe086240, 0x03a81f00, 0xfe0c6260,
|
||||
0x00a19f80, 0x06006600, 0x92bb353d, 0x4260e53c,
|
||||
0x00a51f80, 0x06046220, 0x4260e53c, 0x00000000,
|
||||
0x07ac1f00, 0x0308620f, 0x07a81f00, 0x030c622f,
|
||||
0x07a41f00, 0x0500624f, 0x07a01f80, 0x0504626f,
|
||||
0xe8eab03c, 0x00000000, 0x04a81f00, 0xfe04620f,
|
||||
0x04ac1f00, 0xfe00622f, 0x04a41f00, 0xfe08624f,
|
||||
0x04a01f80, 0xfe0c626f, 0xcac3123c, 0x00000000,
|
||||
0x06a41f00, 0xfe08620f, 0x06a01f00, 0xfe0c622f,
|
||||
0x06ac1f00, 0xfe04624f, 0x06a81f80, 0xfe00626f,
|
||||
0xcc28913b, 0x00000000, 0xfe20a000, 0x9000e00f,
|
||||
0xfe242000, 0x9000e02f, 0xfe28a001, 0x9000e04f,
|
||||
0xfe2c2081, 0x9000e06f, 0xfe28a081, 0x80060020,
|
||||
0xfee48f00, 0x7f842300, 0xfee40f00, 0x7f802320,
|
||||
0xfee48f01, 0x7f8c2340, 0xfee40f81, 0x08842b60,
|
||||
0x00202000, 0x90002000, 0x0024a000, 0x90002020,
|
||||
0x00282001, 0x90002040, 0x002ca081, 0x90002060,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x10000000, 0x03100df0, 0x00008010, 0xecdfea0d,
|
||||
0x10000000, 0x00100df0, 0x0000a051, 0xecdfea0d,
|
||||
0x10000100, 0x01100df0, 0x00008010, 0xecdfea0d,
|
||||
0x10000200, 0x02100df0, 0x00000011, 0xecdfea0d,
|
||||
0x10000400, 0x04100df0, 0x0000b070, 0xecdfea0d,
|
||||
0x10000000, 0x00100df0, 0x00008010, 0xecdfea0d,
|
||||
0x10000100, 0x01100df0, 0x00008010, 0xecdfea0d,
|
||||
0x10000600, 0x03100df0, 0x00008010, 0xecdfea0d,
|
||||
0x10000200, 0x02100df0, 0x00008010, 0xecdfea0d,
|
||||
0x10000100, 0x04100df0, 0x00008010, 0xecdfea0d,
|
||||
0x10000300, 0x05100df0, 0x00008010, 0xecdfea0d,
|
||||
0x10000300, 0x03100df0, 0x0000a051, 0xecdfea0d,
|
||||
0x10000700, 0x07100df0, 0x00008010, 0xecdfea0d,
|
||||
0x10000400, 0x04100df0, 0x00008010, 0xecdfea0d,
|
||||
0x10000300, 0x06100df0, 0x00008010, 0xecdfea0d,
|
||||
0x10000000, 0x00100df0, 0x00008010, 0xecdfea0d,
|
||||
0xc8581837, 0x22740275, 0x281eddcc, 0xfa8b9b65};
|
||||
static const uint32_t cPixelShaderRegs[] = {
|
||||
0x00000109, 0x00000002, 0x14000001, 0x00000000,
|
||||
0x00000001, 0x00000100, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x0000000f, 0x00000001, 0x00000010,
|
||||
0x00000000};
|
||||
|
||||
Texture2DShader *Texture2DShader::shaderInstance = nullptr;
|
||||
|
||||
Texture2DShader::Texture2DShader()
|
||||
: vertexShader(cuAttributeCount) {
|
||||
//! create pixel shader
|
||||
pixelShader.setProgram(cPixelShaderProgram, sizeof(cPixelShaderProgram), cPixelShaderRegs, sizeof(cPixelShaderRegs));
|
||||
|
||||
blurLocation = 0;
|
||||
colorIntensityLocation = 4;
|
||||
pixelShader.addUniformVar((GX2UniformVar){
|
||||
"unf_blur_texture_direction", GX2_SHADER_VAR_TYPE_FLOAT3, 1, blurLocation, -1});
|
||||
pixelShader.addUniformVar((GX2UniformVar){
|
||||
"unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, -1});
|
||||
|
||||
samplerLocation = 0;
|
||||
pixelShader.addSamplerVar((GX2SamplerVar){
|
||||
"sampl_texture", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, samplerLocation});
|
||||
|
||||
//! create vertex shader
|
||||
vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs));
|
||||
|
||||
angleLocation = 0;
|
||||
offsetLocation = 4;
|
||||
scaleLocation = 8;
|
||||
vertexShader.addUniformVar((GX2UniformVar){
|
||||
"unf_angle", GX2_SHADER_VAR_TYPE_FLOAT, 1, angleLocation, -1});
|
||||
vertexShader.addUniformVar((GX2UniformVar){
|
||||
"unf_offset", GX2_SHADER_VAR_TYPE_FLOAT3, 1, offsetLocation, -1});
|
||||
vertexShader.addUniformVar((GX2UniformVar){
|
||||
"unf_scale", GX2_SHADER_VAR_TYPE_FLOAT3, 1, scaleLocation, -1});
|
||||
|
||||
positionLocation = 0;
|
||||
texCoordLocation = 1;
|
||||
vertexShader.addAttribVar((GX2AttribVar){
|
||||
"attr_position", GX2_SHADER_VAR_TYPE_FLOAT3, 0, positionLocation});
|
||||
vertexShader.addAttribVar((GX2AttribVar){
|
||||
"attr_texture_coord", GX2_SHADER_VAR_TYPE_FLOAT2, 0, texCoordLocation});
|
||||
|
||||
//! setup attribute streams
|
||||
GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32);
|
||||
GX2InitAttribStream(vertexShader.getAttributeBuffer(1), texCoordLocation, 1, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32);
|
||||
|
||||
//! create fetch shader
|
||||
fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount());
|
||||
|
||||
//! model vertex and texture coords have to be align and cannot be in unknown regions for GX2 like 0xBCAE1000
|
||||
posVtxs = (float *) MEMAllocFromMappedMemoryForGX2Ex(ciPositionVtxsSize, GX2_VERTEX_BUFFER_ALIGNMENT);
|
||||
texCoords = (float *) MEMAllocFromMappedMemoryForGX2Ex(ciTexCoordsVtxsSize, GX2_VERTEX_BUFFER_ALIGNMENT);
|
||||
|
||||
//! defaults for normal square
|
||||
//! position vertex structure and texture coordinate vertex structure
|
||||
int32_t i = 0;
|
||||
posVtxs[i++] = -1.0f;
|
||||
posVtxs[i++] = -1.0f;
|
||||
posVtxs[i++] = 0.0f;
|
||||
posVtxs[i++] = 1.0f;
|
||||
posVtxs[i++] = -1.0f;
|
||||
posVtxs[i++] = 0.0f;
|
||||
posVtxs[i++] = 1.0f;
|
||||
posVtxs[i++] = 1.0f;
|
||||
posVtxs[i++] = 0.0f;
|
||||
posVtxs[i++] = -1.0f;
|
||||
posVtxs[i++] = 1.0f;
|
||||
posVtxs[i++] = 0.0f;
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, posVtxs, ciPositionVtxsSize);
|
||||
|
||||
i = 0;
|
||||
texCoords[i++] = 0.0f;
|
||||
texCoords[i++] = 1.0f;
|
||||
texCoords[i++] = 1.0f;
|
||||
texCoords[i++] = 1.0f;
|
||||
texCoords[i++] = 1.0f;
|
||||
texCoords[i++] = 0.0f;
|
||||
texCoords[i++] = 0.0f;
|
||||
texCoords[i++] = 0.0f;
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, texCoords, ciTexCoordsVtxsSize);
|
||||
}
|
||||
|
||||
Texture2DShader::~Texture2DShader() {
|
||||
if (posVtxs) {
|
||||
MEMFreeToMappedMemory(posVtxs);
|
||||
posVtxs = nullptr;
|
||||
}
|
||||
if (texCoords) {
|
||||
MEMFreeToMappedMemory(texCoords);
|
||||
texCoords = nullptr;
|
||||
}
|
||||
|
||||
delete fetchShader;
|
||||
fetchShader = nullptr;
|
||||
}
|
||||
104
src/shaders/Texture2DShader.h
Normal file
104
src/shaders/Texture2DShader.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#ifndef __TEXTURE_2D_SHADER_H_
|
||||
#define __TEXTURE_2D_SHADER_H_
|
||||
|
||||
#include "FetchShader.h"
|
||||
#include "PixelShader.h"
|
||||
#include "VertexShader.h"
|
||||
|
||||
|
||||
class Texture2DShader : public Shader {
|
||||
private:
|
||||
Texture2DShader();
|
||||
virtual ~Texture2DShader();
|
||||
|
||||
static const uint32_t cuAttributeCount = 2;
|
||||
static const uint32_t ciPositionVtxsSize = 4 * cuVertexAttrSize;
|
||||
static const uint32_t ciTexCoordsVtxsSize = 4 * cuTexCoordAttrSize;
|
||||
|
||||
static Texture2DShader *shaderInstance;
|
||||
|
||||
FetchShader *fetchShader;
|
||||
VertexShader vertexShader;
|
||||
PixelShader pixelShader;
|
||||
|
||||
float *posVtxs;
|
||||
float *texCoords;
|
||||
|
||||
uint32_t angleLocation;
|
||||
uint32_t offsetLocation;
|
||||
uint32_t scaleLocation;
|
||||
uint32_t colorIntensityLocation;
|
||||
uint32_t blurLocation;
|
||||
uint32_t samplerLocation;
|
||||
uint32_t positionLocation;
|
||||
uint32_t texCoordLocation;
|
||||
|
||||
public:
|
||||
static Texture2DShader *instance() {
|
||||
if (!shaderInstance) {
|
||||
shaderInstance = new Texture2DShader();
|
||||
}
|
||||
return shaderInstance;
|
||||
}
|
||||
static void destroyInstance() {
|
||||
if (shaderInstance) {
|
||||
delete shaderInstance;
|
||||
shaderInstance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void setShaders() const {
|
||||
fetchShader->setShader();
|
||||
vertexShader.setShader();
|
||||
pixelShader.setShader();
|
||||
}
|
||||
|
||||
void setAttributeBuffer(const float *texCoords_in = nullptr, const float *posVtxs_in = nullptr, const uint32_t &vtxCount = 0) const {
|
||||
if (posVtxs_in && texCoords_in && vtxCount) {
|
||||
VertexShader::setAttributeBuffer(0, vtxCount * cuVertexAttrSize, cuVertexAttrSize, posVtxs_in);
|
||||
VertexShader::setAttributeBuffer(1, vtxCount * cuTexCoordAttrSize, cuTexCoordAttrSize, texCoords_in);
|
||||
} else {
|
||||
VertexShader::setAttributeBuffer(0, ciPositionVtxsSize, cuVertexAttrSize, posVtxs);
|
||||
VertexShader::setAttributeBuffer(1, ciTexCoordsVtxsSize, cuTexCoordAttrSize, texCoords);
|
||||
}
|
||||
}
|
||||
|
||||
void setAngle(const float &val) {
|
||||
VertexShader::setUniformReg(angleLocation, 4, &val);
|
||||
}
|
||||
void setOffset(const glm::vec3 &vec) {
|
||||
VertexShader::setUniformReg(offsetLocation, 4, &vec[0]);
|
||||
}
|
||||
void setScale(const glm::vec3 &vec) {
|
||||
VertexShader::setUniformReg(scaleLocation, 4, &vec[0]);
|
||||
}
|
||||
void setColorIntensity(const glm::vec4 &vec) {
|
||||
PixelShader::setUniformReg(colorIntensityLocation, 4, &vec[0]);
|
||||
}
|
||||
void setBlurring(const glm::vec3 &vec) {
|
||||
PixelShader::setUniformReg(blurLocation, 4, &vec[0]);
|
||||
}
|
||||
|
||||
void setTextureAndSampler(const GX2Texture *texture, const GX2Sampler *sampler) const {
|
||||
GX2SetPixelTexture((GX2Texture *) texture, samplerLocation);
|
||||
GX2SetPixelSampler((GX2Sampler *) sampler, samplerLocation);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // __TEXTURE_2D_SHADER_H_
|
||||
164
src/shaders/VertexShader.h
Normal file
164
src/shaders/VertexShader.h
Normal file
@@ -0,0 +1,164 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "Shader.h"
|
||||
#include <cstring>
|
||||
#include <gx2/enum.h>
|
||||
|
||||
class VertexShader : public Shader {
|
||||
public:
|
||||
explicit VertexShader(uint32_t numAttr)
|
||||
: attributesCount(numAttr), attributes((GX2AttribStream *) memalign(0x40, sizeof(GX2AttribStream) * attributesCount)), vertexShader((GX2VertexShader *) memalign(0x40, sizeof(GX2VertexShader))) {
|
||||
if (vertexShader) {
|
||||
memset(vertexShader, 0, sizeof(GX2VertexShader));
|
||||
vertexShader->mode = GX2_SHADER_MODE_UNIFORM_REGISTER;
|
||||
}
|
||||
}
|
||||
|
||||
~VertexShader() override {
|
||||
free(attributes);
|
||||
|
||||
if (vertexShader) {
|
||||
if (vertexShader->program) {
|
||||
MEMFreeToMappedMemory(vertexShader->program);
|
||||
}
|
||||
for (uint32_t i = 0; i < vertexShader->uniformBlockCount; i++) {
|
||||
free((void *) vertexShader->uniformBlocks[i].name);
|
||||
}
|
||||
if (vertexShader->uniformBlocks) {
|
||||
free((void *) vertexShader->uniformBlocks);
|
||||
}
|
||||
for (uint32_t i = 0; i < vertexShader->uniformVarCount; i++) {
|
||||
free((void *) vertexShader->uniformVars[i].name);
|
||||
}
|
||||
if (vertexShader->uniformVars) {
|
||||
free((void *) vertexShader->uniformVars);
|
||||
}
|
||||
if (vertexShader->initialValues) {
|
||||
free((void *) vertexShader->initialValues);
|
||||
}
|
||||
for (uint32_t i = 0; i < vertexShader->samplerVarCount; i++) {
|
||||
free((void *) vertexShader->samplerVars[i].name);
|
||||
}
|
||||
if (vertexShader->samplerVars) {
|
||||
free((void *) vertexShader->samplerVars);
|
||||
}
|
||||
for (uint32_t i = 0; i < vertexShader->attribVarCount; i++) {
|
||||
free((void *) vertexShader->attribVars[i].name);
|
||||
}
|
||||
if (vertexShader->attribVars) {
|
||||
free((void *) vertexShader->attribVars);
|
||||
}
|
||||
if (vertexShader->loopVars) {
|
||||
free((void *) vertexShader->loopVars);
|
||||
}
|
||||
|
||||
free(vertexShader);
|
||||
}
|
||||
}
|
||||
|
||||
void setProgram(const uint32_t *program, const uint32_t &programSize, const uint32_t *regs, const uint32_t ®sSize) {
|
||||
if (!vertexShader)
|
||||
return;
|
||||
|
||||
//! this must be moved into an area where the graphic engine has access to and must be aligned to 0x100
|
||||
vertexShader->size = programSize;
|
||||
vertexShader->program = (uint8_t *) MEMAllocFromMappedMemoryForGX2Ex(vertexShader->size, GX2_SHADER_PROGRAM_ALIGNMENT);
|
||||
if (vertexShader->program) {
|
||||
memcpy(vertexShader->program, program, vertexShader->size);
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, vertexShader->program, vertexShader->size);
|
||||
}
|
||||
|
||||
memcpy(&vertexShader->regs, regs, regsSize);
|
||||
}
|
||||
|
||||
void addUniformVar(const GX2UniformVar &var) {
|
||||
if (!vertexShader)
|
||||
return;
|
||||
|
||||
uint32_t idx = vertexShader->uniformVarCount;
|
||||
|
||||
auto *newVar = (GX2UniformVar *) memalign(0x40, (vertexShader->uniformVarCount + 1) * sizeof(GX2UniformVar));
|
||||
if (newVar) {
|
||||
if (vertexShader->uniformVarCount > 0) {
|
||||
memcpy(newVar, vertexShader->uniformVars, vertexShader->uniformVarCount * sizeof(GX2UniformVar));
|
||||
free(vertexShader->uniformVars);
|
||||
}
|
||||
vertexShader->uniformVars = newVar;
|
||||
|
||||
memcpy(vertexShader->uniformVars + idx, &var, sizeof(GX2UniformVar));
|
||||
vertexShader->uniformVars[idx].name = (char *) memalign(0x40, strlen(var.name) + 1);
|
||||
strcpy((char *) vertexShader->uniformVars[idx].name, var.name);
|
||||
|
||||
vertexShader->uniformVarCount++;
|
||||
}
|
||||
}
|
||||
|
||||
void addAttribVar(const GX2AttribVar &var) {
|
||||
if (!vertexShader)
|
||||
return;
|
||||
|
||||
uint32_t idx = vertexShader->attribVarCount;
|
||||
|
||||
auto *newVar = (GX2AttribVar *) memalign(0x40, (vertexShader->attribVarCount + 1) * sizeof(GX2AttribVar));
|
||||
if (newVar) {
|
||||
if (vertexShader->attribVarCount > 0) {
|
||||
memcpy(newVar, vertexShader->attribVars, vertexShader->attribVarCount * sizeof(GX2AttribVar));
|
||||
free(vertexShader->attribVars);
|
||||
}
|
||||
vertexShader->attribVars = newVar;
|
||||
|
||||
memcpy(vertexShader->attribVars + idx, &var, sizeof(GX2AttribVar));
|
||||
vertexShader->attribVars[idx].name = (char *) memalign(0x40, strlen(var.name) + 1);
|
||||
strcpy((char *) vertexShader->attribVars[idx].name, var.name);
|
||||
|
||||
vertexShader->attribVarCount++;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void setAttributeBuffer(uint32_t bufferIdx, uint32_t bufferSize, uint32_t stride, const void *buffer) {
|
||||
GX2SetAttribBuffer(bufferIdx, bufferSize, stride, (void *) buffer);
|
||||
}
|
||||
|
||||
[[nodiscard]] GX2VertexShader *getVertexShader() const {
|
||||
return vertexShader;
|
||||
}
|
||||
|
||||
void setShader() const {
|
||||
GX2SetVertexShader(vertexShader);
|
||||
}
|
||||
|
||||
[[nodiscard]] GX2AttribStream *getAttributeBuffer(uint32_t idx = 0) const {
|
||||
if (idx >= attributesCount) {
|
||||
return nullptr;
|
||||
}
|
||||
return &attributes[idx];
|
||||
}
|
||||
[[nodiscard]] uint32_t getAttributesCount() const {
|
||||
return attributesCount;
|
||||
}
|
||||
|
||||
static void setUniformReg(uint32_t location, uint32_t size, const void *reg) {
|
||||
GX2SetVertexUniformReg(location, size, (uint32_t *) reg);
|
||||
}
|
||||
|
||||
protected:
|
||||
uint32_t attributesCount;
|
||||
GX2AttribStream *attributes;
|
||||
GX2VertexShader *vertexShader;
|
||||
};
|
||||
162
src/shaders/gx2_ext.h
Normal file
162
src/shaders/gx2_ext.h
Normal file
@@ -0,0 +1,162 @@
|
||||
#pragma once
|
||||
|
||||
#include <gx2/utils.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <coreinit/cache.h>
|
||||
#include <gx2/draw.h>
|
||||
#include <gx2/enum.h>
|
||||
#include <gx2/mem.h>
|
||||
#include <gx2/registers.h>
|
||||
#include <gx2/sampler.h>
|
||||
#include <gx2/shaders.h>
|
||||
#include <gx2/surface.h>
|
||||
#include <gx2/texture.h>
|
||||
|
||||
#define GX2_AA_BUFFER_CLEAR_VALUE 0xCC
|
||||
|
||||
#define GX2_COMP_SEL_NONE 0x04040405
|
||||
#define GX2_COMP_SEL_X001 0x00040405
|
||||
#define GX2_COMP_SEL_XY01 0x00010405
|
||||
#define GX2_COMP_SEL_XYZ1 0x00010205
|
||||
#define GX2_COMP_SEL_XYZW 0x00010203
|
||||
#define GX2_COMP_SEL_XXXX 0x00000000
|
||||
#define GX2_COMP_SEL_YYYY 0x01010101
|
||||
#define GX2_COMP_SEL_ZZZZ 0x02020202
|
||||
#define GX2_COMP_SEL_WWWW 0x03030303
|
||||
#define GX2_COMP_SEL_WZYX 0x03020100
|
||||
#define GX2_COMP_SEL_WXYZ 0x03000102
|
||||
|
||||
typedef struct _GX2Color {
|
||||
uint8_t r, g, b, a;
|
||||
} GX2Color;
|
||||
|
||||
typedef struct _GX2ColorF32 {
|
||||
float r, g, b, a;
|
||||
} GX2ColorF32;
|
||||
|
||||
static const uint32_t attribute_dest_comp_selector[20] = {
|
||||
GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001,
|
||||
GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW,
|
||||
GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1,
|
||||
GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW};
|
||||
|
||||
static const uint32_t texture_comp_selector[54] = {
|
||||
GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001,
|
||||
GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW,
|
||||
GX2_COMP_SEL_WZYX, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE,
|
||||
GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE,
|
||||
GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_WZYX, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01,
|
||||
GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW,
|
||||
GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_X001,
|
||||
GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1,
|
||||
GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01};
|
||||
|
||||
static inline void GX2InitDepthBuffer(GX2DepthBuffer *depthBuffer, GX2SurfaceDim dim, uint32_t width, uint32_t height, uint32_t depth, GX2SurfaceFormat format, GX2AAMode aa) {
|
||||
depthBuffer->surface.dim = dim;
|
||||
depthBuffer->surface.width = width;
|
||||
depthBuffer->surface.height = height;
|
||||
depthBuffer->surface.depth = depth;
|
||||
depthBuffer->surface.mipLevels = 1;
|
||||
depthBuffer->surface.format = format;
|
||||
depthBuffer->surface.aa = aa;
|
||||
depthBuffer->surface.use = (GX2SurfaceUse) (((format == GX2_SURFACE_FORMAT_UNORM_R24_X8) || (format == GX2_SURFACE_FORMAT_FLOAT_D24_S8)) ? GX2_SURFACE_USE_DEPTH_BUFFER : (GX2_SURFACE_USE_DEPTH_BUFFER | GX2_SURFACE_USE_TEXTURE));
|
||||
depthBuffer->surface.tileMode = GX2_TILE_MODE_DEFAULT;
|
||||
depthBuffer->surface.swizzle = 0;
|
||||
depthBuffer->viewMip = 0;
|
||||
depthBuffer->viewFirstSlice = 0;
|
||||
depthBuffer->viewNumSlices = depth;
|
||||
depthBuffer->depthClear = 1.0f;
|
||||
depthBuffer->stencilClear = 0;
|
||||
depthBuffer->hiZPtr = nullptr;
|
||||
depthBuffer->hiZSize = 0;
|
||||
GX2CalcSurfaceSizeAndAlignment(&depthBuffer->surface);
|
||||
GX2InitDepthBufferRegs(depthBuffer);
|
||||
}
|
||||
|
||||
static inline void GX2InitColorBuffer(GX2ColorBuffer *colorBuffer, GX2SurfaceDim dim, uint32_t width, uint32_t height, uint32_t depth, GX2SurfaceFormat format, GX2AAMode aa, GX2TileMode tilemode, uint32_t swizzle,
|
||||
void *aaBuffer, uint32_t aaSize) {
|
||||
colorBuffer->surface.dim = dim;
|
||||
colorBuffer->surface.width = width;
|
||||
colorBuffer->surface.height = height;
|
||||
colorBuffer->surface.depth = depth;
|
||||
colorBuffer->surface.mipLevels = 1;
|
||||
colorBuffer->surface.format = format;
|
||||
colorBuffer->surface.aa = aa;
|
||||
colorBuffer->surface.use = GX2_SURFACE_USE_TEXTURE_COLOR_BUFFER_TV;
|
||||
colorBuffer->surface.imageSize = 0;
|
||||
colorBuffer->surface.image = nullptr;
|
||||
colorBuffer->surface.mipmapSize = 0;
|
||||
colorBuffer->surface.mipmaps = nullptr;
|
||||
colorBuffer->surface.tileMode = tilemode;
|
||||
colorBuffer->surface.swizzle = swizzle;
|
||||
colorBuffer->surface.alignment = 0;
|
||||
colorBuffer->surface.pitch = 0;
|
||||
uint32_t i;
|
||||
for (i = 0; i < 13; i++)
|
||||
colorBuffer->surface.mipLevelOffset[i] = 0;
|
||||
colorBuffer->viewMip = 0;
|
||||
colorBuffer->viewFirstSlice = 0;
|
||||
colorBuffer->viewNumSlices = depth;
|
||||
colorBuffer->aaBuffer = aaBuffer;
|
||||
colorBuffer->aaSize = aaSize;
|
||||
for (i = 0; i < 5; i++)
|
||||
colorBuffer->regs[i] = 0;
|
||||
|
||||
GX2CalcSurfaceSizeAndAlignment(&colorBuffer->surface);
|
||||
GX2InitColorBufferRegs(colorBuffer);
|
||||
}
|
||||
|
||||
static inline void GX2InitAttribStream(GX2AttribStream *attr, uint32_t location, uint32_t buffer, uint32_t offset, GX2AttribFormat format) {
|
||||
attr->location = location;
|
||||
attr->buffer = buffer;
|
||||
attr->offset = offset;
|
||||
attr->format = format;
|
||||
attr->type = GX2_ATTRIB_INDEX_PER_VERTEX;
|
||||
attr->aluDivisor = 0;
|
||||
attr->mask = attribute_dest_comp_selector[format & 0xff];
|
||||
attr->endianSwap = GX2_ENDIAN_SWAP_DEFAULT;
|
||||
}
|
||||
|
||||
static inline void GX2InitTexture(GX2Texture *tex, uint32_t width, uint32_t height, uint32_t depth, uint32_t mipLevels, GX2SurfaceFormat format, GX2SurfaceDim dim, GX2TileMode tile) {
|
||||
tex->surface.dim = dim;
|
||||
tex->surface.width = width;
|
||||
tex->surface.height = height;
|
||||
tex->surface.depth = depth;
|
||||
tex->surface.mipLevels = mipLevels;
|
||||
tex->surface.format = format;
|
||||
tex->surface.aa = GX2_AA_MODE1X;
|
||||
tex->surface.use = GX2_SURFACE_USE_TEXTURE;
|
||||
tex->surface.imageSize = 0;
|
||||
tex->surface.image = nullptr;
|
||||
tex->surface.mipmapSize = 0;
|
||||
tex->surface.mipmaps = nullptr;
|
||||
tex->surface.tileMode = tile;
|
||||
tex->surface.swizzle = 0;
|
||||
tex->surface.alignment = 0;
|
||||
tex->surface.pitch = 0;
|
||||
uint32_t i;
|
||||
for (i = 0; i < 13; i++) {
|
||||
tex->surface.mipLevelOffset[i] = 0;
|
||||
}
|
||||
tex->viewFirstMip = 0;
|
||||
tex->viewNumMips = mipLevels;
|
||||
tex->viewFirstSlice = 0;
|
||||
tex->viewNumSlices = depth;
|
||||
tex->compMap = texture_comp_selector[format & 0x3f];
|
||||
for (i = 0; i < 5; i++) {
|
||||
tex->regs[i] = 0;
|
||||
}
|
||||
|
||||
tex->compMap = GX2_COMP_MAP(GX2_SQ_SEL_R, GX2_SQ_SEL_G, GX2_SQ_SEL_B, GX2_SQ_SEL_A);
|
||||
|
||||
DCFlushRange(&tex, sizeof(GX2Texture));
|
||||
GX2CalcSurfaceSizeAndAlignment(&tex->surface);
|
||||
GX2InitTextureRegs(tex);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user