2518
2518
SetViewport(0, 0, previous_width, previous_height);
2522
void GraphicsEngine::InitAsmTexturePremultiplyShader()
2524
std::string AsmVtx =
2526
ATTRIB iPos = vertex.position; \n\
2527
ATTRIB iColor = vertex.attrib[3]; \n\
2528
PARAM mvp[4] = {state.matrix.mvp}; \n\
2529
OUTPUT oPos = result.position; \n\
2530
OUTPUT oColor = result.color; \n\
2531
OUTPUT oTexCoord0 = result.texcoord[0]; \n\
2532
# Transform the vertex to clip coordinates. \n\
2533
DP4 oPos.x, mvp[0], iPos; \n\
2534
DP4 oPos.y, mvp[1], iPos; \n\
2535
DP4 oPos.z, mvp[2], iPos; \n\
2536
DP4 oPos.w, mvp[3], iPos; \n\
2537
MOV oColor, iColor; \n\
2538
MOV oTexCoord0, vertex.attrib[8]; \n\
2541
std::string AsmFrg =
2545
TEX tex0, fragment.texcoord[0], texture[0], 2D; \n\
2546
MUL temp.rgb, tex0, tex0.aaaa; \n\
2547
MOV temp.a, tex0.aaaa; \n\
2548
MUL result.color, fragment.color, temp; \n\
2551
std::string AsmFrgRect =
2555
TEX tex0, fragment.texcoord[0], texture[0], RECT; \n\
2556
MUL temp.rgb, tex0, tex0.aaaa; \n\
2557
MOV temp.a, tex0.aaaa; \n\
2558
MUL result.color, fragment.color, temp; \n\
2561
m_AsmTexturePremultiplyModColor = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
2562
m_AsmTexturePremultiplyModColor->LoadVertexShader(AsmVtx.c_str());
2563
m_AsmTexturePremultiplyModColor->LoadPixelShader(AsmFrg.c_str());
2564
m_AsmTexturePremultiplyModColor->Link();
2566
m_AsmTexturePremultiplyRectModColor = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
2567
m_AsmTexturePremultiplyRectModColor->LoadVertexShader(AsmVtx.c_str());
2568
m_AsmTexturePremultiplyRectModColor->LoadPixelShader(AsmFrgRect.c_str());
2569
m_AsmTexturePremultiplyRectModColor->Link();
2572
void GraphicsEngine::QRP_ASM_1TexPremultiply(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color &color)
2574
if (device_texture.IsNull())
2577
NUX_RETURN_IF_FALSE(m_AsmTexturePremultiplyModColor.IsValid());
2578
NUX_RETURN_IF_FALSE(m_AsmTexturePremultiplyRectModColor.IsValid());
2580
QRP_Compute_Texture_Coord(width, height, device_texture, texxform);
2581
float fx = x, fy = y;
2584
fx, fy, 0.0f, 1.0f, texxform.u0, texxform.v0, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
2585
fx, fy + height, 0.0f, 1.0f, texxform.u0, texxform.v1, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
2586
fx + width, fy + height, 0.0f, 1.0f, texxform.u1, texxform.v1, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
2587
fx + width, fy, 0.0f, 1.0f, texxform.u1, texxform.v0, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
2590
CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
2591
CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
2593
ObjectPtr<IOpenGLAsmShaderProgram> shader_program = m_AsmTexturePremultiplyModColor;
2594
if (device_texture->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
2596
shader_program = m_AsmTexturePremultiplyRectModColor;
2598
shader_program->Begin();
2600
SetTexture(GL_TEXTURE0, device_texture);
2602
CHECKGL(glMatrixMode(GL_MODELVIEW));
2603
CHECKGL(glLoadIdentity());
2604
CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
2605
CHECKGL(glMatrixMode(GL_PROJECTION));
2606
CHECKGL(glLoadIdentity());
2607
CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
2610
int VertexLocation = VTXATTRIB_POSITION;
2611
int TextureCoord0Location = VTXATTRIB_TEXCOORD0;
2612
int VertexColorLocation = VTXATTRIB_COLOR;
2614
CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
2615
CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer));
2617
if (TextureCoord0Location != -1)
2619
CHECKGL(glEnableVertexAttribArrayARB(TextureCoord0Location));
2620
CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4));
2623
if (VertexColorLocation != -1)
2625
CHECKGL(glEnableVertexAttribArrayARB(VertexColorLocation));
2626
CHECKGL(glVertexAttribPointerARB((GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8));
2629
CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
2631
CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
2633
if (TextureCoord0Location != -1)
2634
CHECKGL(glDisableVertexAttribArrayARB(TextureCoord0Location));
2636
if (VertexColorLocation != -1)
2637
CHECKGL(glDisableVertexAttribArrayARB(VertexColorLocation));
2639
shader_program->End();
2522
2642
#endif // NUX_OPENGLES_20